diff options
author | John Polstra <jdp@FreeBSD.org> | 2001-05-19 19:36:32 +0000 |
---|---|---|
committer | John Polstra <jdp@FreeBSD.org> | 2001-05-19 19:36:32 +0000 |
commit | a514569e9af544603208d61ed8a70a8e9a16be53 (patch) | |
tree | d2d36a230346aca6a2055247ae736d7d74fcb9a4 /sys/netgraph/ng_parse.c | |
parent | dc01275be969f600d6cafce55725315658c517d0 (diff) | |
download | src-a514569e9af544603208d61ed8a70a8e9a16be53.tar.gz src-a514569e9af544603208d61ed8a70a8e9a16be53.zip |
Fix a range checking bug in ng_int32_parse which affected 64-bit
machines. The code formerly read:
long val;
if (val < (long)-0x80000000 || ...)
return EINVAL;
The constant 0x80000000 has type unsigned int. The unary `-'
operator does not change the type (or the value, in this case).
Therefore the promotion to long is done by 0-extension, giving
0x0000000080000000 instead of the desired 0xffffffff80000000. I
got rid of the `-' and changed the cast to (int32_t) to give proper
sign-extension on all architectures and to better reflect the fact
that we are range-checking a 32-bit value.
This commit also makes the analogous changes to ng_int{8,16}_parse
for consistency.
MFC after: 3 days
Notes
Notes:
svn path=/head/; revision=76860
Diffstat (limited to 'sys/netgraph/ng_parse.c')
-rw-r--r-- | sys/netgraph/ng_parse.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/sys/netgraph/ng_parse.c b/sys/netgraph/ng_parse.c index cd545c33a274..5daf600a0ef5 100644 --- a/sys/netgraph/ng_parse.c +++ b/sys/netgraph/ng_parse.c @@ -345,7 +345,7 @@ ng_int8_parse(const struct ng_parse_type *type, char *eptr; val = strtol(s + *off, &eptr, 0); - if (val < -0x80 || val > 0xff || eptr == s + *off) + if (val < (int8_t)0x80 || val > (u_int8_t)0xff || eptr == s + *off) return (EINVAL); *off = eptr - s; val8 = (int8_t)val; @@ -438,7 +438,8 @@ ng_int16_parse(const struct ng_parse_type *type, char *eptr; val = strtol(s + *off, &eptr, 0); - if (val < -0x8000 || val > 0xffff || eptr == s + *off) + if (val < (int16_t)0x8000 + || val > (u_int16_t)0xffff || eptr == s + *off) return (EINVAL); *off = eptr - s; val16 = (int16_t)val; @@ -531,8 +532,8 @@ ng_int32_parse(const struct ng_parse_type *type, char *eptr; val = strtol(s + *off, &eptr, 0); - if (val < (long)-0x80000000 - || val > (u_long)0xffffffff || eptr == s + *off) + if (val < (int32_t)0x80000000 + || val > (u_int32_t)0xffffffff || eptr == s + *off) return (EINVAL); *off = eptr - s; val32 = (int32_t)val; |