Message ID | 1682065630-22584-1-git-send-email-wangyunjian@huawei.com |
---|---|
State | Accepted |
Commit | 8d59ab31d2a74003a3f2b83d67e2ba78e1a1225d |
Headers | show |
Series | [ovs-dev,v3] ofp-parse: Check ranges on string to uint32_t conversion. | expand |
Context | Check | Description |
---|---|---|
ovsrobot/apply-robot | success | apply and check: success |
ovsrobot/github-robot-_Build_and_Test | success | github build: passed |
ovsrobot/intel-ovs-compilation | success | test: success |
On 21 Apr 2023, at 10:27, Yunjian Wang wrote: > 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> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com> Thanks for addressing my comment. It looks good to me. Acked-by: Eelco Chaudron <echaudro@redhat.com>
On Fri, Apr 21, 2023 at 10:49:41AM +0200, Eelco Chaudron wrote: > > > On 21 Apr 2023, at 10:27, Yunjian Wang wrote: > > > 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> > > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com> > > Thanks for addressing my comment. It looks good to me. > > Acked-by: Eelco Chaudron <echaudro@redhat.com> Reviewed-by: Simon Horman <simon.horman@corigine.com>
On 4/21/23 11:32, Simon Horman wrote: > On Fri, Apr 21, 2023 at 10:49:41AM +0200, Eelco Chaudron wrote: >> >> >> On 21 Apr 2023, at 10:27, Yunjian Wang wrote: >> >>> 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> >>> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com> >> >> Thanks for addressing my comment. It looks good to me. >> >> Acked-by: Eelco Chaudron <echaudro@redhat.com> > > Reviewed-by: Simon Horman <simon.horman@corigine.com> Thanks! Applied and backported down to 2.17. Best regards, Ilya Maximets.
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;
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> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com> --- v3: fix patch code styles --- lib/ofp-parse.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)