Linux SNPS ARC Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] gdb/remote: make tid/pid type long in wite_ptid
@ 2019-11-09 10:15 Evgeniy Didin
  0 siblings, 0 replies; only message in thread
From: Evgeniy Didin @ 2019-11-09 10:15 UTC (permalink / raw)
  To: gdb-patches; +Cc: Evgeniy Didin, linux-snps-arc

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


_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-09 10:15 [PATCH] gdb/remote: make tid/pid type long in wite_ptid Evgeniy Didin

Linux SNPS ARC Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-snps-arc/0 linux-snps-arc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-snps-arc linux-snps-arc/ https://lore.kernel.org/linux-snps-arc \
		linux-snps-arc@lists.infradead.org
	public-inbox-index linux-snps-arc

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-snps-arc


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git