Skip to content

Commit

Permalink
lib: fix error handling in nl_str2ip_proto()
Browse files Browse the repository at this point in the history
  • Loading branch information
thom311 committed Aug 18, 2023
1 parent 09f03f2 commit 8ee8b05
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ int nl_str2ip_proto(const char *name)
return p->p_proto;

l = strtoul(name, &end, 0);
if (l == ULONG_MAX || *end != '\0')
if (name == end || *end != '\0' || l > (unsigned long)INT_MAX)
return -NLE_OBJ_NOTFOUND;

return (int) l;
Expand Down
4 changes: 2 additions & 2 deletions tests/check-direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ START_TEST(static_checks)
ck_assert_int_eq(i, rtnl_link_str2stat(s));
}

ck_assert_int_eq(nl_str2ip_proto(""), 0);
ck_assert_int_eq(nl_str2ip_proto(""), -NLE_OBJ_NOTFOUND);
ck_assert_int_eq(nl_str2ip_proto("5"), 5);
ck_assert_int_eq(nl_str2ip_proto(" 13 "), -NLE_OBJ_NOTFOUND);
ck_assert_int_eq(nl_str2ip_proto("13"), 13);
ck_assert_int_eq(nl_str2ip_proto("0x13"), 0x13);
ck_assert_int_eq(nl_str2ip_proto("0342"), 0342);
ck_assert_int_eq(nl_str2ip_proto("2147483647"), 2147483647);
ck_assert_int_eq(nl_str2ip_proto("2147483648"), -2147483648);
ck_assert_int_eq(nl_str2ip_proto("2147483648"), -NLE_OBJ_NOTFOUND);
}
END_TEST

Expand Down

0 comments on commit 8ee8b05

Please sign in to comment.