|
From: <ge...@op...> - 2025-10-17 18:53:23
|
This is an automated email from Gerrit. "Name of user not set <sea...@se...>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9173 -- gerrit commit 0e621d0241a73df46213ae8ae0b5d0689fa8af8c Author: Sean Anderson <sea...@li...> Date: Fri Oct 17 14:51:31 2025 -0400 semihosting: Check for overflow in FLEN on 32-bit systems When semihosting 32-bit systems, the return value of FLEN will be stored in a 32-bit integer. To prevent wraparound, return -1 and set EOVERFLOW. This matches the behavior of stat(2). Signed-off-by: Sean Anderson <sea...@li...> Change-Id: Id4577b70bf49ea2b2bc301d9f52db719f88bfa9f diff --git a/src/target/semihosting_common.c b/src/target/semihosting_common.c index 5f8ab1082c..6303950468 100644 --- a/src/target/semihosting_common.c +++ b/src/target/semihosting_common.c @@ -691,11 +691,15 @@ int semihosting_common(struct target *target) semihosting->result = fstat(fd, &buf); if (semihosting->result == -1) { semihosting->sys_errno = errno; - LOG_DEBUG("fstat(%d)=%" PRId64, fd, semihosting->result); - break; + } else if (semihosting->word_size_bytes == 4 && + buf.st_size > 0x7fffffff) { + semihosting->result = -1; + semihosting->sys_errno = EOVERFLOW; + } else { + semihosting->result = buf.st_size; } LOG_DEBUG("fstat(%d)=%" PRId64, fd, semihosting->result); - semihosting->result = buf.st_size; + break; } break; -- |