Skip to content

Commit a3fa671

Browse files
authored
Merge pull request FRRouting#20082 from krishna-samy/krishnasamyr/coverity
lib: Coverity fixes
2 parents 19e7bd3 + 9ea7622 commit a3fa671

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

lib/if.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,8 @@ void if_terminate(struct vrf *vrf)
10751075

10761076
while (!RB_EMPTY(if_name_head, &vrf->ifaces_by_name)) {
10771077
ifp = RB_ROOT(if_name_head, &vrf->ifaces_by_name);
1078+
if (!ifp)
1079+
break;
10781080
if_delete(&ifp);
10791081
}
10801082
}
@@ -1589,6 +1591,12 @@ static int lib_interface_create(struct nb_cb_create_args *args)
15891591
VRF_DEFAULT_NAME);
15901592
}
15911593

1594+
if (!ifp) {
1595+
snprintf(args->errmsg, args->errmsg_len, "failed to create interface '%s'",
1596+
ifname);
1597+
return NB_ERR_RESOURCE;
1598+
}
1599+
15921600
ifp->configured = true;
15931601
nb_running_set_entry(args->dnode, ifp);
15941602
break;

lib/nexthop_group.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,8 @@ void nexthop_group_json_nexthop(json_object *j, const struct nexthop *nh)
11151115

11161116
if (nh->vrf_id != VRF_DEFAULT) {
11171117
vrf = vrf_lookup_by_id(nh->vrf_id);
1118-
json_object_string_add(j, "targetVrf", vrf->name);
1118+
/* When VRF is not initialized or unknown, show the target VRF as none */
1119+
json_object_string_add(j, "targetVrf", vrf ? vrf->name : "-");
11191120
}
11201121

11211122
if (nh->nh_label && nh->nh_label->num_labels > 0) {

lib/vrf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@ void vrf_bitmap_set(vrf_bitmap_t *pbmap, vrf_id_t vrf_id)
487487
vrf_hash = *pbmap;
488488

489489
bit = hash_get(vrf_hash, &lookup, vrf_hash_bitmap_alloc);
490+
if (!bit)
491+
return;
490492
bit->set = true;
491493
}
492494

@@ -1027,6 +1029,8 @@ static const void *lib_vrf_lookup_next(struct nb_cb_lookup_entry_args *args)
10271029

10281030
strlcpy(vrfkey.name, vrfname, sizeof(vrfkey.name));
10291031
vrf = RB_FIND(vrf_name_head, &vrfs_by_name, &vrfkey);
1032+
if (!vrf)
1033+
return NULL;
10301034
if (!strcmp(vrf->name, vrfname))
10311035
vrf = RB_NEXT(vrf_name_head, vrf);
10321036

0 commit comments

Comments
 (0)