aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-09-27 03:43:10 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-09-27 03:43:10 +0000
commit61be11ff088c1e2b22c7e2af6f93ccdc286dba01 (patch)
tree5ba697c620d7ba5d55ea69b1bb6757718ca8d285
parent799ac992014374c23a1fc437f4fd9aa413be4920 (diff)
downloadpostgresql-61be11ff088c1e2b22c7e2af6f93ccdc286dba01.tar.gz
postgresql-61be11ff088c1e2b22c7e2af6f93ccdc286dba01.zip
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.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 41c753a4f8c..1be948505e5 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.376 2009/07/24 17:58:31 tgl Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.377 2009/09/27 03:43:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -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);