This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: cpplib: Be safe in presence of symlinks


Zack Weinberg wrote:-

> I'm nervous about leaving "" alone.  On some systems stat("", &st)
> is an error.

It never gets to stat - see open_file ().  The empty string indicates
stdin, and is handled specially.  We only do fstat (), not stat (),
anyway.  So I reckoned it should be OK.

> > + /* Returns true if it is safe to remove the final component of path,
> > +    when it is followed by a ".." component.  */
> > + static int
> > + remove_component_p (path)
> > +      const char *path ATTRIBUTE_UNUSED;
> > + {
> > + #if defined (HAVE_DOS_BASED_FILE_SYSTEM) || defined (VMS)
> > +   return 1;
> > + #else
> > +   struct stat s;
> > + 
> > +   return lstat (path, &s) == 0 && S_ISDIR (s.st_mode);
> > + #endif
> 
> You can't assume lstat exists.  Add an autoconf probe for it.  If it
> doesn't exist, assume the system has no symlinks - i.e. return 1
> always.

OK.  I've not a clue how to do that, so I might learn something in the
process.

> I'm not sure that's the right thing to do if lstat returns an error.
> To come closer to the no-symlink case, ENOENT should return 1 and all
> other errors should be reported.  But that may not be the right thing,
> either.

I'll think about this some more.  I didn't want to start reporting
errors for something we weren't before, on the assumption that open_file
or something else will report the error if appropriate.

Neil.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]