aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvgeniy Naydanov <evgeniy.naydanov@syntacore.com>2025-02-14 19:31:38 +0300
committerAntonio Borneo <borneo.antonio@gmail.com>2025-03-15 10:18:11 +0000
commit16c6497a89600ab8e8b354e2fc2c0ceb9ae74330 (patch)
tree0fb2af90153a5aac157ec1d958f2c3173664f0b4 /src
parentd892a4d763c283ca775213d4148b76d5b0fde520 (diff)
downloadriscv-openocd-16c6497a89600ab8e8b354e2fc2c0ceb9ae74330.zip
riscv-openocd-16c6497a89600ab8e8b354e2fc2c0ceb9ae74330.tar.gz
riscv-openocd-16c6497a89600ab8e8b354e2fc2c0ceb9ae74330.tar.bz2
rtos/linux: fix name overwrite in `linux_thread_extra_info()`
commit 908ee4dc9641bd3df2eb00264575501867da539d ("build: remove clang unused variable assignment warnings") introduced an error: ``` - tmp_str_ptr += sprintf(tmp_str_ptr, "%s", name); + sprintf(tmp_str_ptr, "%s", name); sprintf(tmp_str_ptr, "%s", temp->name); ``` This results in `name` being overwritten by `temp->name`. Fix this, adding OOM handling along the way. Change-Id: Id41f73247c3f7e6194d7c92187ad3163a9ea6c89 Signed-off-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com> Reviewed-on: https://review.openocd.org/c/openocd/+/8761 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/rtos/linux.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/src/rtos/linux.c b/src/rtos/linux.c
index 91d9a39..5efdc9f 100644
--- a/src/rtos/linux.c
+++ b/src/rtos/linux.c
@@ -1120,23 +1120,13 @@ static int linux_thread_extra_info(struct target *target,
while (temp) {
if (temp->threadid == threadid) {
- char *pid = " PID: ";
- char *pid_current = "*PID: ";
- char *name = "Name: ";
- int str_size = strlen(pid) + strlen(name);
- char *tmp_str = calloc(1, str_size + 50);
- char *tmp_str_ptr = tmp_str;
-
- /* discriminate current task */
- if (temp->status == 3)
- tmp_str_ptr += sprintf(tmp_str_ptr, "%s",
- pid_current);
- else
- tmp_str_ptr += sprintf(tmp_str_ptr, "%s", pid);
-
- tmp_str_ptr += sprintf(tmp_str_ptr, "%d, ", (int)temp->pid);
- sprintf(tmp_str_ptr, "%s", name);
- sprintf(tmp_str_ptr, "%s", temp->name);
+ char *tmp_str = alloc_printf("%cPID: %" PRIu32 ", Name: %s",
+ temp->status == 3 ? '*' : ' ',
+ temp->pid, temp->name);
+ if (!tmp_str) {
+ LOG_ERROR("Out of memory");
+ return ERROR_FAIL;
+ }
char *hex_str = calloc(1, strlen(tmp_str) * 2 + 1);
size_t pkt_len = hexify(hex_str, (const uint8_t *)tmp_str,
strlen(tmp_str), strlen(tmp_str) * 2 + 1);