From 914ace7a373456b4059d372f99afb51aa544bbfd Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 28 Apr 2008 18:42:56 +0000 Subject: [PATCH] Fixed a bug reading from gpgconf. --- ChangeLog | 4 ++++ configure.ac | 3 ++- gpgme/ChangeLog | 5 +++++ gpgme/engine-gpgconf.c | 32 +++++++++++++++++++------------- gpgme/gpgme.h | 2 +- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index f6a0f2d..64316bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-04-01 Werner Koch + + * configure.ac (AC_INIT): Fix quoting. + 2008-01-30 Marcus Brinkmann * configure.ac: Bump required version of automake up to 1.10. diff --git a/configure.ac b/configure.ac index 5016b1c..e824b47 100644 --- a/configure.ac +++ b/configure.ac @@ -36,7 +36,8 @@ m4_define(my_issvn, [yes]) m4_define([svn_revision], m4_esyscmd([echo -n $( (svn info 2>/dev/null \ || echo 'Revision: 0')|sed -n '/^Revision:/ {s/[^0-9]//gp;q;}')])) -AC_INIT([gpgme], my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision]), +AC_INIT([gpgme], + [my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision])], [bug-gpgme@gnupg.org]) diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index 219d482..e5b441b 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,8 @@ +2008-04-28 Werner Koch + + * engine-gpgconf.c (gpgconf_read): Fixed segv. Avoid memmove for + each line. + 2008-04-22 Marcus Brinkmann * w32-qt-io.cpp, kdpipeiodevice.cpp: New versions from Frank diff --git a/gpgme/engine-gpgconf.c b/gpgme/engine-gpgconf.c index ab03e9d..456f330 100644 --- a/gpgme/engine-gpgconf.c +++ b/gpgme/engine-gpgconf.c @@ -198,7 +198,7 @@ gpgconf_read (void *engine, char *arg1, char *arg2, struct engine_gpgconf *gpgconf = engine; gpgme_error_t err = 0; #define LINELENGTH 1024 - char line[LINELENGTH] = ""; + char linebuf[LINELENGTH] = ""; int linelen = 0; char *argv[] = { NULL /* file_name */, arg1, arg2, 0 }; int rp[2]; @@ -229,28 +229,33 @@ gpgconf_read (void *engine, char *arg1, char *arg2, do { - nread = _gpgme_io_read (rp[0], &line[linelen], LINELENGTH - linelen - 1); + nread = _gpgme_io_read (rp[0], + linebuf + linelen, LINELENGTH - linelen - 1); if (nread > 0) { + char *line; + const char *lastmark = NULL; + size_t nused; + linelen += nread; - line[linelen] = '\0'; + linebuf[linelen] = '\0'; - while ((mark = strchr (line, '\n'))) + for (line=linebuf; (mark = strchr (line, '\n')); line = mark+1 ) { - char *eol = mark; - - if (eol > line && eol[-1] == '\r') - eol--; - *eol = '\0'; + lastmark = mark; + if (mark > line && mark[-1] == '\r') + mark--; + *mark = '\0'; /* Got a full line. */ err = (*cb) (hook, line); if (err) - break; - - linelen -= mark + 1 - line; - memmove (line, mark + 1, linelen); + goto leave; } + + nused = lastmark? (lastmark + 1 - linebuf) : 0; + memmove (linebuf, linebuf + nused, nused); + linelen -= nused; } } while (nread > 0 && linelen < LINELENGTH - 1); @@ -260,6 +265,7 @@ gpgconf_read (void *engine, char *arg1, char *arg2, if (!err && nread > 0) err = gpg_error (GPG_ERR_LINE_TOO_LONG); + leave: _gpgme_io_close (rp[0]); return err; diff --git a/gpgme/gpgme.h b/gpgme/gpgme.h index 8ae4daf..af6b239 100644 --- a/gpgme/gpgme.h +++ b/gpgme/gpgme.h @@ -72,7 +72,7 @@ extern "C" { AM_PATH_GPGME macro) check that this header matches the installed library. Warning: Do not edit the next line. configure will do that for you! */ -#define GPGME_VERSION "1.1.7-svn1301" +#define GPGME_VERSION "1.1.7-svn1307" -- 2.26.2