[13254] in bugtraq

home help back first fref pref prev next nref lref last post

Re: Symlinks and Cryogenic Sleep

daemon@ATHENA.MIT.EDU (Pavel Machek)
Wed Jan 5 17:07:44 2000

Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Message-Id:  <20000104224709.I140@bug.ucw.cz>
Date:         Tue, 4 Jan 2000 22:47:09 +0100
Reply-To: Pavel Machek <pavel@SUSE.CZ>
From: Pavel Machek <pavel@SUSE.CZ>
X-To:         Olaf Kirch <okir@MONAD.SWB.DE>, BUGTRAQ@SECURITYFOCUS.COM
To: BUGTRAQ@SECURITYFOCUS.COM
In-Reply-To:  <20000103212443.A5807@monad.swb.de>; from Olaf Kirch on Mon,
              Jan 03, 2000 at 09:24:43PM +0100

Hi!

> when you're dealing with files in /tmp that are supposed to be re-opened
> (rather than opened once and then discarded) there's an established
> way to do it which goes like this:
>
> 	if (lstat(fname, &stb1) >= 0 && S_ISREG(stb1.st_mode)) {
> 		fd = open(fname, O_RDWR);
> 		if (fd < 0 || fstat(fd, &stb2) < 0
> 		 || ino_or_dev_mismatch(&stb1, &stb2))
> 			raise_big_stink()

If you add (at this place)

		if (lstat(fname, &stb2) < 0 || !S_ISREG(stb2.st_mode))
		    ino_or_dev_mismatch(&stb1, &stb2)

it is safe.

Idea is: once opened, dev/ino is stable, therefore if I followed link
to interesting file, there's no way to create other regular file with
same dev/ino.

> Comments? Suggestions?

See above. Does it work?
								Pavel
PS: Do you need to _symlink_ it? What about hardlinks?
--
I'm pavel@ucw.cz. "In my country we have almost anarchy and I don't care."
Panos Katsaloulis describing me w.r.t. patents me at discuss@linmodems.org

home help back first fref pref prev next nref lref last post