diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 07:43:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 07:43:00 +0000 |
commit | f74e883352a52dd3ed454627dc159aa65f98d7f3 (patch) | |
tree | ef77b7637e7135f0f61cad9ae9923215ed60066b /misc.c | |
parent | Adding debian version 1:9.7p1-7. (diff) | |
download | openssh-f74e883352a52dd3ed454627dc159aa65f98d7f3.tar.xz openssh-f74e883352a52dd3ed454627dc159aa65f98d7f3.zip |
Merging upstream version 1:9.8p1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 100 |
1 files changed, 70 insertions, 30 deletions
@@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.190 2024/03/04 02:16:11 djm Exp $ */ +/* $OpenBSD: misc.c,v 1.196 2024/06/06 17:15:25 djm Exp $ */ /* * Copyright (c) 2000 Markus Friedl. All rights reserved. * Copyright (c) 2005-2020 Damien Miller. All rights reserved. @@ -563,6 +563,14 @@ a2tun(const char *s, int *remote) #define DAYS (HOURS * 24) #define WEEKS (DAYS * 7) +static char * +scandigits(char *s) +{ + while (isdigit((unsigned char)*s)) + s++; + return s; +} + /* * Convert a time string into seconds; format is * a sequence of: @@ -587,28 +595,31 @@ a2tun(const char *s, int *remote) int convtime(const char *s) { - long total, secs, multiplier; - const char *p; - char *endp; - - errno = 0; - total = 0; - p = s; + int secs, total = 0, multiplier; + char *p, *os, *np, c = 0; + const char *errstr; - if (p == NULL || *p == '\0') + if (s == NULL || *s == '\0') + return -1; + p = os = strdup(s); /* deal with const */ + if (os == NULL) return -1; while (*p) { - secs = strtol(p, &endp, 10); - if (p == endp || - (errno == ERANGE && (secs == INT_MIN || secs == INT_MAX)) || - secs < 0) - return -1; + np = scandigits(p); + if (np) { + c = *np; + *np = '\0'; + } + secs = (int)strtonum(p, 0, INT_MAX, &errstr); + if (errstr) + goto fail; + *np = c; multiplier = 1; - switch (*endp++) { + switch (c) { case '\0': - endp--; + np--; /* back up */ break; case 's': case 'S': @@ -630,20 +641,23 @@ convtime(const char *s) multiplier = WEEKS; break; default: - return -1; + goto fail; } if (secs > INT_MAX / multiplier) - return -1; + goto fail; secs *= multiplier; if (total > INT_MAX - secs) - return -1; + goto fail; total += secs; if (total < 0) - return -1; - p = endp; + goto fail; + p = ++np; } - + free(os); return total; +fail: + free(os); + return -1; } #define TF_BUFS 8 @@ -1859,9 +1873,9 @@ static const struct { int parse_ipqos(const char *cp) { + const char *errstr; u_int i; - char *ep; - long val; + int val; if (cp == NULL) return -1; @@ -1870,8 +1884,8 @@ parse_ipqos(const char *cp) return ipqos[i].value; } /* Try parsing as an integer */ - val = strtol(cp, &ep, 0); - if (*cp == '\0' || *ep != '\0' || val < 0 || val > 255) + val = (int)strtonum(cp, 0, 255, &errstr); + if (errstr) return -1; return val; } @@ -1990,6 +2004,19 @@ forward_equals(const struct Forward *a, const struct Forward *b) return 1; } +/* returns port number, FWD_PERMIT_ANY_PORT or -1 on error */ +int +permitopen_port(const char *p) +{ + int port; + + if (strcmp(p, "*") == 0) + return FWD_PERMIT_ANY_PORT; + if ((port = a2port(p)) > 0) + return port; + return -1; +} + /* returns 1 if process is already daemonized, 0 otherwise */ int daemonized(void) @@ -2414,13 +2441,10 @@ const char * atoi_err(const char *nptr, int *val) { const char *errstr = NULL; - long long num; if (nptr == NULL || *nptr == '\0') return "missing"; - num = strtonum(nptr, 0, INT_MAX, &errstr); - if (errstr == NULL) - *val = (int)num; + *val = strtonum(nptr, 0, INT_MAX, &errstr); return errstr; } @@ -3076,3 +3100,19 @@ lib_contains_symbol(const char *path, const char *s) return ret; #endif /* HAVE_NLIST_H */ } + +int +signal_is_crash(int sig) +{ + switch (sig) { + case SIGSEGV: + case SIGBUS: + case SIGTRAP: + case SIGSYS: + case SIGFPE: + case SIGILL: + case SIGABRT: + return 1; + } + return 0; +} |