|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
Re: Symlinks and Cryogenic Sleep
Subject: Re: Symlinks and Cryogenic Sleep
From: Mikael Olsson (mikael.olsson
ENTERNET.SE)
Date: Wed Jan 05 2000 - 02:34:01 CST
- Next message: danny: "Re: Flaw in 3c59x.c or in Kernel?"
- Previous message: Peter W: "Re: FWD: Redhat advisory (RPM --upgrade/-U vs. --freshen/-F)"
- In reply to: Goetz Babin-Ebell: "Re: Symlinks and Cryogenic Sleep"
- Next in thread: pedward
WEBCOM.COM: "Re: Symlinks and Cryogenic Sleep"
- Reply: Mikael Olsson: "Re: Symlinks and Cryogenic Sleep"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I think I see a flaw with this...
Goetz Babin-Ebell wrote:
>
> 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;
> }
>
In my tired state, I get the feeling that you open
yourself up to an inverted race situation here.
In this situation, the file that you open may
be a link, but before it is stat()ed, it may
be deleted (yes you can do this even though
it is open) and replaced with a normal file,
so that stat() won't complain.
I'd suggest that you don't stat the file by
name, but rather by the file descriptor that
you already have (_fstat()?); this way you know
that you are stat()ing the same file that you
actually opened (I hope!).
Oh, and the freopen() call opens you up to
another race situation (I think).
AFAIK, freopen() is just a shorthand for
fclose() followed by fopen(), so that leaves
room for a race situation.
(I might be talking out of my arse here tho)
If it were me, I'd move the file pointer to 0
and set the file length to 0; this way the file
remains open all the time, and you still get the
desired effect.
<flame shield>
I'm _REALLY_ tired
Just so you know :-)
</flame shield>
/Mike
-- Mikael Olsson, EnterNet Sweden AB, Box 393, S-891 28 ÖRNSKÖLDSVIK Phone: +46-(0)660-105 50 Fax: +46-(0)660-122 50 Mobile: +46-(0)70-248 00 33 WWW: http://www.enternet.se E-mail: mikael.olssonenternet.se
- Next message: danny: "Re: Flaw in 3c59x.c or in Kernel?"
- Previous message: Peter W: "Re: FWD: Redhat advisory (RPM --upgrade/-U vs. --freshen/-F)"
- In reply to: Goetz Babin-Ebell: "Re: Symlinks and Cryogenic Sleep"
- Next in thread: pedward
WEBCOM.COM: "Re: Symlinks and Cryogenic Sleep"
- Reply: Mikael Olsson: "Re: Symlinks and Cryogenic Sleep"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
This archive was generated by hypermail 2b27 : Wed Jan 05 2000 - 11:02:49 CST