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

Commite77aaad

Browse files
committed
Repair libpq to follow protocol by not sending Terminate messages before
the startup exchange is complete. Also make sure that packets defined assingle bytes aren't sent with a trailing '\0'.
1 parent9981b0f commite77aaad

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.164 2001/03/31 23:14:37 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.165 2001/07/06 17:58:53 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1409,6 +1409,7 @@ PQconnectPoll(PGconn *conn)
14091409
if (areq==AUTH_REQ_OK)
14101410
{
14111411
/* We are done with authentication exchange */
1412+
conn->startup_complete= TRUE;
14121413
conn->status=CONNECTION_AUTH_OK;
14131414

14141415
/*
@@ -1909,6 +1910,7 @@ makeEmptyPGconn(void)
19091910
freePGconn(conn);
19101911
conn=NULL;
19111912
}
1913+
conn->startup_complete= FALSE;
19121914
returnconn;
19131915
}
19141916

@@ -1972,7 +1974,9 @@ freePGconn(PGconn *conn)
19721974
staticvoid
19731975
closePGconn(PGconn*conn)
19741976
{
1975-
if (conn->sock >=0)
1977+
/* Note that the protocol doesn't allow us to send Terminate
1978+
messages during the startup phase. */
1979+
if (conn->sock >=0&&conn->startup_complete)
19761980
{
19771981

19781982
/*
@@ -1981,8 +1985,8 @@ closePGconn(PGconn *conn)
19811985
* avoid getting SIGPIPE'd if the connection were already closed.
19821986
* Now we rely on pqFlush to avoid the signal.
19831987
*/
1984-
(void)pqPuts("X",conn);
1985-
(void)pqFlush(conn);
1988+
pqPutc('X',conn);
1989+
pqFlush(conn);
19861990
}
19871991

19881992
/*

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.101 2001/02/10 02:31:30 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.102 2001/07/06 17:58:53 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -556,8 +556,7 @@ PQsendQuery(PGconn *conn, const char *query)
556556
return0;
557557
/* 'Q' == queries */
558558
/* XXX: if we fail here we really ought to not block */
559-
if (pqPutnchar("Q",1,conn)||
560-
pqPuts(query,conn))
559+
if (pqPutc('Q',conn)!=0||pqPuts(query,conn)!=0)
561560
{
562561
handleSendFailure(conn);
563562
return0;
@@ -567,17 +566,16 @@ PQsendQuery(PGconn *conn, const char *query)
567566
* give the data a push, ignore the return value as ConsumeInput()
568567
* will do any aditional flushing if needed
569568
*/
570-
(void)pqFlush(conn);
569+
pqFlush(conn);
571570
}
572571
else
573572
{
574573

575574
/*
576575
* the frontend-backend protocol uses 'Q' to designate queries
577576
*/
578-
if (pqPutnchar("Q",1,conn)||
579-
pqPuts(query,conn)||
580-
pqFlush(conn))
577+
if (pqPutc('Q',conn)!=0||pqPuts(query,conn)!=0||
578+
pqFlush(conn)!=0)
581579
{
582580
handleSendFailure(conn);
583581
return0;
@@ -1655,9 +1653,9 @@ PQfn(PGconn *conn,
16551653
returnNULL;
16561654
}
16571655

1658-
if (pqPuts("F ",conn)||/* function */
1659-
pqPutInt(fnid,4,conn)||/* function id */
1660-
pqPutInt(nargs,4,conn))/* # of args */
1656+
if (pqPuts("F ",conn)!=0||/* function */
1657+
pqPutInt(fnid,4,conn)!=0||/* function id */
1658+
pqPutInt(nargs,4,conn)!=0)/* # of args */
16611659
{
16621660
handleSendFailure(conn);
16631661
returnNULL;

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
*
2727
* IDENTIFICATION
28-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.49 2001/05/28 15:29:51 tgl Exp $
28+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.50 2001/07/06 17:58:53 petere Exp $
2929
*
3030
*-------------------------------------------------------------------------
3131
*/
@@ -59,6 +59,8 @@
5959
#defineDONOTICE(conn,message) \
6060
((*(conn)->noticeHook) ((conn)->noticeArg, (message)))
6161

62+
staticintpqPutBytes(constchar*s,size_tnbytes,PGconn*conn);
63+
6264

6365
/* --------------------------------------------------------------------- */
6466
/* pqGetc:
@@ -83,6 +85,22 @@ pqGetc(char *result, PGconn *conn)
8385
}
8486

8587

88+
/*
89+
* write 1 char to the connection
90+
*/
91+
int
92+
pqPutc(charc,PGconn*conn)
93+
{
94+
if (pqPutBytes(&c,1,conn)==EOF)
95+
returnEOF;
96+
97+
if (conn->Pfdebug)
98+
fprintf(conn->Pfdebug,"To backend> %c\n",c);
99+
100+
return0;
101+
}
102+
103+
86104
/* --------------------------------------------------------------------- */
87105
/* pqPutBytes: local routine to write N bytes to the connection,
88106
with buffering

‎src/interfaces/libpq/libpq-int.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: libpq-int.h,v 1.33 2001/03/22 04:01:27 momjian Exp $
15+
* $Id: libpq-int.h,v 1.34 2001/07/06 17:58:53 petere Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -278,6 +278,7 @@ struct pg_conn
278278
PQExpBufferDataworkBuffer;/* expansible string */
279279

280280
intclient_encoding;/* encoding id */
281+
intstartup_complete;
281282
};
282283

283284
/* String descriptions of the ExecStatusTypes.
@@ -313,6 +314,7 @@ extern void pqClearAsyncResult(PGconn *conn);
313314
* necessarily any error.
314315
*/
315316
externintpqGetc(char*result,PGconn*conn);
317+
externintpqPutc(charc,PGconn*conn);
316318
externintpqGets(PQExpBufferbuf,PGconn*conn);
317319
externintpqPuts(constchar*s,PGconn*conn);
318320
externintpqGetnchar(char*s,size_tlen,PGconn*conn);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp