summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYunjian Wang <wangyunjian@huawei.com>2023-04-21 16:27:10 +0800
committerIlya Maximets <i.maximets@ovn.org>2023-04-25 21:56:05 +0200
commitb7e1593f4cde3d87c39d9ac16f33b77d387d3b5a (patch)
tree2b1f4c59b63168b311ba8840e42e65bd522e0294
parent70cb45c665190c09fe3f7cbd86b25f1fc5358986 (diff)
downloadopenvswitch-b7e1593f4cde3d87c39d9ac16f33b77d387d3b5a.tar.gz
ofp-parse: Check ranges on string to uint32_t conversion.
An unnecessarily overflow would occurs when the 'value' is longer than 4294967295. So it's required to check ranges to avoid uint32_t overflow. Reported-by: Nan Zhou <zhounan14@huawei.com> Acked-by: Eelco Chaudron <echaudro@redhat.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
-rw-r--r--lib/ofp-parse.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c
index a90b926ef..102b183a8 100644
--- a/lib/ofp-parse.c
+++ b/lib/ofp-parse.c
@@ -71,16 +71,13 @@ str_to_u16(const char *str, const char *name, uint16_t *valuep)
char * OVS_WARN_UNUSED_RESULT
str_to_u32(const char *str, uint32_t *valuep)
{
- char *tail;
- uint32_t value;
+ unsigned long long value;
if (!str[0]) {
return xstrdup("missing required numeric argument");
}
- errno = 0;
- value = strtoul(str, &tail, 0);
- if (errno == EINVAL || errno == ERANGE || *tail) {
+ if (!str_to_ullong(str, 0, &value) || value > UINT32_MAX) {
return xasprintf("invalid numeric format %s", str);
}
*valuep = value;