Skip to content

Commit 8336101

Browse files
yonghuahjren1
authored andcommitted
DM: Fix potential buffer overflow and uninitialized variable
- @'rpmb_check_frame()', avoid buffer overflow access when calling 'memcmp()' Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
1 parent 194fd8b commit 8336101

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

devicemodel/core/hugetlb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ static bool release_larger_freepage(int level_limit)
506506
*/
507507
static bool hugetlb_reserve_pages(void)
508508
{
509-
int left_gap, pg_size;
509+
int left_gap = 0, pg_size;
510510
int level;
511511

512512
printf("to reserve more free pages:\n");

devicemodel/hw/platform/rpmb/rpmb_backend.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ static int rpmb_check_frame(const char *cmd_str, int *err,
180180
{
181181
uint32_t i;
182182
uint8_t mac[32];
183+
size_t len;
183184

184185
for (i = 0; i < frame_cnt; i++) {
185186
if (write_counter && *write_counter != swap32(frames[i].write_counter)) {
@@ -203,7 +204,11 @@ static int rpmb_check_frame(const char *cmd_str, int *err,
203204
return -1;
204205
}
205206

206-
if (addr && !memcmp(cmd_str, WRITE_DATA_STR, sizeof(WRITE_DATA_STR))) {
207+
len = strlen(cmd_str) + 1;
208+
if (len > sizeof(WRITE_DATA_STR))
209+
len = sizeof(WRITE_DATA_STR);
210+
211+
if (addr && !memcmp(cmd_str, WRITE_DATA_STR, len)) {
207212
if (*addr < get_common_blocks()) {
208213
*err = RPMB_RES_WRITE_FAILURE;
209214
DPRINTF(("%s: Common block is read only\n", cmd_str));

0 commit comments

Comments
 (0)