Fix parsing of long lines.
authorWerner Koch <wk@gnupg.org>
Fri, 20 Jun 2008 09:53:54 +0000 (09:53 +0000)
committerWerner Koch <wk@gnupg.org>
Fri, 20 Jun 2008 09:53:54 +0000 (09:53 +0000)
gpgme/ChangeLog
gpgme/engine-gpgconf.c

index f527ba96d086c1e7d0a83f9fb9deda88477e9806..8c3595989690e1c3de239d0b0ca5abc54201cb8f 100644 (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,
index c894dea92d3bf0a1adb64d9f05611aa043aaf628..6a9cf2be22b034925050265496367f6dbf6c5024 100644 (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;
        }
     }