Bugtraq mailing list archives
Re: Symlinks and Cryogenic Sleep
From: pedward () WEBCOM COM (pedward () WEBCOM COM)
Date: Tue, 4 Jan 2000 14:16:55 -0800
Why not do an: fd = open(file, O_RDWR); fstat(fd, &fi); lstat(file, &li); if (fi.st_ino == li.st_ino && fi.st_dev == li.st_dev && S_ISREG(fi.st_mode)) { /* it's a real, plain, file */ } That guarantees that the directory structure reflects your file descriptor. The method below has a race condition, you're not checking that the file you opened is legitmate, youre lstat proves nothing. The race exists because there is no fstat. You could open the link, replace the link with a file, lstat would be cool, and then reopen the link for writing. In the above, you'd open the link, get the inode info on the file that the link pointed to, lstat the link, and compare the results. Obviously the linked to file couldn't have the same dev/inode as the link, and you obviously couldn't put the actual file there, so there is no race. --Perry
I did something that way: FILE *DoOpen(const char *cpFile, long bAppend) { FILE *spNew; FILE *spTest; struct stat sStat; spTest = fopen(cpFile,"a"); if (!spTest) { Log("ERR FILE OPEN",cpFile); return NULL; } if (lstat(cpFile,&sStat)) { Log("ERR STAT",cpFile); return NULL; } if ((sStat.st_mode & S_IFMT) == S_IFLNK) { fclose(spTest); Log("ERR ISLINK",cpFile); return NULL; } if (bAppend) spNew = spTest; else { spNew = freopen(cpFile,"w",spTest); fclose(spTest); } if (!spNew) { Log("ERR FILE OPEN",cpFile); return NULL; } return spFile; } Comments ? Improvements ? By Goetz
-- Perry Harrington Director of zelur xuniL () perry () webcom com System Architecture Think Blue. /\
Current thread:
- Symlinks and Cryogenic Sleep Olaf Kirch (Jan 03)
- Re: Symlinks and Cryogenic Sleep Mark A. Heilpern (Jan 03)
- Re: Symlinks and Cryogenic Sleep Casper Dik (Jan 04)
- Re: Symlinks and Cryogenic Sleep Olaf Kirch (Jan 04)
- Re: Symlinks and Cryogenic Sleep Henrik Nordstrom (Jan 04)
- First Telecom E-conso service totally insecure Thomas Quinot (Jan 03)
- Re: Symlinks and Cryogenic Sleep Goetz Babin-Ebell (Jan 04)
- Re: Symlinks and Cryogenic Sleep pedward () WEBCOM COM (Jan 04)
- Re: Symlinks and Cryogenic Sleep Christos Zoulas (Jan 04)
- Re: Symlinks and Cryogenic Sleep Mikael Olsson (Jan 05)
- Re: Symlinks and Cryogenic Sleep Marc Heuse (Jan 05)
- Re: Symlinks and Cryogenic Sleep Wietse Venema (Jan 04)
- Re: Symlinks and Cryogenic Sleep Pavel Machek (Jan 04)
- Security problem with Solstice Backup/Legato Networker recover command Chris Siebenmann (Jan 04)
- Local / Remote D.o.S Attack in IMail IMONITOR Server for WinNT Version 5.08 Ussr Labs (Jan 05)
- Re: Symlinks and Cryogenic Sleep Pavel Kankovsky (Jan 05)
- [RHSA-2000:002] New lpr packages available Bill Nottingham (Jan 07)
- <Possible follow-ups>
- Re: Symlinks and Cryogenic Sleep der Mouse (Jan 03)
(Thread continues...)
- Re: Symlinks and Cryogenic Sleep Mark A. Heilpern (Jan 03)