Skip to content

Commit d7e2c1b

Browse files
rlubosfabiobaltieri
authored andcommitted
tests: net: lwm2m: client: Fix stack memory corruptions
LwM2M client context was defined on stack in the test function, however it could still be in use when the test ended, as the actual LwM2M teardown took place in a common "after" test function. In result, the Lwm2M context content could be corrupted. Additionally, increase the system work queue stack size, as the stack overflowed. Signed-off-by: Robert Lubos <[email protected]>
1 parent 6bfeb4f commit d7e2c1b

File tree

2 files changed

+2
-58
lines changed

2 files changed

+2
-58
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
CONFIG_ZTEST=y
22
CONFIG_ZTEST_STACK_SIZE=4096
3+
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
34
CONFIG_MP_MAX_NUM_CPUS=1

tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ FAKE_VOID_FUNC(show_lwm2m_event, enum lwm2m_rd_client_event);
2727
FAKE_VOID_FUNC(show_lwm2m_observe, enum lwm2m_observe_event);
2828

2929
static int next_event;
30+
static struct lwm2m_ctx ctx;
3031

3132
bool expect_lwm2m_rd_client_event(uint8_t expected_val)
3233
{
@@ -198,8 +199,6 @@ ZTEST_SUITE(lwm2m_rd_client, NULL, NULL, my_suite_before, my_suite_after, NULL);
198199

199200
ZTEST(lwm2m_rd_client, test_start_registration_ok)
200201
{
201-
struct lwm2m_ctx ctx;
202-
203202
(void)memset(&ctx, 0x0, sizeof(ctx));
204203

205204
lwm2m_rd_client_init();
@@ -224,8 +223,6 @@ ZTEST(lwm2m_rd_client, test_start_registration_ok)
224223

225224
ZTEST(lwm2m_rd_client, test_register_update_too_small_lifetime_to_default)
226225
{
227-
struct lwm2m_ctx ctx;
228-
229226
get_u32_val = CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME / 2;
230227
lwm2m_get_u32_fake.custom_fake = lwm2m_get_u32_val;
231228

@@ -247,8 +244,6 @@ ZTEST(lwm2m_rd_client, test_register_update_too_small_lifetime_to_default)
247244

248245
ZTEST(lwm2m_rd_client, test_timeout_resume_registration)
249246
{
250-
struct lwm2m_ctx ctx;
251-
252247
(void)memset(&ctx, 0x0, sizeof(ctx));
253248

254249
lwm2m_rd_client_init();
@@ -270,8 +265,6 @@ ZTEST(lwm2m_rd_client, test_timeout_resume_registration)
270265

271266
ZTEST(lwm2m_rd_client, test_start_registration_timeout)
272267
{
273-
struct lwm2m_ctx ctx;
274-
275268
(void)memset(&ctx, 0x0, sizeof(ctx));
276269

277270
lwm2m_rd_client_init();
@@ -289,8 +282,6 @@ ZTEST(lwm2m_rd_client, test_start_registration_timeout)
289282

290283
ZTEST(lwm2m_rd_client, test_start_registration_fail)
291284
{
292-
struct lwm2m_ctx ctx;
293-
294285
(void)memset(&ctx, 0x0, sizeof(ctx));
295286

296287
lwm2m_rd_client_init();
@@ -315,8 +306,6 @@ ZTEST(lwm2m_rd_client, test_start_registration_fail)
315306

316307
ZTEST(lwm2m_rd_client, test_start_registration_update)
317308
{
318-
struct lwm2m_ctx ctx;
319-
320309
(void)memset(&ctx, 0x0, sizeof(ctx));
321310

322311
lwm2m_rd_client_init();
@@ -337,8 +326,6 @@ ZTEST(lwm2m_rd_client, test_start_registration_update)
337326

338327
ZTEST(lwm2m_rd_client, test_rx_off)
339328
{
340-
struct lwm2m_ctx ctx;
341-
342329
(void)memset(&ctx, 0x0, sizeof(ctx));
343330

344331
lwm2m_rd_client_init();
@@ -360,8 +347,6 @@ ZTEST(lwm2m_rd_client, test_rx_off)
360347

361348
ZTEST(lwm2m_rd_client, test_start_registration_update_fail)
362349
{
363-
struct lwm2m_ctx ctx;
364-
365350
(void)memset(&ctx, 0x0, sizeof(ctx));
366351

367352
lwm2m_rd_client_init();
@@ -384,8 +369,6 @@ ZTEST(lwm2m_rd_client, test_start_registration_update_fail)
384369

385370
ZTEST(lwm2m_rd_client, test_registration_update_timeout)
386371
{
387-
struct lwm2m_ctx ctx;
388-
389372
(void)memset(&ctx, 0x0, sizeof(ctx));
390373

391374
lwm2m_rd_client_init();
@@ -414,8 +397,6 @@ ZTEST(lwm2m_rd_client, test_registration_update_timeout)
414397

415398
ZTEST(lwm2m_rd_client, test_deregistration_timeout)
416399
{
417-
struct lwm2m_ctx ctx;
418-
419400
(void)memset(&ctx, 0x0, sizeof(ctx));
420401

421402
lwm2m_rd_client_init();
@@ -437,8 +418,6 @@ ZTEST(lwm2m_rd_client, test_deregistration_timeout)
437418

438419
ZTEST(lwm2m_rd_client, test_error_on_registration_update)
439420
{
440-
struct lwm2m_ctx ctx;
441-
442421
(void)memset(&ctx, 0x0, sizeof(ctx));
443422

444423
lwm2m_rd_client_init();
@@ -462,8 +441,6 @@ ZTEST(lwm2m_rd_client, test_error_on_registration_update)
462441

463442
ZTEST(lwm2m_rd_client, test_network_error_on_registration)
464443
{
465-
struct lwm2m_ctx ctx;
466-
467444
(void)memset(&ctx, 0x0, sizeof(ctx));
468445

469446
lwm2m_rd_client_init();
@@ -480,8 +457,6 @@ ZTEST(lwm2m_rd_client, test_network_error_on_registration)
480457

481458
ZTEST(lwm2m_rd_client, test_suspend_resume_registration)
482459
{
483-
struct lwm2m_ctx ctx;
484-
485460
(void)memset(&ctx, 0x0, sizeof(ctx));
486461

487462
lwm2m_rd_client_init();
@@ -514,8 +489,6 @@ ZTEST(lwm2m_rd_client, test_suspend_resume_registration)
514489

515490
ZTEST(lwm2m_rd_client, test_suspend_stop_resume)
516491
{
517-
struct lwm2m_ctx ctx;
518-
519492
(void)memset(&ctx, 0x0, sizeof(ctx));
520493

521494
lwm2m_rd_client_init();
@@ -540,8 +513,6 @@ ZTEST(lwm2m_rd_client, test_suspend_stop_resume)
540513

541514
ZTEST(lwm2m_rd_client, test_socket_error)
542515
{
543-
struct lwm2m_ctx ctx;
544-
545516
(void)memset(&ctx, 0x0, sizeof(ctx));
546517

547518
lwm2m_rd_client_init();
@@ -564,8 +535,6 @@ ZTEST(lwm2m_rd_client, test_socket_error)
564535

565536
ZTEST(lwm2m_rd_client, test_socket_error_on_stop)
566537
{
567-
struct lwm2m_ctx ctx;
568-
569538
(void)memset(&ctx, 0x0, sizeof(ctx));
570539

571540
lwm2m_rd_client_init();
@@ -590,8 +559,6 @@ ZTEST(lwm2m_rd_client, test_socket_error_on_stop)
590559

591560
ZTEST(lwm2m_rd_client, test_no_context)
592561
{
593-
struct lwm2m_ctx ctx;
594-
595562
lwm2m_rd_client_init();
596563
zassert_equal(lwm2m_rd_client_stop(&ctx, NULL, false), -EPERM);
597564
zassert_equal(lwm2m_rd_client_pause(), -EPERM);
@@ -602,8 +569,6 @@ ZTEST(lwm2m_rd_client, test_no_context)
602569

603570
ZTEST(lwm2m_rd_client, test_engine_trigger_bootstrap)
604571
{
605-
struct lwm2m_ctx ctx;
606-
607572
(void)memset(&ctx, 0x0, sizeof(ctx));
608573

609574
lwm2m_rd_client_init();
@@ -630,9 +595,6 @@ ZTEST(lwm2m_rd_client, test_engine_trigger_bootstrap)
630595

631596
ZTEST(lwm2m_rd_client, test_bootstrap_timeout)
632597
{
633-
634-
struct lwm2m_ctx ctx;
635-
636598
(void)memset(&ctx, 0x0, sizeof(ctx));
637599

638600
lwm2m_rd_client_init();
@@ -653,8 +615,6 @@ ZTEST(lwm2m_rd_client, test_bootstrap_timeout)
653615

654616
ZTEST(lwm2m_rd_client, test_bootstrap_fail)
655617
{
656-
struct lwm2m_ctx ctx;
657-
658618
(void)memset(&ctx, 0x0, sizeof(ctx));
659619

660620
lwm2m_rd_client_init();
@@ -676,9 +636,6 @@ ZTEST(lwm2m_rd_client, test_bootstrap_fail)
676636

677637
ZTEST(lwm2m_rd_client, test_bootstrap_no_srv)
678638
{
679-
680-
struct lwm2m_ctx ctx;
681-
682639
(void)memset(&ctx, 0x0, sizeof(ctx));
683640

684641
lwm2m_rd_client_init();
@@ -695,8 +652,6 @@ ZTEST(lwm2m_rd_client, test_bootstrap_no_srv)
695652

696653
ZTEST(lwm2m_rd_client, test_disable_server)
697654
{
698-
struct lwm2m_ctx ctx;
699-
700655
(void)memset(&ctx, 0x0, sizeof(ctx));
701656

702657
lwm2m_rd_client_init();
@@ -718,8 +673,6 @@ ZTEST(lwm2m_rd_client, test_disable_server)
718673

719674
ZTEST(lwm2m_rd_client, test_disable_server_stop)
720675
{
721-
struct lwm2m_ctx ctx;
722-
723676
(void)memset(&ctx, 0x0, sizeof(ctx));
724677

725678
lwm2m_rd_client_init();
@@ -744,8 +697,6 @@ ZTEST(lwm2m_rd_client, test_disable_server_stop)
744697

745698
ZTEST(lwm2m_rd_client, test_disable_server_connect)
746699
{
747-
struct lwm2m_ctx ctx;
748-
749700
(void)memset(&ctx, 0x0, sizeof(ctx));
750701

751702
lwm2m_rd_client_init();
@@ -774,8 +725,6 @@ ZTEST(lwm2m_rd_client, test_disable_server_connect)
774725

775726
ZTEST(lwm2m_rd_client, test_fallback_to_bootstrap)
776727
{
777-
struct lwm2m_ctx ctx;
778-
779728
(void)memset(&ctx, 0x0, sizeof(ctx));
780729

781730
lwm2m_rd_client_init();
@@ -796,8 +745,6 @@ ZTEST(lwm2m_rd_client, test_fallback_to_bootstrap)
796745

797746
ZTEST(lwm2m_rd_client, test_no_srv_fallback_to_bootstrap)
798747
{
799-
struct lwm2m_ctx ctx;
800-
801748
(void)memset(&ctx, 0x0, sizeof(ctx));
802749

803750
lwm2m_rd_client_init();
@@ -822,8 +769,6 @@ ZTEST(lwm2m_rd_client, test_no_srv_fallback_to_bootstrap)
822769

823770
ZTEST(lwm2m_rd_client, test_start_stop_ignore_engine_fault)
824771
{
825-
struct lwm2m_ctx ctx;
826-
827772
(void)memset(&ctx, 0x0, sizeof(ctx));
828773

829774
test_prepare_pending_message_cb(&message_reply_cb_default);
@@ -857,8 +802,6 @@ ZTEST(lwm2m_rd_client, test_start_stop_ignore_engine_fault)
857802

858803
ZTEST(lwm2m_rd_client, test_start_suspend_ignore_engine_fault)
859804
{
860-
struct lwm2m_ctx ctx;
861-
862805
(void)memset(&ctx, 0x0, sizeof(ctx));
863806

864807
test_prepare_pending_message_cb(&message_reply_cb_default);

0 commit comments

Comments
 (0)