Skip to content

Commit

Permalink
tests: Fix multiple Coverity warnings in test programs.
Browse files Browse the repository at this point in the history
This patch addresses several common issues in various test programs
instead of sending multiple small patches.  While these are not
critical, cleaning them up improves code quality.

- Fixed two resource leaks in test-aa.c and test-ovsdb.c.
- Fixed four instances of unchecked return values in test-ovsdb.c
  and test-packet.c.
- Fixed one out-of-bounds read in test-ccmap.c

Signed-off-by: Eelco Chaudron <[email protected]>
Signed-off-by: 0-day Robot <[email protected]>
  • Loading branch information
chaudron authored and ovsrobot committed Feb 6, 2025
1 parent 56a5c70 commit 171f726
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions tests/test-aa.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ test_aa_send(void)

if (n == 0) {
printf("Error: unable to build packet\n");
lldp_destroy_dummy(lldp);
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test-ccmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ test_ccmap_inc_dec(hash_func *hash)
check_ccmap(&ccmap, values, i + 1, hash);
}
shuffle(values, N_ELEMS);
for (i = 0; i < N_ELEMS; i++) {
for (i = 0; i < (N_ELEMS - 1); i++) {
ccmap_dec(&ccmap, hash(values[i]));
check_ccmap(&ccmap, values + (i + 1), N_ELEMS - (i + 1), hash);
}
Expand Down
10 changes: 7 additions & 3 deletions tests/test-ovsdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ do_log_io(struct ovs_cmdl_context *ctx)
}

ovsdb_log_close(log);
ovsdb_log_close(replacement);
}

static void
Expand Down Expand Up @@ -3089,7 +3090,8 @@ do_idl_partial_update_set_column(struct ovs_cmdl_context *ctx)
myTxn = ovsdb_idl_txn_create(idl);
idltest_simple3_get_uset(myRow, OVSDB_TYPE_UUID);
struct uuid uuid_to_add;
uuid_from_string(&uuid_to_add, "001e43d2-dd3f-4616-ab6a-83a490bb0991");
ovs_assert(uuid_from_string(&uuid_to_add,
"001e43d2-dd3f-4616-ab6a-83a490bb0991"));
idltest_simple3_update_uset_addvalue(myRow, uuid_to_add);
idltest_simple3_set_name(myRow, "String2");
ovsdb_idl_txn_commit_block(myTxn);
Expand All @@ -3101,7 +3103,8 @@ do_idl_partial_update_set_column(struct ovs_cmdl_context *ctx)
/* Insert duplicate element. */
myTxn = ovsdb_idl_txn_create(idl);
struct uuid uuid_to_add2;
uuid_from_string(&uuid_to_add2, "0026b3ba-571b-4729-8227-d860a5210ab8");
ovs_assert(uuid_from_string(&uuid_to_add2,
"0026b3ba-571b-4729-8227-d860a5210ab8"));
idltest_simple3_update_uset_addvalue(myRow, uuid_to_add2);
ovsdb_idl_txn_commit_block(myTxn);
ovsdb_idl_txn_destroy(myTxn);
Expand Down Expand Up @@ -3145,7 +3148,8 @@ do_idl_partial_update_set_column(struct ovs_cmdl_context *ctx)
/* create row, insert key, delete row */
myTxn = ovsdb_idl_txn_create(idl);
myRow = idltest_simple3_insert(myTxn);
uuid_from_string(&uuid_to_add, "12345678-dd3f-4616-ab6a-83a490bb0991");
ovs_assert(uuid_from_string(&uuid_to_add,
"12345678-dd3f-4616-ab6a-83a490bb0991"));
idltest_simple3_update_uset_addvalue(myRow, uuid_to_add);
idltest_simple3_set_name(myRow, "String2");
idltest_simple3_delete(myRow);
Expand Down
2 changes: 1 addition & 1 deletion tests/test-packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ test_ipv6_parsing(void)
struct in6_addr o_ipv6, p_ipv6;
struct in6_addr mask;

inet_pton(AF_INET6, "2001:db8:0:0:0:0:2:1", &o_ipv6);
assert(inet_pton(AF_INET6, "2001:db8:0:0:0:0:2:1", &o_ipv6) == 1);

assert(!ipv6_parse_masked("2001:db8:0:0:0:0:2:1/64", &p_ipv6, &mask));
assert(ipv6_addr_equals(&o_ipv6, &p_ipv6));
Expand Down

0 comments on commit 171f726

Please sign in to comment.