@@ -48,6 +48,71 @@ 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] -> 0x0010FF */
63+ patch [3 ] = 0xFF ; /* 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
94+
95+ START_TEST (test_wb_patch_resume_large_len )
96+ {
97+ WB_PATCH_CTX patch_ctx ;
98+ uint8_t src [SRC_SIZE ] = {0 };
99+ uint8_t patch [PATCH_SIZE ] = {0 };
100+ uint8_t dst [DST_SIZE ] = {0 };
101+ uint32_t len = 70000 ;
102+ int ret ;
103+
104+ src [0 ] = 0xA5 ;
105+ ret = wb_patch_init (& patch_ctx , src , SRC_SIZE , patch , BLOCK_HDR_SIZE );
106+ ck_assert_int_eq (ret , 0 );
107+
108+ patch_ctx .matching = 1 ;
109+ patch_ctx .blk_off = 0 ;
110+ patch_ctx .blk_sz = len ;
111+
112+ ret = wb_patch (& patch_ctx , dst , len );
113+ ck_assert_int_eq (ret , -1 );
114+ }
115+ END_TEST
51116
52117START_TEST (test_wb_diff_init_invalid )
53118{
@@ -162,6 +227,9 @@ Suite *patch_diff_suite(void)
162227
163228 tcase_add_test (tc_wolfboot_delta , test_wb_patch_init_invalid );
164229 tcase_add_test (tc_wolfboot_delta , test_wb_diff_init_invalid );
230+ tcase_add_test (tc_wolfboot_delta , test_wb_patch_src_bounds_invalid );
231+ tcase_add_test (tc_wolfboot_delta , test_wb_patch_resume_bounds_invalid );
232+ tcase_add_test (tc_wolfboot_delta , test_wb_patch_resume_large_len );
165233 tcase_add_test (tc_wolfboot_delta , test_wb_patch_and_diff );
166234 suite_add_tcase (s , tc_wolfboot_delta );
167235
0 commit comments