[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
ensuring-that-stat-info-is-valid.patch
Description: Text Data
- [Nano-devel] [PATCH 1/2] check stat's result and avoid calling stat on a NULL pointer, Kamil Dudka, 2016/02/03
- [Nano-devel] [PATCH 2/2] use futimens() if available, instead of utime(), Kamil Dudka, 2016/02/03
- Re: [Nano-devel] [PATCH 2/2] use futimens() if available, instead of utime(), Mike Frysinger, 2016/02/03
- Re: [Nano-devel] [PATCH 2/2] use futimens() if available, instead of utime(), Kamil Dudka, 2016/02/03
- [Nano-devel] begin using gnulib?, Benno Schulenberg, 2016/02/04
- Re: [Nano-devel] begin using gnulib?, Mike Frysinger, 2016/02/04
- Re: [Nano-devel] begin using gnulib?, Chris Allegretta, 2016/02/05
- Re: [Nano-devel] begin using gnulib?, Kamil Dudka, 2016/02/05
Re: [Nano-devel] [PATCH 1/2] check stat's result and avoid calling stat on a NULL pointer, Benno Schulenberg, 2016/02/06