summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2009-01-22 10:02:35 +0000
committerDamien Miller <djm@cvs.openbsd.org>2009-01-22 10:02:35 +0000
commit0435102032a11e65c85556d97788aaa493e961c5 (patch)
tree427ca5c5b89340e1a6b64f29a1cdd06d754864f6
parenta0c3482df2bba2a7b24e534b155079910aed219d (diff)
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@
-rw-r--r--usr.bin/ssh/clientloop.c10
-rw-r--r--usr.bin/ssh/misc.c22
-rw-r--r--usr.bin/ssh/readconf.c6
-rw-r--r--usr.bin/ssh/readconf.h6
-rw-r--r--usr.bin/ssh/servconf.c20
-rw-r--r--usr.bin/ssh/servconf.h8
-rw-r--r--usr.bin/ssh/serverloop.c4
-rw-r--r--usr.bin/ssh/ssh-keyscan.c4
-rw-r--r--usr.bin/ssh/ssh.c4
-rw-r--r--usr.bin/ssh/sshd.c4
10 files changed, 42 insertions, 46 deletions
diff --git a/usr.bin/ssh/clientloop.c b/usr.bin/ssh/clientloop.c
index 1b67dae3aaf..eeaba5274f5 100644
--- a/usr.bin/ssh/clientloop.c
+++ b/usr.bin/ssh/clientloop.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clientloop.c,v 1.207 2008/12/09 22:37:33 stevesk Exp $ */
+/* $OpenBSD: clientloop.c,v 1.208 2009/01/22 10:02:34 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -756,7 +756,7 @@ process_cmdline(void)
char *s, *cmd, *cancel_host;
int delete = 0;
int local = 0, remote = 0, dynamic = 0;
- u_short cancel_port;
+ int cancel_port;
Forward fwd;
bzero(&fwd, sizeof(fwd));
@@ -834,7 +834,7 @@ process_cmdline(void)
cancel_port = a2port(cancel_host);
cancel_host = NULL;
}
- if (cancel_port == 0) {
+ if (cancel_port <= 0) {
logit("Bad forwarding close port");
goto out;
}
@@ -1626,7 +1626,7 @@ client_request_forwarded_tcpip(const char *request_type, int rchan)
{
Channel *c = NULL;
char *listen_address, *originator_address;
- int listen_port, originator_port;
+ u_short listen_port, originator_port;
/* Get rest of the packet */
listen_address = packet_get_string(NULL);
@@ -1652,7 +1652,7 @@ client_request_x11(const char *request_type, int rchan)
{
Channel *c = NULL;
char *originator;
- int originator_port;
+ u_short originator_port;
int sock;
if (!options.forward_x11) {
diff --git a/usr.bin/ssh/misc.c b/usr.bin/ssh/misc.c
index 78142ecde3a..e7ab17c5d42 100644
--- a/usr.bin/ssh/misc.c
+++ b/usr.bin/ssh/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.
@@ -208,23 +208,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
diff --git a/usr.bin/ssh/readconf.c b/usr.bin/ssh/readconf.c
index 27387009f3c..963709e729f 100644
--- a/usr.bin/ssh/readconf.c
+++ b/usr.bin/ssh/readconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: readconf.c,v 1.174 2009/01/15 17:38:43 stevesk Exp $ */
+/* $OpenBSD: readconf.c,v 1.175 2009/01/22 10:02:34 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1274,11 +1274,11 @@ parse_forward(Forward *fwd, const char *fwdspec, int dynamicfwd)
} else {
if (!(i == 3 || i == 4))
goto fail_free;
- if (fwd->connect_port == 0)
+ if (fwd->connect_port <= 0)
goto fail_free;
}
- if (fwd->listen_port == 0)
+ if (fwd->listen_port <= 0)
goto fail_free;
if (fwd->connect_host != NULL &&
diff --git a/usr.bin/ssh/readconf.h b/usr.bin/ssh/readconf.h
index c9e5f6a411c..d94d65890d2 100644
--- a/usr.bin/ssh/readconf.h
+++ b/usr.bin/ssh/readconf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: readconf.h,v 1.76 2008/11/04 08:22:13 djm Exp $ */
+/* $OpenBSD: readconf.h,v 1.77 2009/01/22 10:02:34 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -20,9 +20,9 @@
typedef struct {
char *listen_host; /* Host (address) to listen on. */
- u_short listen_port; /* Port to forward. */
+ int listen_port; /* Port to forward. */
char *connect_host; /* Host to connect. */
- u_short connect_port; /* Port to connect on connect_host. */
+ int connect_port; /* Port to connect on connect_host. */
} Forward;
/* Data structure for representing option data. */
diff --git a/usr.bin/ssh/servconf.c b/usr.bin/ssh/servconf.c
index 8eba4abc0f0..10e59bc5071 100644
--- a/usr.bin/ssh/servconf.c
+++ b/usr.bin/ssh/servconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: servconf.c,v 1.193 2008/12/09 03:20:42 stevesk Exp $ */
+/* $OpenBSD: servconf.c,v 1.194 2009/01/22 10:02:34 djm Exp $ */
/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
@@ -40,8 +40,8 @@
#include "channels.h"
#include "groupaccess.h"
-static void add_listen_addr(ServerOptions *, char *, u_short);
-static void add_one_listen_addr(ServerOptions *, char *, u_short);
+static void add_listen_addr(ServerOptions *, char *, int);
+static void add_one_listen_addr(ServerOptions *, char *, int);
/* Use of privilege separation or not */
extern int use_privsep;
@@ -423,7 +423,7 @@ parse_token(const char *cp, const char *filename,
}
static void
-add_listen_addr(ServerOptions *options, char *addr, u_short port)
+add_listen_addr(ServerOptions *options, char *addr, int port)
{
u_int i;
@@ -439,7 +439,7 @@ add_listen_addr(ServerOptions *options, char *addr, u_short port)
}
static void
-add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
+add_one_listen_addr(ServerOptions *options, char *addr, int port)
{
struct addrinfo hints, *ai, *aitop;
char strport[NI_MAXSERV];
@@ -449,7 +449,7 @@ add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
hints.ai_family = options->address_family;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
- snprintf(strport, sizeof strport, "%u", port);
+ snprintf(strport, sizeof strport, "%d", port);
if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
fatal("bad addr or host: %s (%s)",
addr ? addr : "<NULL>",
@@ -605,7 +605,7 @@ process_server_config_line(ServerOptions *options, char *line,
SyslogFacility *log_facility_ptr;
LogLevel *log_level_ptr;
ServerOpCodes opcode;
- u_short port;
+ int port;
u_int i, flags = 0;
size_t len;
@@ -656,7 +656,7 @@ process_server_config_line(ServerOptions *options, char *line,
fatal("%s line %d: missing port number.",
filename, linenum);
options->ports[options->num_ports++] = a2port(arg);
- if (options->ports[options->num_ports-1] == 0)
+ if (options->ports[options->num_ports-1] <= 0)
fatal("%s line %d: Badly formatted port number.",
filename, linenum);
break;
@@ -709,7 +709,7 @@ process_server_config_line(ServerOptions *options, char *line,
p = cleanhostname(p);
if (arg == NULL)
port = 0;
- else if ((port = a2port(arg)) == 0)
+ else if ((port = a2port(arg)) <= 0)
fatal("%s line %d: bad port number", filename, linenum);
add_listen_addr(options, p, port);
@@ -1222,7 +1222,7 @@ process_server_config_line(ServerOptions *options, char *line,
fatal("%s line %d: missing host in PermitOpen",
filename, linenum);
p = cleanhostname(p);
- if (arg == NULL || (port = a2port(arg)) == 0)
+ if (arg == NULL || (port = a2port(arg)) <= 0)
fatal("%s line %d: bad port number in "
"PermitOpen", filename, linenum);
if (*activep && n == -1)
diff --git a/usr.bin/ssh/servconf.h b/usr.bin/ssh/servconf.h
index 394f4dd2a35..101b1a4a345 100644
--- a/usr.bin/ssh/servconf.h
+++ b/usr.bin/ssh/servconf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: servconf.h,v 1.86 2008/11/04 08:22:13 djm Exp $ */
+/* $OpenBSD: servconf.h,v 1.87 2009/01/22 10:02:34 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -41,9 +41,9 @@
#define INTERNAL_SFTP_NAME "internal-sftp"
typedef struct {
- u_int num_ports;
- u_int ports_from_cmdline;
- u_short ports[MAX_PORTS]; /* Port number to listen on. */
+ u_int num_ports;
+ u_int ports_from_cmdline;
+ int ports[MAX_PORTS]; /* Port number to listen on. */
char *listen_addr; /* Address on which the server listens. */
struct addrinfo *listen_addrs; /* Addresses on which the server listens. */
int address_family; /* Address family used by the server. */
diff --git a/usr.bin/ssh/serverloop.c b/usr.bin/ssh/serverloop.c
index c7db8ab2176..86ee4ae31d4 100644
--- a/usr.bin/ssh/serverloop.c
+++ b/usr.bin/ssh/serverloop.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: serverloop.c,v 1.154 2008/12/02 19:08:59 markus Exp $ */
+/* $OpenBSD: serverloop.c,v 1.155 2009/01/22 10:02:34 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -910,7 +910,7 @@ server_request_direct_tcpip(void)
{
Channel *c;
char *target, *originator;
- int target_port, originator_port;
+ u_short target_port, originator_port;
target = packet_get_string(NULL);
target_port = packet_get_int();
diff --git a/usr.bin/ssh/ssh-keyscan.c b/usr.bin/ssh/ssh-keyscan.c
index 40a9966b17c..2edfc29db3f 100644
--- a/usr.bin/ssh/ssh-keyscan.c
+++ b/usr.bin/ssh/ssh-keyscan.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keyscan.c,v 1.77 2008/11/01 11:14:36 sobrado Exp $ */
+/* $OpenBSD: ssh-keyscan.c,v 1.78 2009/01/22 10:02:34 djm Exp $ */
/*
* Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
*
@@ -730,7 +730,7 @@ main(int argc, char **argv)
break;
case 'p':
ssh_port = a2port(optarg);
- if (ssh_port == 0) {
+ if (ssh_port <= 0) {
fprintf(stderr, "Bad port '%s'\n", optarg);
exit(1);
}
diff --git a/usr.bin/ssh/ssh.c b/usr.bin/ssh/ssh.c
index a20d156bbe7..912ff5e54dd 100644
--- a/usr.bin/ssh/ssh.c
+++ b/usr.bin/ssh/ssh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh.c,v 1.322 2008/11/01 17:40:33 stevesk Exp $ */
+/* $OpenBSD: ssh.c,v 1.323 2009/01/22 10:02:34 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -430,7 +430,7 @@ main(int ac, char **av)
break;
case 'p':
options.port = a2port(optarg);
- if (options.port == 0) {
+ if (options.port <= 0) {
fprintf(stderr, "Bad port '%s'\n", optarg);
exit(255);
}
diff --git a/usr.bin/ssh/sshd.c b/usr.bin/ssh/sshd.c
index 4624fb2cf9d..d28b0ac9535 100644
--- a/usr.bin/ssh/sshd.c
+++ b/usr.bin/ssh/sshd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshd.c,v 1.365 2008/10/30 19:31:16 stevesk Exp $ */
+/* $OpenBSD: sshd.c,v 1.366 2009/01/22 10:02:34 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1273,7 +1273,7 @@ main(int ac, char **av)
exit(1);
}
options.ports[options.num_ports++] = a2port(optarg);
- if (options.ports[options.num_ports-1] == 0) {
+ if (options.ports[options.num_ports-1] <= 0) {
fprintf(stderr, "Bad port number.\n");
exit(1);
}