|
1 | 1 | /* unit-store-sbrk.c |
2 | 2 | * |
3 | 3 | * Unit tests for store allocator helper. |
| 4 | + * |
| 5 | + * Copyright (C) 2025 wolfSSL Inc. |
| 6 | + * |
| 7 | + * This file is part of wolfBoot. |
| 8 | + * |
| 9 | + * wolfBoot is free software; you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU General Public License as published by |
| 11 | + * the Free Software Foundation; either version 3 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + * |
| 14 | + * wolfBoot is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
4 | 22 | */ |
5 | 23 |
|
6 | 24 | #include <check.h> |
| 25 | +#include <limits.h> |
7 | 26 | #include <stdint.h> |
8 | 27 |
|
9 | 28 | #include "../../src/store_sbrk.h" |
@@ -36,13 +55,27 @@ START_TEST(test_sbrk_rejects_overflow) |
36 | 55 | } |
37 | 56 | END_TEST |
38 | 57 |
|
| 58 | +START_TEST(test_sbrk_rejects_alignment_overflow) |
| 59 | +{ |
| 60 | + uint8_t heap_buf[16]; |
| 61 | + uint8_t *heap = NULL; |
| 62 | + void *ret; |
| 63 | + |
| 64 | + ret = wolfboot_store_sbrk(UINT_MAX - 1U, &heap, heap_buf, sizeof(heap_buf)); |
| 65 | + |
| 66 | + ck_assert_ptr_eq(ret, (void *)-1); |
| 67 | + ck_assert_ptr_eq(heap, NULL); |
| 68 | +} |
| 69 | +END_TEST |
| 70 | + |
39 | 71 | Suite *wolfboot_suite(void) |
40 | 72 | { |
41 | 73 | Suite *s = suite_create("store-sbrk"); |
42 | 74 | TCase *tcase = tcase_create("store_sbrk"); |
43 | 75 |
|
44 | 76 | tcase_add_test(tcase, test_sbrk_first_call_advances_heap); |
45 | 77 | tcase_add_test(tcase, test_sbrk_rejects_overflow); |
| 78 | + tcase_add_test(tcase, test_sbrk_rejects_alignment_overflow); |
46 | 79 | suite_add_tcase(s, tcase); |
47 | 80 | return s; |
48 | 81 | } |
|
0 commit comments