Skip to content

Commit

Permalink
semihosting: fix accessing memory outside the bounds of the fn array
Browse files Browse the repository at this point in the history
There is an accsess to wrong index, when arm semihosting_basedir
command not used or basedir set to empty string.

Signed-off-by: Erhan Kurubas <[email protected]>
Change-Id: I3afa049d74b30496f5c03ba4ef67431784f81bdc
Fixes: ce5027a ("semihosting: add semihosting_basedir command")
Reviewed-on: https://review.openocd.org/c/openocd/+/7005
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <[email protected]>
Reviewed-by: Antonio Borneo <[email protected]>
  • Loading branch information
erhankur authored and borneoa committed Jun 10, 2022
1 parent 7033850 commit 480d4e1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/target/semihosting_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,9 +877,11 @@ int semihosting_common(struct target *target)
semihosting->result = -1;
semihosting->sys_errno = ENOMEM;
} else {
strncpy((char *)fn, semihosting->basedir, basedir_len);
if (fn[basedir_len - 1] != '/')
fn[basedir_len++] = '/';
if (basedir_len > 0) {
strcpy((char *)fn, semihosting->basedir);
if (fn[basedir_len - 1] != '/')
fn[basedir_len++] = '/';
}
retval = target_read_memory(target, addr, 1, len, fn + basedir_len);
if (retval != ERROR_OK) {
free(fn);
Expand Down

0 comments on commit 480d4e1

Please sign in to comment.