Fix parsing of long lines.

This commit is contained in:
Werner Koch 2008-06-20 09:53:54 +00:00
parent 63ea0d6663
commit 5a19f6d421
2 changed files with 16 additions and 5 deletions

View File

@ -1,3 +1,9 @@
2008-06-20 Werner Koch <wk@g10code.com>
* engine-gpgconf.c (gpgconf_read): Change ARGV initialization for
compatibility with old compilers. Fix amount of memmove. Fix
CR removal.
2008-06-19 Werner Koch <wk@g10code.com>
* gpgme.h (GPGME_CONF_PATHNAME): Replace by GPGME_CONF_FILENAME,

View File

@ -199,7 +199,7 @@ gpgconf_read (void *engine, char *arg1, char *arg2,
#define LINELENGTH 1024
char linebuf[LINELENGTH] = "";
int linelen = 0;
char *argv[] = { NULL /* file_name */, arg1, arg2, 0 };
char *argv[4] = { NULL /* file_name */, NULL, NULL, NULL };
int rp[2];
struct spawn_fd_item_s pfd[] = { {0, -1}, {-1, -1} };
struct spawn_fd_item_s cfd[] = { {-1, 1 /* STDOUT_FILENO */}, {-1, -1} };
@ -207,6 +207,10 @@ gpgconf_read (void *engine, char *arg1, char *arg2,
int nread;
char *mark = NULL;
argv[1] = arg1;
argv[2] = arg2;
/* FIXME: Deal with engine->home_dir. */
/* _gpgme_engine_new guarantees that this is not NULL. */
@ -243,20 +247,21 @@ gpgconf_read (void *engine, char *arg1, char *arg2,
{
lastmark = mark;
if (mark > line && mark[-1] == '\r')
mark--;
*mark = '\0';
mark[-1] = '\0';
else
mark[0] = '\0';
/* Got a full line. Due to the CR removal code (which
occurs only on Windows) we might be one-off and thus
would see empty lines. Don't pass them to the
callback. */
err = *line? (*cb) (hook, line) : NULL;
err = *line? (*cb) (hook, line) : 0;
if (err)
goto leave;
}
nused = lastmark? (lastmark + 1 - linebuf) : 0;
memmove (linebuf, linebuf + nused, nused);
memmove (linebuf, linebuf + nused, linelen - nused);
linelen -= nused;
}
}