diff options
author | delphij <delphij@FreeBSD.org> | 2014-09-25 22:37:27 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2014-09-25 22:37:27 +0000 |
commit | d8ef9b3342dce9245e3438162b0c68f65e684155 (patch) | |
tree | ed6a16025fe029b95c9ead46225b9256588a1a84 /sbin/sysctl | |
parent | ce631e38133b2b7ec19fcf840d3c333e91c0ac39 (diff) | |
download | FreeBSD-src-d8ef9b3342dce9245e3438162b0c68f65e684155.zip FreeBSD-src-d8ef9b3342dce9245e3438162b0c68f65e684155.tar.gz |
The strtol(3) family of functions would set errno when it hits one.
Check errno and handle it as invalid input.
Obtained from: HardenedBSD
Submitted by: David CARLIER <devnexen@gmail.com>
MFC after: 2 weeks
Diffstat (limited to 'sbin/sysctl')
-rw-r--r-- | sbin/sysctl/sysctl.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index f9207f1..d7fe8e9 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -305,7 +305,8 @@ parse(const char *string, int lineno) } else { intval = (int)strtol(newval, &endptr, 0); - if (endptr == newval || *endptr != '\0') { + if (errno != 0 || endptr == newval || + *endptr != '\0') { warnx("invalid integer '%s'%s", (char *)newval, line); return (1); @@ -316,7 +317,8 @@ parse(const char *string, int lineno) break; case CTLTYPE_UINT: uintval = (int) strtoul(newval, &endptr, 0); - if (endptr == newval || *endptr != '\0') { + if (errno != 0 || endptr == newval || + *endptr != '\0') { warnx("invalid unsigned integer '%s'%s", (char *)newval, line); return (1); @@ -326,7 +328,8 @@ parse(const char *string, int lineno) break; case CTLTYPE_LONG: longval = strtol(newval, &endptr, 0); - if (endptr == newval || *endptr != '\0') { + if (errno != 0 || endptr == newval || + *endptr != '\0') { warnx("invalid long integer '%s'%s", (char *)newval, line); return (1); @@ -336,7 +339,8 @@ parse(const char *string, int lineno) break; case CTLTYPE_ULONG: ulongval = strtoul(newval, &endptr, 0); - if (endptr == newval || *endptr != '\0') { + if (errno != 0 || endptr == newval || + *endptr != '\0') { warnx("invalid unsigned long integer" " '%s'%s", (char *)newval, line); return (1); @@ -348,7 +352,8 @@ parse(const char *string, int lineno) break; case CTLTYPE_S64: i64val = strtoimax(newval, &endptr, 0); - if (endptr == newval || *endptr != '\0') { + if (errno != 0 || endptr == newval || + *endptr != '\0') { warnx("invalid int64_t '%s'%s", (char *)newval, line); return (1); @@ -358,7 +363,8 @@ parse(const char *string, int lineno) break; case CTLTYPE_U64: u64val = strtoumax(newval, &endptr, 0); - if (endptr == newval || *endptr != '\0') { + if (errno != 0 || endptr == newval || + *endptr != '\0') { warnx("invalid uint64_t '%s'%s", (char *)newval, line); return (1); @@ -669,14 +675,16 @@ set_IK(const char *str, int *val) p = &str[len - 1]; if (*p == 'C' || *p == 'F') { temp = strtof(str, &endptr); - if (endptr == str || endptr != p) + if (errno != 0 || endptr == str || + endptr != p) return (0); if (*p == 'F') temp = (temp - 32) * 5 / 9; kelv = temp * 10 + 2732; } else { kelv = (int)strtol(str, &endptr, 10); - if (endptr == str || *endptr != '\0') + if (errno != 0 || endptr == str || + *endptr != '\0') return (0); } *val = kelv; |