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

Commit6d157e7

Browse files
committed
Don't fail on libpq-generated error reports in ecpg_raise_backend().
An error PGresult generated by libpq itself, such as a report ofconnection loss, won't have broken-down error fields.ecpg_raise_backend() blithely assumed that PG_DIAG_MESSAGE_PRIMARYwould always be present, and would end up passing a NULL stringpointer to snprintf when it isn't. That would typically crashbefore3779ac6, and it would fail to provide a useful error reportin any case. Best practice is to substitute PQerrorMessage(conn)in such cases, so do that.Per bug #17421 from Masayuki Hirose. Back-patch to all supportedbranches.Discussion:https://postgr.es/m/17421-790ff887e3188874@postgresql.org
1 parent157f873 commit6d157e7

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

‎src/interfaces/ecpg/ecpglib/error.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,17 @@ ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
229229
return;
230230
}
231231

232-
if (result)
233-
{
234-
sqlstate=PQresultErrorField(result,PG_DIAG_SQLSTATE);
235-
if (sqlstate==NULL)
236-
sqlstate=ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
237-
message=PQresultErrorField(result,PG_DIAG_MESSAGE_PRIMARY);
238-
}
239-
else
240-
{
232+
/*
233+
* PQresultErrorField will return NULL if "result" is NULL, or if there is
234+
* no such field, which will happen for libpq-generated errors. Fall back
235+
* to PQerrorMessage in such cases.
236+
*/
237+
sqlstate=PQresultErrorField(result,PG_DIAG_SQLSTATE);
238+
if (sqlstate==NULL)
241239
sqlstate=ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
240+
message=PQresultErrorField(result,PG_DIAG_MESSAGE_PRIMARY);
241+
if (message==NULL)
242242
message=PQerrorMessage(conn);
243-
}
244243

245244
if (strcmp(sqlstate,ECPG_SQLSTATE_ECPG_INTERNAL_ERROR)==0)
246245
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp