Sfoglia il codice sorgente

dpkg: Use secure_unlink instead of ad-hoc code

Guillem Jover 17 anni fa
parent
commit
025191b0d7
1 ha cambiato i file con 2 aggiunte e 17 eliminazioni
  1. 2 17
      src/remove.c

+ 2 - 17
src/remove.c

@@ -259,23 +259,8 @@ static void removal_bulk_remove_files(
       }
       if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf);
       debug(dbg_eachfiledetail, "removal_bulk unlinking `%s'", fnvb.buf);
-      {
-        /*
-         * If file to remove is a device or s[gu]id, change its mode
-         * so that a malicious user cannot use it even if it's linked
-         * to another file
-         */
-        struct stat stat_buf;
-        if (lstat(fnvb.buf,&stat_buf)==0) {
-          if (S_ISCHR(stat_buf.st_mode) || S_ISBLK(stat_buf.st_mode)) {
-            chmod(fnvb.buf,0);
-          }
-          if (stat_buf.st_mode & (S_ISUID|S_ISGID)) {
-            chmod(fnvb.buf,stat_buf.st_mode & ~(S_ISUID|S_ISGID));
-          }
-        }
-      }
-      if (unlink(fnvb.buf)) ohshite(_("cannot remove file `%.250s'"),fnvb.buf);
+      if (secure_unlink(fnvb.buf))
+        ohshite(_("unable to securely remove '%.250s'"), fnvb.buf);
     }
     write_filelist_except(pkg,leftover,0);
     maintainer_script_installed(pkg, POSTRMFILE, "post-removal",