Skip to content

Commit 59916eb

Browse files
steverobbSteve Robb
and
Steve Robb
authored
Fixed potential buffer overruns when adding too many .ini array elements. (#923)
Co-authored-by: Steve Robb <[email protected]>
1 parent 042ad82 commit 59916eb

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

cfg.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static const ini_var_t ini_vars[] =
8282
{ "SHARED_FOLDER", (void*)(&(cfg.shared_folder)), STRING, 0, sizeof(cfg.shared_folder) - 1 },
8383
{ "NO_MERGE_VID", (void*)(&(cfg.no_merge_vid)), HEX16, 0, 0xFFFF },
8484
{ "NO_MERGE_PID", (void*)(&(cfg.no_merge_pid)), HEX16, 0, 0xFFFF },
85-
{ "NO_MERGE_VIDPID", (void*)(cfg.no_merge_vidpid), HEX32ARR, 0, 0xFFFFFFFF },
85+
{ "NO_MERGE_VIDPID", (void*)(cfg.no_merge_vidpid), HEX32ARR, 0, sizeof(cfg.no_merge_vidpid) / sizeof(cfg.no_merge_vidpid[0]) },
8686
{ "CUSTOM_ASPECT_RATIO_1", (void*)(&(cfg.custom_aspect_ratio[0])), STRING, 0, sizeof(cfg.custom_aspect_ratio[0]) - 1 },
8787
{ "CUSTOM_ASPECT_RATIO_2", (void*)(&(cfg.custom_aspect_ratio[1])), STRING, 0, sizeof(cfg.custom_aspect_ratio[1]) - 1 },
8888
{ "SPINNER_VID", (void*)(&(cfg.spinner_vid)), HEX16, 0, 0xFFFF },
@@ -126,7 +126,7 @@ static const ini_var_t ini_vars[] =
126126
{ "HDR_AVG_NITS", (void*)(&(cfg.hdr_avg_nits)), UINT16, 100, 10000 },
127127
{ "VGA_MODE", (void*)(&(cfg.vga_mode)), STRING, 0, sizeof(cfg.vga_mode) - 1 },
128128
{ "NTSC_MODE", (void *)(&(cfg.ntsc_mode)), UINT8, 0, 2 },
129-
{ "CONTROLLER_UNIQUE_MAPPING", (void *)(cfg.controller_unique_mapping), UINT32ARR, 0, 0xFFFFFFFF },
129+
{ "CONTROLLER_UNIQUE_MAPPING", (void *)(cfg.controller_unique_mapping), UINT32ARR, 0, sizeof(cfg.controller_unique_mapping) / sizeof(cfg.controller_unique_mapping[0]) },
130130
{ "OSD_LOCK", (void*)(&(cfg.osd_lock)), STRING, 0, sizeof(cfg.osd_lock) - 1 },
131131
{ "OSD_LOCK_TIME", (void*)(&(cfg.osd_lock_time)), UINT16, 0, 60 },
132132
{ "DEBUG", (void *)(&(cfg.debug)), UINT8, 0, 1 },
@@ -410,8 +410,11 @@ static void ini_parse_var(char* buf)
410410
}
411411

412412
uint32_t *arr = (uint32_t*)var->var;
413-
uint32_t pos = ++arr[0];
414-
ini_parse_numeric(var, &buf[i], &arr[pos]);
413+
if (arr[0] < var->max)
414+
{
415+
uint32_t pos = ++arr[0];
416+
ini_parse_numeric(var, &buf[i], &arr[pos]);
417+
}
415418
}
416419
break;
417420

0 commit comments

Comments
 (0)