summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/misc.c
diff options
context:
space:
mode:
authorKevin Steves <stevesk@cvs.openbsd.org>2001-04-12 20:09:39 +0000
committerKevin Steves <stevesk@cvs.openbsd.org>2001-04-12 20:09:39 +0000
commite57cfb6e67a9083afbbf8ef90cc40f20f3cc0cae (patch)
tree9c6a40aa55acc3e7cd847d65b01b96fc26a1ad9a /usr.bin/ssh/misc.c
parent16b07b0d75cefdf012d4d5121c56a888154ae47d (diff)
robust port validation; ok markus@ jakob@
Diffstat (limited to 'usr.bin/ssh/misc.c')
-rw-r--r--usr.bin/ssh/misc.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/usr.bin/ssh/misc.c b/usr.bin/ssh/misc.c
index 0399725eaaa..b5c0fd1734c 100644
--- a/usr.bin/ssh/misc.c
+++ b/usr.bin/ssh/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.4 2001/02/28 17:52:54 deraadt Exp $ */
+/* $OpenBSD: misc.c,v 1.5 2001/04/12 20:09:37 stevesk Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -25,7 +25,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: misc.c,v 1.4 2001/02/28 17:52:54 deraadt Exp $");
+RCSID("$OpenBSD: misc.c,v 1.5 2001/04/12 20:09:37 stevesk Exp $");
#include "misc.h"
#include "log.h"
@@ -113,3 +113,18 @@ pwcopy(struct passwd *pw)
copy->pw_shell = xstrdup(pw->pw_shell);
return copy;
}
+
+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;
+
+ return port;
+}