@@ -48,6 +48,49 @@ START_TEST(test_wb_patch_init_invalid)
4848}
4949END_TEST
5050
51+ START_TEST (test_wb_patch_src_bounds_invalid )
52+ {
53+ WB_PATCH_CTX patch_ctx ;
54+ uint8_t src [SRC_SIZE ] = {0 };
55+ uint8_t patch [PATCH_SIZE ] = {0 };
56+ uint8_t dst [DELTA_BLOCK_SIZE ] = {0 };
57+ int ret ;
58+
59+ /* ESC + header with src_off beyond src_size */
60+ patch [0 ] = ESC ;
61+ patch [1 ] = 0x00 ; /* off[0] */
62+ patch [2 ] = 0x10 ; /* off[1] -> 0x001000 */
63+ patch [3 ] = 0x00 ; /* off[2] */
64+ patch [4 ] = 0x00 ; /* sz[0] */
65+ patch [5 ] = 0x10 ; /* sz[1] -> 16 */
66+
67+ ret = wb_patch_init (& patch_ctx , src , SRC_SIZE , patch , BLOCK_HDR_SIZE );
68+ ck_assert_int_eq (ret , 0 );
69+
70+ ret = wb_patch (& patch_ctx , dst , sizeof (dst ));
71+ ck_assert_int_eq (ret , -1 );
72+ }
73+ END_TEST
74+
75+ START_TEST (test_wb_patch_resume_bounds_invalid )
76+ {
77+ WB_PATCH_CTX patch_ctx ;
78+ uint8_t src [SRC_SIZE ] = {0 };
79+ uint8_t patch [PATCH_SIZE ] = {0 };
80+ uint8_t dst [DELTA_BLOCK_SIZE ] = {0 };
81+ int ret ;
82+
83+ ret = wb_patch_init (& patch_ctx , src , SRC_SIZE , patch , BLOCK_HDR_SIZE );
84+ ck_assert_int_eq (ret , 0 );
85+
86+ patch_ctx .matching = 1 ;
87+ patch_ctx .blk_off = SRC_SIZE + 1 ;
88+ patch_ctx .blk_sz = 4 ;
89+
90+ ret = wb_patch (& patch_ctx , dst , sizeof (dst ));
91+ ck_assert_int_eq (ret , -1 );
92+ }
93+ END_TEST
5194
5295START_TEST (test_wb_diff_init_invalid )
5396{
@@ -162,6 +205,8 @@ Suite *patch_diff_suite(void)
162205
163206 tcase_add_test (tc_wolfboot_delta , test_wb_patch_init_invalid );
164207 tcase_add_test (tc_wolfboot_delta , test_wb_diff_init_invalid );
208+ tcase_add_test (tc_wolfboot_delta , test_wb_patch_src_bounds_invalid );
209+ tcase_add_test (tc_wolfboot_delta , test_wb_patch_resume_bounds_invalid );
165210 tcase_add_test (tc_wolfboot_delta , test_wb_patch_and_diff );
166211 suite_add_tcase (s , tc_wolfboot_delta );
167212
0 commit comments