[PATCH] Process record: Fix null deref when loading empty core file

Andrew D'Addesio modchipv12@gmail.com
Sat May 12 03:53:00 GMT 2018


Fix a null dereference in the "record full restore" command. If the
supplied file contains no records, the arch list will be empty, so
no need to copy to the record list.

Also remove a redundant "record_full_arch_list_tail->next = NULL;"
assignment, as our arch list is already non-circular by design.

gdb/ChangeLog:
2018-05-11  Andrew D'Addesio  <modchipv12@gmail.com>

	* record-full.c (record_full_restore): Avoid null deref when
	appending the arch list to the record list.
---
 gdb/record-full.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/gdb/record-full.c b/gdb/record-full.c
index 79f5c0f..edd30fb 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -2486,11 +2486,13 @@ record_full_restore (void)
 
   discard_cleanups (old_cleanups);
 
-  /* Add record_full_arch_list_head to the end of record list.  */
-  record_full_first.next = record_full_arch_list_head;
-  record_full_arch_list_head->prev = &record_full_first;
-  record_full_arch_list_tail->next = NULL;
-  record_full_list = &record_full_first;
+  /* Append the arch list to the record list.  */
+  if (record_full_arch_list_head != NULL)
+    {
+      record_full_first.next = record_full_arch_list_head;
+      record_full_arch_list_head->prev = &record_full_first;
+      record_full_list = &record_full_first;
+    }
 
   /* Update record_full_insn_max_num.  */
   if (record_full_insn_num > record_full_insn_max_num)
-- 
2.7.4



More information about the Gdb-patches mailing list