Skip to content

Commit c194a32

Browse files
author
coverage-leader
committed
test: ff_dpdk_if_send NULL ctx guard regression (FU-CB-DPDKIF-NULLGUARD)
unit test_ff_dpdk_if +2 TC: - ff_dpdk_if_send(NULL, NULL, 0) returns -1 without crashing - ff_dpdk_if_send(NULL, dummy_mbuf, 100) returns -1 + frees mbuf integration test_ff_dpdk_if_integration +1 TC: - ff_dpdk_if_send(NULL, NULL, 0) post real EAL init must not crash 11 unit binaries / 142 TC / 0 SKIP / 0 FAIL. 1 integration binary / 8 TC / 0 SKIP / 0 FAIL. valgrind clean across both suites.
1 parent ca83653 commit c194a32

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

tests/integration/test_ff_dpdk_if_integration.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ test_ff_get_traffic_post_init(void **state)
297297

298298
/* ------------------------------------------------------------------------ */
299299
/* TC-INT-DPDKIF-06: ff_dpdk_if_send with valid ctx + 0-byte payload */
300-
/* (NULL ctx is not tested -- ff_dpdk_if_send dereferences ctx->port_id */
301-
/* unconditionally and would segfault. Tracked as FU-CB-DPDKIF-NULLGUARD.) */
300+
/* (NULL ctx is exercised separately in TC-INT-DPDKIF-08 below.) */
302301
/* ------------------------------------------------------------------------ */
303302
static void
304303
test_ff_dpdk_if_send_zero_total(void **state)
@@ -321,6 +320,21 @@ test_ff_dpdk_if_send_zero_total(void **state)
321320
ff_dpdk_deregister_if(ctx);
322321
}
323322

323+
/* ------------------------------------------------------------------------ */
324+
/* TC-INT-DPDKIF-08 (Stage-6 Phase-9 / FU-CB-DPDKIF-NULLGUARD): */
325+
/* ff_dpdk_if_send(NULL, ...) must not crash. With the lib NULL guard in */
326+
/* place this returns -1 immediately. Pre-guard, this would segfault on */
327+
/* the very first ctx->port_id deref. */
328+
/* ------------------------------------------------------------------------ */
329+
static void
330+
test_ff_dpdk_if_send_null_ctx_no_crash(void **state)
331+
{
332+
(void)state;
333+
SKIP_IF_NO_INIT();
334+
int rv = ff_dpdk_if_send(NULL, NULL, 0);
335+
assert_int_equal(rv, -1);
336+
}
337+
324338
/* ------------------------------------------------------------------------ */
325339
/* TC-INT-DPDKIF-07: rte_eal_process_type returns PRIMARY post-init */
326340
/* ------------------------------------------------------------------------ */
@@ -346,6 +360,7 @@ main(void)
346360
cmocka_unit_test(test_ff_get_tsc_ns_monotonic),
347361
cmocka_unit_test(test_ff_get_traffic_post_init),
348362
cmocka_unit_test(test_ff_dpdk_if_send_zero_total),
363+
cmocka_unit_test(test_ff_dpdk_if_send_null_ctx_no_crash),
349364
cmocka_unit_test(test_eal_process_type_primary),
350365
};
351366
return cmocka_run_group_tests(tests, group_setup, group_teardown);

tests/unit/test_ff_dpdk_if.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,32 @@ test_ff_dpdk_register_if_returns_ctx(void **state)
473473
}
474474

475475
/* ------------------------------------------------------------------------ */
476-
/* Main runner */
476+
/* TC-U-P3-DPDKIF-18 (Stage-6 Phase-9 / FU-CB-DPDKIF-NULLGUARD): */
477+
/* ff_dpdk_if_send(NULL, ...) must not crash; lib's NULL ctx guard returns */
478+
/* -1 and frees the caller's mbuf (if any) instead of dereferencing. */
477479
/* ------------------------------------------------------------------------ */
480+
extern int ff_dpdk_if_send(struct ff_dpdk_if_context *ctx, void *m, int total);
481+
482+
static void
483+
test_ff_dpdk_if_send_null_ctx_safe(void **state)
484+
{
485+
(void)state;
486+
/* Both args NULL: the guard returns -1 without touching m. */
487+
int rv = ff_dpdk_if_send(NULL, NULL, 0);
488+
assert_int_equal(rv, -1);
489+
}
490+
491+
static void
492+
test_ff_dpdk_if_send_null_ctx_with_mbuf(void **state)
493+
{
494+
(void)state;
495+
/* Non-NULL m: the guard must call ff_mbuf_free(m) before returning -1.
496+
* Our local stub ff_mbuf_free is a no-op, so we just verify the call
497+
* doesn't crash and the return is -1. */
498+
int dummy_mbuf = 0xCAFE;
499+
int rv = ff_dpdk_if_send(NULL, &dummy_mbuf, 100);
500+
assert_int_equal(rv, -1);
501+
}
478502
int
479503
main(void)
480504
{
@@ -498,6 +522,9 @@ main(void)
498522
cmocka_unit_test(test_ff_rss_tbl_get_portrange_disabled),
499523
cmocka_unit_test(test_ff_rss_tbl_get_portrange_smoke),
500524
cmocka_unit_test(test_ff_dpdk_register_if_returns_ctx),
525+
/* Stage-6 Phase-9 (FU-CB-DPDKIF-NULLGUARD) */
526+
cmocka_unit_test(test_ff_dpdk_if_send_null_ctx_safe),
527+
cmocka_unit_test(test_ff_dpdk_if_send_null_ctx_with_mbuf),
501528
};
502529
return cmocka_run_group_tests(tests, NULL, NULL);
503530
}

0 commit comments

Comments
 (0)