svn commit: r277802 - head/usr.bin/sed
Pedro Giffuni
pfg at FreeBSD.org
Wed Jan 28 15:24:52 UTC 2015
Hello;
On 01/28/15 03:41, Bruce Evans wrote:
> On Tue, 27 Jan 2015, Pedro F. Giffuni wrote:
>
>> Log:
>> Fix resource leak and dereference after NULL.
>>
>> process.c:
>> Protect access against NULL.
>>
>> main.c:
>> Prevent outfile overwrite resource leak.
>> ...
>> Modified: head/usr.bin/sed/main.c
>> ==============================================================================
>>
>> --- head/usr.bin/sed/main.c Tue Jan 27 18:56:46 2015 (r277801)
>> +++ head/usr.bin/sed/main.c Tue Jan 27 18:58:24 2015 (r277802)
>> @@ -411,6 +411,8 @@ mf_fgets(SPACE *sp, enum e_spflag spflag
>> unlink(tmpfname);
>> if ((outfile = fopen(tmpfname, "w")) == NULL)
>> err(1, "%s", fname);
>> + if (outfile != NULL && outfile != stdout)
>> + fclose(outfile);
>> fchown(fileno(outfile), sb.st_uid, sb.st_gid);
>> fchmod(fileno(outfile), sb.st_mode & ALLPERMS);
>> outfname = tmpfname;
>
> This is mismerged at best. It just breaks the new outfile by closing it.
> The check in it makes no sense in this contents, since the freshly-opened
> outfile cannot be NULL (since the open succeeded) or stdout (fopen()
> cannot return a pointer to an already-open stream, so it can only return
> stdout if the stdout pointer is garbage, but then it is not really
> stdout).
>
Yes, I pasted the check after it was useful and not before like the
original.
I noticed right away and fixed it though:
https://svnweb.freebsd.org/base?view=revision&revision=277811
But thanks for checking!
Pedro.
More information about the svn-src-all
mailing list