From: Guillem Jover Date: Tue, 1 Jul 2008 01:44:12 +0000 (+0300) Subject: dpkg: Do not allocate memory when lstat fails while upgrading X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7c561fe071e2e7d90de2af262cd0c648e172590;p=dpkg dpkg: Do not allocate memory when lstat fails while upgrading --- diff --git a/ChangeLog b/ChangeLog index 15f57b78..be02b230 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-07-01 Guillem Jover + + * src/processarc.c (process_archive): Do not allocate a struct stat + when lstat fails, instead assign a pointer to a static empty stat + variable that will mark it as such. + 2008-06-30 Guillem Jover * lib/showpkg.c (parsefield): Remove unneeded 'const char *' cast. diff --git a/debian/changelog b/debian/changelog index 04a46a93..bfbd6a02 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,6 +22,7 @@ dpkg (1.15.0) UNRELEASED; urgency=low * Support diverting files when origin and destination are on different file systems. Based on a patch by Juergen Kreileder. Closes: #102144, #149961 * Do not silently enable --rename on dpkg-divert --remove. Closes: #160848 + * Do not allocate memory when lstat fails during package upgrade. [ Raphael Hertzog ] * Enhance dpkg-shlibdeps's error message when a library can't be found to diff --git a/src/processarc.c b/src/processarc.c index 667ca7b4..75535d02 100644 --- a/src/processarc.c +++ b/src/processarc.c @@ -680,6 +680,8 @@ void process_archive(const char *filename) { * since ones that stayed the same don't really apply here. */ struct fileinlist *sameas = NULL; + static struct stat empty_stat; + /* If we can't stat the old or new file, or it's a directory, * we leave it up to the normal code */ @@ -688,17 +690,21 @@ void process_archive(const char *filename) { for (cfile= newfileslist; cfile; cfile= cfile->next) { if (!cfile->namenode->filestat) { - cfile->namenode->filestat= nfmalloc(sizeof(struct stat)); - if (lstat(cfile->namenode->name, cfile->namenode->filestat)) { + struct stat tmp_stat; + + if (lstat(cfile->namenode->name, &tmp_stat) == 0) { + cfile->namenode->filestat = nfmalloc(sizeof(struct stat)); + memcpy(cfile->namenode->filestat, &tmp_stat, sizeof(struct stat)); + } else { if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR)) ohshite(_("unable to stat other new file `%.250s'"), cfile->namenode->name); - memset(cfile->namenode->filestat, 0, - sizeof(*cfile->namenode->filestat)); + cfile->namenode->filestat = &empty_stat; continue; } } - if (!cfile->namenode->filestat->st_mode) continue; + if (cfile->namenode->filestat == &empty_stat) + continue; if (oldfs.st_dev == cfile->namenode->filestat->st_dev && oldfs.st_ino == cfile->namenode->filestat->st_ino) { if (sameas)