8000 libpq: random fixes · markokr/postgres@944a9d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 944a9d0

Browse files
committed
libpq: random fixes
These fixes were part of rowproc commit. - lo_open: check if conn is NULL - lo_import_internal: check if conn is NULL - lo_import_internal: remove unnecessary 'const' - pqGetline2: check for COPY state - libpq-fe.h: move comment
1 parent 5b1fb57 commit 944a9d0

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

src/interfaces/libpq/fe-lobj.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ lo_open(PGconn *conn, Oid lobjId, int mode)
5959
PQArgBlock argv[2];
6060
PGresult *res;
6161

62-
if (conn->lobjfuncs == NULL)
62+
if (conn == NULL || conn->lobjfuncs == NULL)
6363
{
6464
if (lo_initialize(conn) < 0)
6565
return -1;
@@ -101,7 +101,7 @@ lo_close(PGconn *conn, int fd)
101101
int retval;
102102
int result_len;
103103

104-
if (conn->lobjfuncs == NULL)
104+
if (conn == NULL || conn->lobjfuncs == NULL)
105105
{
106106
if (lo_initialize(conn) < 0)
107107
return -1;
@@ -139,7 +139,7 @@ lo_truncate(PGconn *conn, int fd, size_t len)
139139
int retval;
140140
int result_len;
141141

142-
if (conn->lobjfuncs == NULL)
142+
if (conn == NULL || conn->lobjfuncs == NULL)
143143
{
144144
if (lo_initialize(conn) < 0)
145145
return -1;
@@ -192,7 +192,7 @@ lo_read(PGconn *conn, int fd, char *buf, size_t len)
192192
PGresult *res;
193193
int result_len;
194194

195-
if (conn->lobjfuncs == NULL)
195+
if (conn == NULL || conn->lobjfuncs == NULL)
196196
{
197197
if (lo_initialize(conn) < 0)
1981 8000 98
return -1;
@@ -234,7 +234,7 @@ lo_write(PGconn *conn, int fd, const char *buf, size_t len)
234234
int result_len;
235235
int retval;
236236

237-
if (conn->lobjfuncs == NULL)
237+
if (conn == NULL || conn->lobjfuncs == NULL)
238238
{
239239
if (lo_initialize(conn) < 0)
240240
return -1;
@@ -280,7 +280,7 @@ lo_lseek(PGconn *conn, int fd, int offset, int whence)
280280
int retval;
281281
int result_len;
282282

283-
if (conn->lobjfuncs == NULL)
283+
if (conn == NULL || conn->lobjfuncs == NULL)
284284
{
285285
if (lo_initialize(conn) < 0)
286286
return -1;
@@ -328,7 +328,7 @@ lo_creat(PGconn *conn, int mode)
328328
int retval;
329329
int result_len;
330330

331-
if (conn->lobjfuncs == NULL)
331+
if (conn == NULL || conn->lobjfuncs == NULL)
332332
{
333333
if (lo_initialize(conn) < 0)
334334
return InvalidOid;
@@ -367,7 +367,7 @@ lo_create(PGconn *conn, Oid lobjId)
367367
int retval;
368368
int result_len;
369369

370-
if (conn->lobjfuncs == NULL)
370+
if (conn == NULL || conn->lobjfuncs == NULL)
371371
{
372372
if (lo_initialize(conn) < 0)
373373
return InvalidOid;
@@ -413,7 +413,7 @@ lo_tell(PGconn *conn, int fd)
413413
PGresult *res;
414414
int result_len;
415415

416-
if (conn->lobjfuncs == NULL)
416+
if (conn == NULL || conn->lobjfuncs == NULL)
417417
{
418418
if (lo_initialize(conn) < 0)
419419
return -1;
@@ -451,7 +451,7 @@ lo_unlink(PGconn *conn, Oid lobjId)
451451
int result_len;
452452
int retval;
453453

454-
if (conn->lobjfuncs == NULL)
454+
if (conn == NULL || conn->lobjfuncs == NULL)
455455
{
456456
if (lo_initialize(conn) < 0)
457457
return -1;
@@ -505,7 +505,7 @@ lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId)
505505
}
506506

507507
static Oid
508-
lo_import_internal(PGconn *conn, const char *filename, const Oid oid)
508+
lo_import_internal(PGconn *conn, const char *filename, Oid oid)
509509
{
510510
int fd;
511511
int nbytes,
@@ -686,6 +686,9 @@ lo_initialize(PGconn *conn)
686686
const char *fname;
687687
Oid foid;
688688

689+
if (!conn)
690+
return -1;
691+
689692
/*
690693
* Allocate the structure to hold the functions OID's
691694
*/

src/interfaces/libpq/fe-protocol2.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,8 @@ pqGetline2(PGconn *conn, char *s, int maxlen)
11221122
{
11231123
int result = 1; /* return value if buffer overflows */
11241124

1125< 9E88 /td>-
if (conn->sock < 0)
1125+
if (conn->sock < 0 ||
1126+
conn->asyncStatus != PGASYNC_COPY_OUT)
11261127
{
11271128
*s = '\0';
11281129
return EOF;

src/interfaces/libpq/libpq-fe.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ extern "C"
3838

3939
/* Application-visible enum types */
4040

41+
/*
42+
* Although it is okay to add to these lists, values which become unused
43+
* should never be removed, nor should constants be redefined - that would
44+
* break compatibility with existing code.
45+
*/
46+
4147
typedef enum
4248
{
43-
/*
44-
* Although it is okay to add to this list, values which become unused
45-
* should never be removed, nor should constants be redefined - that would
46-
* break compatibility with existing code.
47-
*/
4849
CONNECTION_OK,
4950
CONNECTION_BAD,
5051
/* Non-blocking mode only below here */

0 commit comments

Comments
 (0)
0