From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 94888 invoked by alias); 24 Oct 2016 21:52:33 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 94869 invoked by uid 89); 24 Oct 2016 21:52:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS,URIBL_RED autolearn=ham version=3.3.2 spammy=*msg X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Oct 2016 21:52:22 +0000 Received: from svr-orw-fem-03.mgc.mentorg.com ([147.34.97.39]) by relay1.mentorg.com with esmtp id 1bynAK-00056J-Is from Luis_Gustavo@mentor.com for gdb-patches@sourceware.org; Mon, 24 Oct 2016 14:52:20 -0700 Received: from Opsys.world.mentorg.com (147.34.91.1) by svr-orw-fem-03.mgc.mentorg.com (147.34.97.39) with Microsoft SMTP Server id 14.3.224.2; Mon, 24 Oct 2016 14:52:20 -0700 From: Luis Machado To: Subject: [PATCH] Fix potential NULL pointer dereference Date: Mon, 24 Oct 2016 21:52:00 -0000 Message-ID: <1477345938-32287-1-git-send-email-lgustavo@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00668.txt.bz2 This patch addresses a potential NULL pointer dereference when we try to duplicate a string. The input pointer can be NULL and that may lead to crashes. We just use a statically-allocated string to prevent bad things from happening. gdb/ChangeLog: 2016-10-24 Luis Machado * exec.c (exec_file_locate_attach): Prevent NULL pointer dereference when duplicating a string. --- gdb/ChangeLog | 5 +++++ gdb/exec.c | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 388cc1f..43175ff 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2016-10-24 Luis Machado + * exec.c (exec_file_locate_attach): Prevent NULL pointer dereference + when duplicating a string. + +2016-10-24 Luis Machado + * exec.c (exception_print_same): Fix string comparison to use statically-allocated ones. diff --git a/gdb/exec.c b/gdb/exec.c index 67ecc63..5eeac44 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -221,13 +221,20 @@ exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty) } CATCH (err, RETURN_MASK_ERROR) { + const char *msg; + if (err.message != NULL) - warning ("%s", err.message); + { + warning ("%s", err.message); + msg = err.message; + } + else + msg = ""; prev_err = err; /* Save message so it doesn't get trashed by the catch below. */ - prev_err.message = xstrdup (err.message); + prev_err.message = xstrdup (msg); } END_CATCH -- 2.7.4