svn commit: r243328 - head/lib/libutil

Baptiste Daroussin bapt at FreeBSD.org
Tue Nov 20 12:43:12 UTC 2012


On Tue, Nov 20, 2012 at 02:22:26PM +0200, Jaakko Heinonen wrote:
> 
> Hi!
> 
> On 2012-11-20, Baptiste Daroussin wrote:
> >   change mode the group file to 0644 after a successfull rename(2)
> > 
> >  int
> >  gr_mkdb(void)
> >  {
> > -	return (rename(tempname, group_file));
> > +	int ret;
> > +
> > +	ret = rename(tempname, group_file);
> > +
> > +	if (ret == 0)
> > +		chmod(group_file, 0644);
> > +
> > +	return (ret);
> >  }
> 
> Rename+chmod is not an atomic operation. There is a window when the file
> has wrong permissions. Also, you don't check the return value of
> chmod(). Maybe chmod first and then rename?
> 
> -- 
> Jaakko

Yes you are right chmod should probably be first.

regards,
Bapt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/svn-src-head/attachments/20121120/af67a1fa/attachment.sig>


More information about the svn-src-head mailing list