Skip to content

Commit 49cc44a

Browse files
committed
fake_bsp: fix out-of-bounds read of OFFSET_CONFIGURATION_ROM
The check failed to account for the trailing null byte, and memcpy() read beyond the end of the copied string literal. Signed-off-by: Peter Colberg <peter.colberg@intel.com>
1 parent 7f737cd commit 49cc44a

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

test/fake_bsp/fakegoodbsp.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,14 @@ AOCL_MMD_CALL int aocl_mmd_read(int handle, aocl_mmd_op_t op, size_t len,
282282
fprintf(stderr, "Error: Not handling read of 0x%x in unit test\n",
283283
(unsigned int)offset);
284284
return -1;
285-
case OFFSET_CONFIGURATION_ROM:
286-
if (strlen(config_str) <= len) {
287-
memcpy(dst, (void *)config_str, len);
288-
return 0;
289-
} else {
285+
case OFFSET_CONFIGURATION_ROM: {
286+
const size_t config_size = strlen(config_str) + 1;
287+
if (config_size > len) {
290288
return -1;
291289
}
292-
break;
290+
memcpy(dst, config_str, config_size);
291+
return 0;
292+
}
293293
case OFFSET_COUNTER:
294294
if (len == sizeof(unsigned int)) {
295295
memcpy(dst, &offset_counter, len);

test/fake_bsp/missingfuncbsp.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,14 @@ AOCL_MMD_CALL int aocl_mmd_read(int handle, aocl_mmd_op_t op, size_t len,
267267
fprintf(stderr, "Error: Not handling read of 0x%x in unit test\n",
268268
(unsigned int)offset);
269269
return -1;
270-
case OFFSET_CONFIGURATION_ROM:
271-
if (strlen(config_str) <= len) {
272-
memcpy(dst, (void *)config_str, len);
273-
return 0;
274-
} else {
270+
case OFFSET_CONFIGURATION_ROM: {
271+
const size_t config_size = strlen(config_str) + 1;
272+
if (config_size > len) {
275273
return -1;
276274
}
277-
break;
275+
memcpy(dst, config_str, config_size);
276+
return 0;
277+
}
278278
case OFFSET_COUNTER:
279279
fprintf(stderr, "Error: Not handling read of 0x%x in unit test\n",
280280
(unsigned int)offset);

0 commit comments

Comments
 (0)