summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authordjm <djm>2009-01-28 05:31:22 +0000
committerdjm <djm>2009-01-28 05:31:22 +0000
commit9060986622442a52685aa8dc99d7b57a3b53cfb6 (patch)
treee903cafd701aa01d833f5d638180ac4a7680f178 /misc.c
parent087a1f1e2dfc0fe12271427999753ca68954fe1d (diff)
downloadopenssh-9060986622442a52685aa8dc99d7b57a3b53cfb6.tar.gz
- djm@cvs.openbsd.org 2009/01/22 10:02:34
[clientloop.c misc.c readconf.c readconf.h servconf.c servconf.h] [serverloop.c ssh-keyscan.c ssh.c sshd.c] make a2port() return -1 when it encounters an invalid port number rather than 0, which it will now treat as valid (needed for future work) adjust current consumers of a2port() to check its return value is <= 0, which in turn required some things to be converted from u_short => int make use of int vs. u_short consistent in some other places too feedback & ok markus@
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/misc.c b/misc.c
index 8b303f16..755eda10 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.69 2008/06/13 01:38:23 dtucker Exp $ */
+/* $OpenBSD: misc.c,v 1.70 2009/01/22 10:02:34 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -221,23 +221,19 @@ pwcopy(struct passwd *pw)
/*
* Convert ASCII string to TCP/IP port number.
- * Port must be >0 and <=65535.
- * Return 0 if invalid.
+ * Port must be >=0 and <=65535.
+ * Return -1 if invalid.
*/
int
a2port(const char *s)
{
- long port;
- char *endp;
-
- errno = 0;
- port = strtol(s, &endp, 0);
- if (s == endp || *endp != '\0' ||
- (errno == ERANGE && (port == LONG_MIN || port == LONG_MAX)) ||
- port <= 0 || port > 65535)
- return 0;
+ long long port;
+ const char *errstr;
- return port;
+ port = strtonum(s, 0, 65535, &errstr);
+ if (errstr != NULL)
+ return -1;
+ return (int)port;
}
int