From patchwork Fri May 11 21:54:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew D'Addesio X-Patchwork-Id: 27252 Received: (qmail 91752 invoked by alias); 11 May 2018 21:55:38 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 91731 invoked by uid 89); 11 May 2018 21:55:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=2.7.4, our X-HELO: mail-ot0-f170.google.com Received: from mail-ot0-f170.google.com (HELO mail-ot0-f170.google.com) (74.125.82.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 11 May 2018 21:55:36 +0000 Received: by mail-ot0-f170.google.com with SMTP id g7-v6so7865586otj.11 for ; Fri, 11 May 2018 14:55:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=H9obqFnL+YNWpbI+B1AHd5Z0XNnRcR6c+L34aWxpk7Q=; b=n8QUTzqO3nC+caKxbo6QOpkAuwpOatMyjPq6U0inblg+WO2Q1Ui/2nxutGIaJtNG2G gIr3XDpYxUP+IW43XWHwODYuQEk4oqhkfXSbo/TCGxaeSe3XAi0cjOmC8+dQC/UsywzP r8hFUPOWyrpX8cgIfd9Ws54nKpQrEeoha5ecI8FoXt0xBJGNNS/k9xPF5oUwVTWRjlUi a0WjlAUg/z4RTIMh1PguiyDBlOaKTKXFpkVjXwA2ENt6/EX99d4X6MyNHdoyTHruBDGt 9/gqweV1sD7+pyMBhN18gJjqyA+pau+2X1I5+aZy/jezKDqX4fMvl75mVzDx6TSQP1Hl c3Aw== X-Gm-Message-State: ALKqPwf1wh5Qg88yKBl1NVUSUuhDtoVHooJRsxdwCpoWFz4vc+Mw44ed mtE/s38dRgmAvsE0QU+C7I0lYA== X-Google-Smtp-Source: AB8JxZrzbCxWdrdu+BmkVywhNNN2yDJE565S4JEU/gxKSrO2MqsrQ7fqKw4wfqQt72p5H+q7jd/0gQ== X-Received: by 2002:a9d:40ad:: with SMTP id n42-v6mr4950208ote.389.1526075734386; Fri, 11 May 2018 14:55:34 -0700 (PDT) Received: from jigglypuff-PC.aus.lan ([64.157.241.12]) by smtp.gmail.com with ESMTPSA id n50-v6sm2481794otb.14.2018.05.11.14.55.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 May 2018 14:55:33 -0700 (PDT) From: Andrew D'Addesio To: gdb-patches@sourceware.org Cc: Andrew D'Addesio Subject: [PATCH] Process record: Fix null deref when loading empty core file Date: Fri, 11 May 2018 16:54:58 -0500 Message-Id: <1526075698-20880-1-git-send-email-modchipv12@gmail.com> 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 * 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)