]> andersk Git - openssh.git/commitdiff
- djm@cvs.openbsd.org 2009/01/22 10:02:34
authordjm <djm>
Wed, 28 Jan 2009 05:31:22 +0000 (05:31 +0000)
committerdjm <djm>
Wed, 28 Jan 2009 05:31:22 +0000 (05:31 +0000)
     [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@

ChangeLog
clientloop.c
misc.c
readconf.c
readconf.h
servconf.c
servconf.h
serverloop.c
ssh-keyscan.c
ssh.c
sshd.c

index 7b475ff9b143735e527d4ae8dbfe6a48c124b117..fd632fe85164d9e4e4b1fc84277926a2f2959474 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
      [channels.c]
      oops! I committed the wrong version of the Channel->path diff,
      it was missing some tweaks suggested by stevesk@
+   - 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@
 
 20090107
  - (djm) [uidswap.c] bz#1412: Support >16 supplemental groups in OS X.
index fdeedc351d94ea2102bbadc30b393a3645dd9078..1b5badb7163d524a18545b8248a00246d68b3991 100644 (file)
@@ -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
@@ -765,7 +765,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));
@@ -843,7 +843,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;
                }
@@ -1638,7 +1638,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);
@@ -1664,7 +1664,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/misc.c b/misc.c
index 8b303f16f7720f4a4cb5e344394a627f5bacb6a7..755eda10549ca5125eb29e4f7b5fd691973e4ff3 100644 (file)
--- 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
index f63a00c4742de5f5c21f5529d2f31b6f28f18b5f..0a8be140072d4d5cd0fa36e1ceef34730397074b 100644 (file)
@@ -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
@@ -1279,11 +1279,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 &&
index c9e5f6a411c623a66e597839d6ba9c6267924250..d94d65890d291487460ea3c5ea5485017bc5744c 100644 (file)
@@ -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. */
 
index 7d8851860261eca82277318ffafe1a00b0ccc695..e7fc2a7812a78a0343a8012d5b084a328d6b586c 100644 (file)
@@ -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
@@ -42,8 +42,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;
@@ -460,7 +460,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;
 
@@ -476,7 +476,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];
@@ -486,7 +486,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>",
@@ -642,7 +642,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;
 
@@ -699,7 +699,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;
@@ -752,7 +752,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);
@@ -1265,7 +1265,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)
index 1d4c3a01a32d5232629f761a35d20cff5fd2eb25..b3ac7da4b6510dcb7131fa7031a311aa47087585 100644 (file)
@@ -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. */
index 6a3ae16658b71576128acb20b69559c21d386f58..931779e3034b08d83295fe86d7d53c5a0c6e4cce 100644 (file)
@@ -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
@@ -942,7 +942,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();
index c6ec3507ecfc3614f8ff72ffb110d4dcd0fef94e..9a91be499ec7c86fb2049190ee3f0daa71c9c3ae 100644 (file)
@@ -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>.
  *
@@ -748,7 +748,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/ssh.c b/ssh.c
index 5bb67c5b1672018a4e7716f535535b34fd92a44f..26f070f3ead425e7382d7586f593dbc52ce4e799 100644 (file)
--- a/ssh.c
+++ b/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
@@ -443,7 +443,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/sshd.c b/sshd.c
index fa314b8a7c115afa438e0214369db861ad5e1d5f..3b5cd3cfd60edea82dcdce7dc810396f185901b5 100644 (file)
--- a/sshd.c
+++ b/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
@@ -1333,7 +1333,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);
                        }
This page took 0.070746 seconds and 5 git commands to generate.