@@ -1899,17 +1899,34 @@ ProcessStartupPacket(Port *port, bool SSLdone)
18991899 MemoryContext oldcontext ;
19001900
19011901 pq_startmsgread ();
1902- if (pq_getbytes ((char * ) & len , 4 ) == EOF )
1902+
1903+ /*
1904+ * Grab the first byte of the length word separately, so that we can tell
1905+ * whether we have no data at all or an incomplete packet. (This might
1906+ * sound inefficient, but it's not really, because of buffering in
1907+ * pqcomm.c.)
1908+ */
1909+ if (pq_getbytes ((char * ) & len , 1 ) == EOF )
19031910 {
19041911 /*
1905- * EOF after SSLdone probably means the client didn't like our
1906- * response to NEGOTIATE_SSL_CODE. That's not an error condition, so
1907- * don't clutter the log with a complaint.
1912+ * If we get no data at all, don't clutter the log with a complaint;
1913+ * such cases often occur for legitimate reasons. An example is that
1914+ * we might be here after responding to NEGOTIATE_SSL_CODE, and if the
1915+ * client didn't like our response, it'll probably just drop the
1916+ * connection. Service-monitoring software also often just opens and
1917+ * closes a connection without sending anything. (So do port
1918+ * scanners, which may be less benign, but it's not really our job to
1919+ * notice those.)
19081920 */
1909- if (!SSLdone )
1910- ereport (COMMERROR ,
1911- (errcode (ERRCODE_PROTOCOL_VIOLATION ),
1912- errmsg ("incomplete startup packet" )));
1921+ return STATUS_ERROR ;
1922+ }
1923+
1924+ if (pq_getbytes (((char * ) & len ) + 1 , 3 ) == EOF )
1925+ {
1926+ /* Got a partial length word, so bleat about that */
1927+ ereport (COMMERROR ,
1928+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
1929+ errmsg ("incomplete startup packet" )));
19131930 return STATUS_ERROR ;
19141931 }
19151932
0 commit comments