Re: BUG #8167: false EINVAL -22 for opening a file

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: nelson(at)monkey(dot)org
Cc: pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #8167: false EINVAL -22 for opening a file
Date: 2013-05-16 15:55:10
Message-ID: 15677.1368719710@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

nelson(at)monkey(dot)org writes:
> RhodiumToad asked me to report "pg in PathNameOpenFile / mdopen is
> assuming that errno is preserved over calls to free() which is not
> required by the spec"

Good catch! The proximate problem appears to be this bit in
PathNameOpenFile:

vfdP->fd = BasicOpenFile(fileName, fileFlags, fileMode);

if (vfdP->fd < 0)
{
FreeVfd(file);
free(fnamecopy);
return -1;
}

The other code layers in this stack seem to be careful about preserving
errno where needed, but this bit isn't.

I've not really reviewed fd.c for other instances of the same bug,
but I do see some places where there are DO_DB(...) debug calls in
places where errno had better not change. I'm thinking maybe we should
improve that macro to include save/restore errno. Or else rip that
stuff out entirely --- I've sure never built this code with FDDEBUG
set, has anyone else?

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message John R Pierce 2013-05-16 19:19:38 Re: Postgresql 9.12 support cluster mode
Previous Message weiwei 2013-05-16 09:16:44 回复: Postgresql 9.12 support cluster mode

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2013-05-16 16:05:06 Re: Logging of PAM Authentication Failure
Previous Message Andrew Dunstan 2013-05-16 15:17:51 Re: PostgreSQL 9.3 beta breaks some extensions "make install"