From 0c2206f542ce6df2606586d43f190cd5a423fb13 Mon Sep 17 00:00:00 2001 From: Chantry Xavier Date: Thu, 7 Feb 2008 14:58:23 +0100 Subject: libalpm/add.c : safety check for fixing FS#9235. Fixes FS#9235. We already had the following case in extract_single_file : /* cases 1,2,3: couldn't stat an existing file, skip all backup checks */ But we actually only did a lstat here. And if lstat worked, we did a stat without checking. When lstat works and stat fails, it means we have a broken symlink, like in FS#9235. We can actually treat this case like a non-existing file. The broken symlink will then be simply overwritten. Signed-off-by: Chantry Xavier --- lib/libalpm/add.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index ec49c2a3..eddf637e 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -361,14 +361,12 @@ static int extract_single_file(struct archive *archive, * links, etc. * 12- skip extraction, dir already exists. */ - struct stat lsbuf; - if(_alpm_lstat(filename, &lsbuf) != 0) { + + /* do both a lstat and a stat, so we can see what symlinks point to */ + struct stat lsbuf, sbuf; + if(_alpm_lstat(filename, &lsbuf) != 0 || stat(filename, &sbuf) != 0) { /* cases 1,2,3: couldn't stat an existing file, skip all backup checks */ } else { - /* do a stat as well, so we can see what symlinks point to */ - struct stat sbuf; - stat(filename, &sbuf); - if(S_ISDIR(lsbuf.st_mode) && S_ISDIR(entrymode)) { /* case 12: existing dir, ignore it */ if(lsbuf.st_mode != entrymode) { -- cgit v1.2.3-24-g4f1b