Explorar el Código

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 hace 10 años
padre
commit
3b3efd1790
Se han modificado 1 ficheros con 4 adiciones y 3 borrados
  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);
   }