diff options
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 27 |
1 files changed, 12 insertions, 15 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.71 2009/02/21 19:32:04 tobias 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 |
@@ -718,7 +714,8 @@ sanitise_stdfd(void) | |||
718 | int nullfd, dupfd; | 714 | int nullfd, dupfd; |
719 | 715 | ||
720 | if ((nullfd = dupfd = open(_PATH_DEVNULL, O_RDWR)) == -1) { | 716 | if ((nullfd = dupfd = open(_PATH_DEVNULL, O_RDWR)) == -1) { |
721 | fprintf(stderr, "Couldn't open /dev/null: %s", strerror(errno)); | 717 | fprintf(stderr, "Couldn't open /dev/null: %s\n", |
718 | strerror(errno)); | ||
722 | exit(1); | 719 | exit(1); |
723 | } | 720 | } |
724 | while (++dupfd <= 2) { | 721 | while (++dupfd <= 2) { |
@@ -726,7 +723,7 @@ sanitise_stdfd(void) | |||
726 | if (fcntl(dupfd, F_GETFL, 0) >= 0) | 723 | if (fcntl(dupfd, F_GETFL, 0) >= 0) |
727 | continue; | 724 | continue; |
728 | if (dup2(nullfd, dupfd) == -1) { | 725 | if (dup2(nullfd, dupfd) == -1) { |
729 | fprintf(stderr, "dup2: %s", strerror(errno)); | 726 | fprintf(stderr, "dup2: %s\n", strerror(errno)); |
730 | exit(1); | 727 | exit(1); |
731 | } | 728 | } |
732 | } | 729 | } |