Переглянути джерело

dpkg-deb: Fix double free in --info

Change the code to not increase cdlist, and instead index it, so that
we can free it at the end.

Regression introduced in commit c264dd83d33250927fe165de5336145afdf99610.
Guillem Jover 16 роки тому
батько
коміт
b066610b39
1 змінених файлів з 3 додано та 3 видалено
  1. 3 3
      dpkg-deb/info.c

+ 3 - 3
dpkg-deb/info.c

@@ -131,7 +131,7 @@ static void info_list(const char *debar, const char *directory) {
   char interpreter[INTERPRETER_MAX+1], *p;
   char interpreter[INTERPRETER_MAX+1], *p;
   int il, lines;
   int il, lines;
   struct dirent **cdlist, *cdep;
   struct dirent **cdlist, *cdep;
-  int cdn;
+  int cdn, n;
   FILE *cc;
   FILE *cc;
   struct stat stab;
   struct stat stab;
   int c;
   int c;
@@ -139,8 +139,8 @@ static void info_list(const char *debar, const char *directory) {
   cdn= scandir(".", &cdlist, &ilist_select, alphasort);
   cdn= scandir(".", &cdlist, &ilist_select, alphasort);
   if (cdn == -1) ohshite(_("cannot scan directory `%.255s'"),directory);
   if (cdn == -1) ohshite(_("cannot scan directory `%.255s'"),directory);
 
 
-  while (cdn-- >0) {
-    cdep= *cdlist++;
+  for (n = 0; n < cdn; n++) {
+    cdep = cdlist[n];
     if (stat(cdep->d_name,&stab))
     if (stat(cdep->d_name,&stab))
       ohshite(_("cannot stat `%.255s' (in `%.255s')"),cdep->d_name,directory);
       ohshite(_("cannot stat `%.255s' (in `%.255s')"),cdep->d_name,directory);
     if (S_ISREG(stab.st_mode)) {
     if (S_ISREG(stab.st_mode)) {