Skip to content

Commit e39bc69

Browse files
committed
Be a little bit more careful about using sqlstate, in case libpq returned
NULL for it.
1 parent 0bf7087 commit e39bc69

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/interfaces/ecpg/ecpglib/connect.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.15 2003/08/04 00:43:32 momjian Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.16 2003/08/08 13:16:20 petere Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -164,6 +164,9 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
164164

165165
int sqlcode;
166166

167+
if (sqlstate == NULL)
168+
sqlstate = ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
169+
167170
/* these are not warnings */
168171
if (strncmp(sqlstate, "00", 2) == 0)
169172
return;

src/interfaces/ecpg/ecpglib/error.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.6 2003/08/04 00:43:32 momjian Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.7 2003/08/08 13:16:20 petere Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -159,18 +159,29 @@ void
159159
ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat)
160160
{
161161
struct sqlca_t *sqlca = ECPGget_sqlca();
162+
char *sqlstate;
163+
char *message;
164+
165+
if (result)
166+
{
167+
sqlstate = PQresultErrorField(result, 'C');
168+
if (sqlstate == NULL)
169+
sqlstate = ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
170+
message = PQresultErrorField(result, 'M');
171+
}
172+
else
173+
{
174+
sqlstate = ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
175+
message = PQerrorMessage(conn);
176+
}
162177

163178
/* copy error message */
164179
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
165-
"'%s' in line %d.",
166-
result ? PQresultErrorField(result, 'M') : PQerrorMessage(conn),
167-
line);
180+
"'%s' in line %d.", message, line);
168181
sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
169182

170183
/* copy SQLSTATE */
171-
strncpy(sqlca->sqlstate,
172-
result ? PQresultErrorField(result, 'C') : ECPG_SQLSTATE_ECPG_INTERNAL_ERROR,
173-
sizeof(sqlca->sqlstate));
184+
strncpy(sqlca->sqlstate, sqlstate, sizeof(sqlca->sqlstate));
174185

175186
/* assign SQLCODE for backward compatibility */
176187
if (strncmp(sqlca->sqlstate, "23505", sizeof(sqlca->sqlstate)) == 0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy