mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
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
This commit is contained in:
parent
97d15a9372
commit
9e4ed37219
1 changed files with 16 additions and 8 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue