Skip to content

Commit d473b90

Browse files
committed
fixed bugs found by static analyzer
1 parent 94a0f7e commit d473b90

6 files changed

Lines changed: 22 additions & 8 deletions

File tree

extra/glue.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp,
222222
oid->id = DN_API_VERSION;
223223

224224
ret = do_cmd(-IP_DUMMYNET3, oid, (uintptr_t)&l);
225-
if (ret != 0)
225+
if (ret != 0) {
226+
free(oid);
226227
return -1;
228+
}
227229

228230
l=oid->id;
229231
free(oid);
@@ -235,8 +237,10 @@ sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp,
235237
oid->id = DN_API_VERSION;
236238

237239
ret = do_cmd(-IP_DUMMYNET3, oid, (uintptr_t)&l);
238-
if (ret != 0)
240+
if (ret != 0) {
241+
free(oid);
239242
return -1;
243+
}
240244

241245
entry = (struct sysctlhead*)(oid+1);
242246
while(entry->blocklen != 0)

sys/net/radix.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,8 @@ rn_walktree_from(struct radix_node_head *h, void *a, void *m,
10001000
*/
10011001
if (rn->rn_bit >= 0)
10021002
rn = last;
1003+
if (!last)
1004+
return -1;
10031005
lastb = last->rn_bit;
10041006

10051007
/* printf("rn %p, lastb %d\n", rn, lastb);*/

sys/netpfil/ipfw/ip_dummynet.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,7 @@ config_profile(struct dn_profile *pf, struct dn_id *arg)
15881588
kpf->oid.len < pf->oid.len)) {
15891589
free(kpf, M_DUMMYNET);
15901590
*pkpf = NULL;
1591+
kpf = NULL;
15911592
}
15921593
if (pf->samples_no == 0)
15931594
continue;

sys/netpfil/ipfw/ip_fw_sockopt.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,7 +2345,7 @@ compare_sh(const void *_a, const void *_b)
23452345

23462346
if ((uintptr_t)a->handler < (uintptr_t)b->handler)
23472347
return (-1);
2348-
else if ((uintptr_t)b->handler > (uintptr_t)b->handler)
2348+
else if ((uintptr_t)a->handler > (uintptr_t)b->handler)
23492349
return (1);
23502350

23512351
return (0);
@@ -2448,7 +2448,8 @@ ipfw_add_sopt_handler(struct ipfw_sopt_handler *sh, size_t count)
24482448

24492449
/* Merge old & new arrays */
24502450
sz = ctl3_hsize + count;
2451-
memcpy(tmp, ctl3_handlers, ctl3_hsize * sizeof(*sh));
2451+
if (ctl3_handlers != NULL)
2452+
memcpy(tmp, ctl3_handlers, ctl3_hsize * sizeof(*sh));
24522453
memcpy(&tmp[ctl3_hsize], sh, count * sizeof(*sh));
24532454
qsort(tmp, sz, sizeof(*sh), compare_sh);
24542455
/* Switch new and free old */

sys/netpfil/ipfw/ip_fw_table.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,8 @@ find_table_entry(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
10931093
return (EINVAL);
10941094

10951095
oh = (struct _ipfw_obj_header *)ipfw_get_sopt_header(sd, sz);
1096+
if (oh == NULL)
1097+
return (EINVAL);
10961098
tent = (ipfw_obj_tentry *)(oh + 1);
10971099

10981100
/* Basic length checks for TLVs */
@@ -1124,8 +1126,10 @@ find_table_entry(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
11241126
kti = KIDX_TO_TI(ch, tc->no.kidx);
11251127
ta = tc->ta;
11261128

1127-
if (ta->find_tentry == NULL)
1129+
if (ta->find_tentry == NULL) {
1130+
IPFW_UH_RUNLOCK(ch);
11281131
return (ENOTSUP);
1132+
}
11291133

11301134
error = ta->find_tentry(tc->astate, kti, tent);
11311135

@@ -1545,6 +1549,8 @@ ipfw_resize_tables(struct ip_fw_chain *ch, unsigned int ntables)
15451549
* FIXME: Check if we really can shrink
15461550
*/
15471551
IPFW_UH_WUNLOCK(ch);
1552+
ipfw_objhash_bitmap_free(new_idx, new_blocks);
1553+
free(tablestate, M_IPFW);
15481554
return (EINVAL);
15491555
}
15501556

@@ -1630,7 +1636,7 @@ ipfw_switch_tables_namespace(struct ip_fw_chain *ch, unsigned int sets)
16301636
no = ipfw_objhash_lookup_kidx(ni, kidx);
16311637

16321638
/* Check if both table object and rule has the set 0 */
1633-
if (no->set != 0 || rule->set != 0) {
1639+
if (!no || no->set != 0 || rule->set != 0) {
16341640
IPFW_UH_WUNLOCK(ch);
16351641
return (EBUSY);
16361642
}

sys/netpfil/ipfw/ip_fw_table_algo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3954,7 +3954,7 @@ ta_dump_kfib_tentry(void *ta_state, struct table_info *ti, void *e,
39543954

39553955
/* Guess IPv4/IPv6 radix by sockaddr family */
39563956
#ifdef INET
3957-
if (addr->sin_family == AF_INET) {
3957+
if (addr && addr->sin_family == AF_INET) {
39583958
tent->k.addr.s_addr = addr->sin_addr.s_addr;
39593959
len = 32;
39603960
if (mask != NULL)
@@ -3967,7 +3967,7 @@ ta_dump_kfib_tentry(void *ta_state, struct table_info *ti, void *e,
39673967
}
39683968
#endif
39693969
#ifdef INET6
3970-
if (addr->sin_family == AF_INET6) {
3970+
if (addr && addr->sin_family == AF_INET6) {
39713971
addr6 = (struct sockaddr_in6 *)addr;
39723972
mask6 = (struct sockaddr_in6 *)mask;
39733973
memcpy(&tent->k, &addr6->sin6_addr, sizeof(struct in6_addr));

0 commit comments

Comments
 (0)