From ca2a87a0560f483f519406377322ce8138f5432b Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Fri, 28 May 2010 18:23:15 +0000 Subject: [PATCH] gdb/ * linux-nat.c (linux_nat_core_of_thread_1): Fix crash on invalid CONTENT. gdb/gdbserver/ * linux-low.c (linux_core_of_thread): Fix crash on invalid CONTENT. New comment. --- gdb/ChangeLog | 5 +++++ gdb/gdbserver/ChangeLog | 5 +++++ gdb/gdbserver/linux-low.c | 16 ++++++++++++---- gdb/linux-nat.c | 14 ++++++++++---- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index cf1b5851020..83da1f4d5ef 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2010-05-28 Jan Kratochvil + + * linux-nat.c (linux_nat_core_of_thread_1): Fix crash on invalid + CONTENT. + 2010-05-28 Jan Kratochvil * linux-nat.c (linux_nat_wait_1): Do not call diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index e9c960e9eba..16c5149210e 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,8 @@ +2010-05-28 Jan Kratochvil + + * linux-low.c (linux_core_of_thread): Fix crash on invalid CONTENT. + New comment. + 2010-05-26 Ozkan Sezer * gdbreplay.c (remote_open): Check error return from socket() call by diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 4a19db74008..4db9711efa6 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -4346,13 +4346,21 @@ linux_core_of_thread (ptid_t ptid) } p = strchr (content, '('); - p = strchr (p, ')') + 2; /* skip ")" and a whitespace. */ - p = strtok_r (p, " ", &ts); - for (i = 0; i != 36; ++i) + /* Skip ")". */ + if (p != NULL) + p = strchr (p, ')'); + if (p != NULL) + p++; + + /* If the first field after program name has index 0, then core number is + the field with index 36. There's no constant for that anywhere. */ + if (p != NULL) + p = strtok_r (p, " ", &ts); + for (i = 0; p != NULL && i != 36; ++i) p = strtok_r (NULL, " ", &ts); - if (sscanf (p, "%d", &core) == 0) + if (p == NULL || sscanf (p, "%d", &core) == 0) core = -1; free (content); diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index b0f79f108bd..43370f0f80c 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -5509,15 +5509,21 @@ linux_nat_core_of_thread_1 (ptid_t ptid) make_cleanup (xfree, content); p = strchr (content, '('); - p = strchr (p, ')') + 2; /* skip ")" and a whitespace. */ + + /* Skip ")". */ + if (p != NULL) + p = strchr (p, ')'); + if (p != NULL) + p++; /* If the first field after program name has index 0, then core number is the field with index 36. There's no constant for that anywhere. */ - p = strtok_r (p, " ", &ts); - for (i = 0; i != 36; ++i) + if (p != NULL) + p = strtok_r (p, " ", &ts); + for (i = 0; p != NULL && i != 36; ++i) p = strtok_r (NULL, " ", &ts); - if (sscanf (p, "%d", &core) == 0) + if (p == NULL || sscanf (p, "%d", &core) == 0) core = -1; do_cleanups (back_to); -- 2.30.2