Browse Source

dpkg: Track newargs in a different variable to avoid modifying it

The dpkg_options_parse() call modifies the argv argument which means
that if we try to free it later on or realloc it we will crash.
Guillem Jover 7 years ago
parent
commit
3b3efd1790
1 changed files with 4 additions and 3 deletions
  1. 4 3
      src/main.c

+ 4 - 3
src/main.c

@@ -777,7 +777,7 @@ commandfd(const char *const *argv)
 {
   struct varbuf linevb = VARBUF_INIT;
   const char * pipein;
-  const char **newargs = NULL;
+  const char **newargs = NULL, **endargs;
   char *ptr, *endptr;
   FILE *in;
   long infd;
@@ -862,12 +862,13 @@ commandfd(const char *const *argv)
     for(i=1;i<argc;i++)
       if (newargs[i])
         newargs[i] = m_strdup(newargs[i]);
+    endargs = newargs;
 
     setaction(NULL, NULL);
-    dpkg_options_parse((const char *const **)&newargs, cmdinfos, printforhelp);
+    dpkg_options_parse((const char *const **)&endargs, cmdinfos, printforhelp);
     if (!cipaction) badusage(_("need an action option"));
 
-    ret |= cipaction->action(newargs);
+    ret |= cipaction->action(endargs);
 
     pop_error_context(ehflag_normaltidy);
   }