From: Peter Eisentraut <peter_e@gmx.net>
Date: Tue, 7 Aug 2001 10:44:16 +0000 (+0000)
Subject: Add a check for end of client connection before expecting a password
X-Git-Tag: REL7_2_BETA1~751
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=50036e85b35eb8eaa3f25da836959a9dd986a2c6;p=postgresql

Add a check for end of client connection before expecting a password
response, to avoid noise in the server log.
---

diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index 77bcc4ef23..81d4865ce6 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.55 2001/08/01 23:25:39 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.56 2001/08/07 10:44:13 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -554,7 +554,7 @@ recv_and_check_password_packet(Port *port)
 	int32		len;
 	int			result;
 
-	if (pq_getint(&len, 4) == EOF)
+	if (pq_eof() == EOF || pq_getint(&len, 4) == EOF)
 		return STATUS_ERROR;	/* client didn't want to send password */
 	initStringInfo(&buf);
 	pq_getstr(&buf);
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 56148c857b..e5d6c1f7b0 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -29,7 +29,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- *	$Id: pqcomm.c,v 1.119 2001/08/05 01:22:16 tgl Exp $
+ *	$Id: pqcomm.c,v 1.120 2001/08/07 10:44:15 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -695,6 +695,26 @@ pq_flush(void)
 }
 
 
+/*
+ * Return EOF if the connection has been broken, else 0.
+ */
+int
+pq_eof(void)
+{
+	char x;
+	int res;
+
+	res = recv(MyProcPort->sock, &x, 1, MSG_PEEK);
+
+	if (res == -1)
+		fprintf(stderr, "pq_eof: recv() failed: %s\n", strerror(errno));
+	else if (res == 0)
+		return EOF;
+	else
+		return 0;
+}
+
+
 /* --------------------------------
  * Message-level I/O routines begin here.
  *
diff --git a/src/include/libpq/libpq.h b/src/include/libpq/libpq.h
index 4ab823e546..9390219838 100644
--- a/src/include/libpq/libpq.h
+++ b/src/include/libpq/libpq.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: libpq.h,v 1.44 2001/03/22 04:00:48 momjian Exp $
+ * $Id: libpq.h,v 1.45 2001/08/07 10:44:16 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -65,6 +65,7 @@ extern int	pq_getstring(StringInfo s);
 extern int	pq_peekbyte(void);
 extern int	pq_putbytes(const char *s, size_t len);
 extern int	pq_flush(void);
+extern int	pq_eof(void);
 extern int	pq_putmessage(char msgtype, const char *s, size_t len);
 extern void pq_startcopyout(void);
 extern void pq_endcopyout(bool errorAbort);