summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2009-09-27 03:43:10 +0000
committerTom Lane2009-09-27 03:43:10 +0000
commit1e36f87b7b6ecafaf4c8a2b25f892525e62c1d78 (patch)
treee775f439c1c7bcd9f15deeab494da7c0c935e1c7
parent062de17aab0e4a1fd05044c0f4dd67f4a45c44ab (diff)
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
-rw-r--r--src/interfaces/libpq/fe-connect.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 38b3823586..011ebab1d5 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -817,7 +817,16 @@ connectDBStart(PGconn *conn)
/* Set up port number as a string */
if (conn->pgport != NULL && conn->pgport[0] != '\0')
+ {
portnum = atoi(conn->pgport);
+ if (portnum < 1 || portnum > 65535)
+ {
+ appendPQExpBuffer(&conn->errorMessage,
+ libpq_gettext("invalid port number: \"%s\"\n"),
+ conn->pgport);
+ goto connect_errReturn;
+ }
+ }
else
portnum = DEF_PGPORT;
snprintf(portstr, sizeof(portstr), "%d", portnum);