Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit f287aa8

Browse files
committed
semihosting: Bound-check the open_mode flag before indexing a small array
1 parent 13c9c90 commit f287aa8

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/target/semihosting.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ int32_t semihosting_open(target_s *const target, const semihosting_s *const requ
337337
{
338338
const target_addr_t file_name_taddr = request->params[0];
339339
const uint32_t file_name_length = request->params[2];
340+
/* Explicit bounds check for open_mode_flags */
341+
const uint32_t open_mode_libc = request->params[1];
342+
if (open_mode_libc > 11)
343+
return -1;
340344

341345
/*
342346
* Translation table of fopen() modes to GDB-compatible open flags

0 commit comments

Comments
 (0)