Skip site navigation (1) Skip section navigation (2)

Re: Bad bug in fopen() wrapper code

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgresql(dot)org, "Claudio Natoli" <claudio(dot)natoli(at)memetrics(dot)com>
Cc: "Magnus Hagander" <mha(at)sollentuna(dot)net>, pgsql-patches(at)postgresql(dot)org
Subject: Re: Bad bug in fopen() wrapper code
Date: 2006-09-30 17:54:30
Message-ID: 14631.1159638870@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
"Claudio Natoli" <claudio(dot)natoli(at)memetrics(dot)com> writes:
> Magnus Hagander writes:
>> Now, I still twist my head around the lines:
>> if ((fd = _open_osfhandle((long) h, fileFlags & O_APPEND)) < 0
>> ||
>> (fileFlags & (O_TEXT | O_BINARY) && (_setmode(fd,
>> fileFlags & (O_TEXT | O_BINARY)) < 0)))

> Without having studied it closely, it might also highlight a bug on failure of the second clause -- if the _setmode fails, shouldn't _close be called instead of CloseHandle, and -1 returned?  (CloseHandle would still be called on failure of the _open_osfhandle, obviously)

I agree that this code is both wrong and unreadable (although in
practice the _setmode will probably never fail, which is why our
attention hasn't been drawn to it).  Is someone going to submit a
patch?  I'm hesitant to change the code myself since I'm not in
a position to test it.

			regards, tom lane

In response to

Responses

pgsql-hackers by date

Next:From: Joshua D. DrakeDate: 2006-09-30 18:04:04
Subject: libedit broke in head
Previous:From: Tom LaneDate: 2006-09-30 17:48:01
Subject: Re: PostgreSQL 8.2beta1 w/ VALUES

pgsql-patches by date

Next:From: Tom LaneDate: 2006-09-30 18:27:29
Subject: Re: adminpack
Previous:From: Bruce MomjianDate: 2006-09-30 12:09:40
Subject: strlcpy() and bsd/os

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group