[PATCH] gdb/remote: make tid/pid type long in wite_ptid
Evgeniy Didin
Evgeniy.Didin@synopsys.com
Sat Nov 9 10:15:00 GMT 2019
From: Evgeniy Didin <didin@synopsys.com>
In Zephyr RTOS the k_thread_create function returns
thread ID which is actually pointer to k_thread structure.
If the memory addressing starts from 0x80000000, passing such
big values to write_ptid() leads to overflow of "int tid" variable
and thread ID becomes negative.
So lets make tid/pid variables type "long", this will prevent overflow
and should not break any logic.
gdb/ChangeLog:
2019-11-09 Evgeniy Didin <didin@synopsys.com>
* remote.c (remote_target::write_ptid): Make tid,pid
variables type "long" to prevent overflow.
Signed-off-by: Evgeniy Didin <didin@synopsys.com>
Cc: linux-snps-arc@lists.infradead.org
---
gdb/ChangeLog | 5 +++++
gdb/remote.c | 10 +++++-----
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f5c8a76c0f..5581df877b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-11-09 Evgeniy Didin <didin@synopsys.com>
+
+ * remote.c (remote_target::write_ptid): Make tid,pid
+ variables type "long" to prevent overflow.
+
2019-11-08 Tom Tromey <tromey@adacore.com>
* top.c (read_command_file): Update.
diff --git a/gdb/remote.c b/gdb/remote.c
index 1ac9013408..19602508f7 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -2909,22 +2909,22 @@ static int remote_newthread_step (threadref *ref, void *context);
char *
remote_target::write_ptid (char *buf, const char *endbuf, ptid_t ptid)
{
- int pid, tid;
+ long pid, tid;
struct remote_state *rs = get_remote_state ();
if (remote_multi_process_p (rs))
{
pid = ptid.pid ();
if (pid < 0)
- buf += xsnprintf (buf, endbuf - buf, "p-%x.", -pid);
+ buf += xsnprintf (buf, endbuf - buf, "p-%lx.", -pid);
else
- buf += xsnprintf (buf, endbuf - buf, "p%x.", pid);
+ buf += xsnprintf (buf, endbuf - buf, "p%lx.", pid);
}
tid = ptid.lwp ();
if (tid < 0)
- buf += xsnprintf (buf, endbuf - buf, "-%x", -tid);
+ buf += xsnprintf (buf, endbuf - buf, "-%lx", -tid);
else
- buf += xsnprintf (buf, endbuf - buf, "%x", tid);
+ buf += xsnprintf (buf, endbuf - buf, "%lx", tid);
return buf;
}
--
2.16.2
More information about the Gdb-patches
mailing list