nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] check stat's result to avoid referencing unitialized da


From: Benno Schulenberg
Subject: Re: [Nano-devel] check stat's result to avoid referencing unitialized data
Date: Tue, 09 Feb 2016 15:31:27 +0100

On Mon, Feb 8, 2016, at 09:35, Kamil Dudka wrote:
> On Saturday 06 February 2016 11:35:29 Benno Schulenberg wrote:
> > So I think this part should be:
> > 
> > -       /* Update current_stat to reference the file as it is now. */
> > -       if (openfile->current_stat == NULL)
> > -           openfile->current_stat =
> > -               (struct stat *)nmalloc(sizeof(struct stat));
> > -       if (!openfile->mark_set)
> > -           stat(realname, openfile->current_stat);
> > +       if (!openfile->mark_set) {
> > +           if (openfile->current_stat == NULL)
> > +               openfile->current_stat =
> > +                       (struct stat *)nmalloc(sizeof(struct stat));
> > +
> > +           /* Update the stat info to reflect the file as it is now. */
> > +           if (stat(realname, openfile->current_stat) != 0) {
> > +               free(openfile->current_stat);
> > +               openfile->current_stat = NULL;
> > +           }
> > +       }
> 
> Looks good to me.

I've reworked the patch a bit to reduce the number of lines.
See attached.

If you can think of a better name than 'stat_with_alloc',
do let me know.

Benno

-- 
http://www.fastmail.com - Send your email first class

Attachment: ensuring-that-stat-info-is-valid.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]