Skip to content

Commit 61be11f

Browse files
committed
Make libpq reject non-numeric and out-of-range port numbers with a suitable
error message, rather than blundering on and failing with something opaque. Sam Mason
1 parent 799ac99 commit 61be11f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.376 2009/07/24 17:58:31 tgl Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.377 2009/09/27 03:43:10 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -817,7 +817,16 @@ connectDBStart(PGconn *conn)
817817

818818
/* Set up port number as a string */
819819
if (conn->pgport != NULL && conn->pgport[0] != '\0')
820+
{
820821
portnum = atoi(conn->pgport);
822+
if (portnum < 1 || portnum > 65535)
823+
{
824+
appendPQExpBuffer(&conn->errorMessage,
825+
libpq_gettext("invalid port number: \"%s\"\n"),
826+
conn->pgport);
827+
goto connect_errReturn;
828+
}
829+
}
821830
else
822831
portnum = DEF_PGPORT;
823832
snprintf(portstr, sizeof(portstr), "%d", portnum);

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