diff options
author | Damien Miller <djm@mindrot.org> | 2009-01-28 16:31:22 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2009-01-28 16:31:22 +1100 |
commit | 3dc71ad8653bab5591fc75bb1d3e6aa8fb9360df (patch) | |
tree | c41a8152c222b8bebb63d9d9185e8a160b71a5a0 /misc.c | |
parent | 9576ac4afc7124415183dd9fe73d410165dbfe82 (diff) |
- 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.c | 22 |
1 files changed, 9 insertions, 13 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.c,v 1.69 2008/06/13 01:38:23 dtucker Exp $ */ | 1 | /* $OpenBSD: misc.c,v 1.70 2009/01/22 10:02:34 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. |
@@ -221,23 +221,19 @@ pwcopy(struct passwd *pw) | |||
221 | 221 | ||
222 | /* | 222 | /* |
223 | * Convert ASCII string to TCP/IP port number. | 223 | * Convert ASCII string to TCP/IP port number. |
224 | * Port must be >0 and <=65535. | 224 | * Port must be >=0 and <=65535. |
225 | * Return 0 if invalid. | 225 | * Return -1 if invalid. |
226 | */ | 226 | */ |
227 | int | 227 | int |
228 | a2port(const char *s) | 228 | a2port(const char *s) |
229 | { | 229 | { |
230 | long port; | 230 | long long port; |
231 | char *endp; | 231 | const char *errstr; |
232 | |||
233 | errno = 0; | ||
234 | port = strtol(s, &endp, 0); | ||
235 | if (s == endp || *endp != '\0' || | ||
236 | (errno == ERANGE && (port == LONG_MIN || port == LONG_MAX)) || | ||
237 | port <= 0 || port > 65535) | ||
238 | return 0; | ||
239 | 232 | ||
240 | return port; | 233 | port = strtonum(s, 0, 65535, &errstr); |
234 | if (errstr != NULL) | ||
235 | return -1; | ||
236 | return (int)port; | ||
241 | } | 237 | } |
242 | 238 | ||
243 | int | 239 | int |