Skip to content

Commit

Permalink
ovn-nbctl: Fix unhandled NULL return from normalize_prefix_str
Browse files Browse the repository at this point in the history
The normalize_prefix_str returns NULL when it fails to
normalize the specified string. Prevent UB with formatting
NULL with %s and simplify the free pattern.

Signed-off-by: Ales Musil <amusil@redhat.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Acked-by: Mark Michelson <mmichels@redhat.com>
Signed-off-by: Mark Michelson <mmichels@redhat.com>
  • Loading branch information
almusil authored and putnopvut committed May 2, 2023
1 parent 9e34292 commit 1fb1eb5
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions utilities/ovn-nbctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4204,8 +4204,7 @@ print_routing_policy(const struct nbrec_logical_router_policy *policy,
policy->match, policy->action);
for (int i = 0; i < policy->n_nexthops; i++) {
char *next_hop = normalize_prefix_str(policy->nexthops[i]);
char *fmt = i ? ", %s" : " %25s";
ds_put_format(s, fmt, next_hop);
ds_put_format(s, i ? ", %s" : " %25s", next_hop ? next_hop : "");
free(next_hop);
}
} else {
Expand Down Expand Up @@ -6586,18 +6585,17 @@ print_route(const struct nbrec_logical_router_static_route *route,
{

char *prefix = normalize_prefix_str(route->ip_prefix);
char *next_hop = "";
char *next_hop = NULL;

if (!strcmp(route->nexthop, "discard")) {
next_hop = xasprintf("discard");
} else if (route->nexthop[0]) {
next_hop = normalize_prefix_str(route->nexthop);
}
ds_put_format(s, "%25s %25s", prefix, next_hop);
ds_put_format(s, "%25s %25s", prefix ? prefix : "",
next_hop ? next_hop : "");
free(prefix);
if (next_hop[0]) {
free(next_hop);
}
free(next_hop);

if (route->policy) {
ds_put_format(s, " %s", route->policy);
Expand Down

0 comments on commit 1fb1eb5

Please sign in to comment.