Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf3f467b

Browse files
committed
Avoid calling strerror[_r] in PQcancel().
PQcancel() is supposed to be safe to call from a signal handler,and indeed psql uses it that way. All of the library functionsit uses are specified to be async-signal-safe by POSIX ...except for strerror. Neither plain strerror nor strerror_rare considered safe. When this code was written, back in thedark ages, we probably figured "oh, strerror will just indexinto a constant array of strings" ... but in any locale except C,that's unlikely to be true. Probably the reason we've not heardcomplaints is that (a) this error-handling code is unlikely to bereached in normal use, and (b) in many scenarios, localized errorstrings would already have been loaded, after which maybe it'ssafe to call strerror here. Still, this is clearly unacceptable.The best we can do without relying on strerror is to print thedecimal value of errno, so make it do that instead. (This isprobably not much loss of user-friendliness, given that it ishard to get a failure here.)Back-patch to all supported branches.Discussion:https://postgr.es/m/2937814.1641960929@sss.pgh.pa.us
1 parentcf92593 commitf3f467b

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4419,7 +4419,6 @@ internal_cancel(SockAddr *raddr, int be_pid, int be_key,
44194419
{
44204420
intsave_errno=SOCK_ERRNO;
44214421
pgsockettmpsock=PGINVALID_SOCKET;
4422-
charsebuf[PG_STRERROR_R_BUFLEN];
44234422
intmaxlen;
44244423
struct
44254424
{
@@ -4498,8 +4497,25 @@ internal_cancel(SockAddr *raddr, int be_pid, int be_key,
44984497
maxlen=errbufsize-strlen(errbuf)-2;
44994498
if (maxlen >=0)
45004499
{
4501-
strncat(errbuf,SOCK_STRERROR(SOCK_ERRNO,sebuf,sizeof(sebuf)),
4502-
maxlen);
4500+
/*
4501+
* We can't invoke strerror here, since it's not signal-safe. Settle
4502+
* for printing the decimal value of errno. Even that has to be done
4503+
* the hard way.
4504+
*/
4505+
intval=SOCK_ERRNO;
4506+
charbuf[32];
4507+
char*bufp;
4508+
4509+
bufp=buf+sizeof(buf)-1;
4510+
*bufp='\0';
4511+
do
4512+
{
4513+
*(--bufp)= (val %10)+'0';
4514+
val /=10;
4515+
}while (val>0);
4516+
bufp-=6;
4517+
memcpy(bufp,"error ",6);
4518+
strncat(errbuf,bufp,maxlen);
45034519
strcat(errbuf,"\n");
45044520
}
45054521
if (tmpsock!=PGINVALID_SOCKET)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp