From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 88213 invoked by alias); 17 Oct 2017 11:42:02 -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 88203 invoked by uid 89); 17 Oct 2017 11:42:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 17 Oct 2017 11:42:00 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C2985A721 for ; Tue, 17 Oct 2017 11:41:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C2985A721 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=palves@redhat.com Received: from cascais.lan (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43DBB64447 for ; Tue, 17 Oct 2017 11:41:58 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [pushed] Fix double-free corruption Date: Tue, 17 Oct 2017 11:42:00 -0000 Message-Id: <1508240517-15322-1-git-send-email-palves@redhat.com> X-SW-Source: 2017-10/txt/msg00508.txt.bz2 Fixes a double-free regression introduced by commit b7b030adc405 ("Return unique_xmalloc_ptr from target_read_stralloc"): gdb.sum: Running src/gdb/testsuite/gdb.base/catch-syscall.exp ... ERROR: Process no longer exists Valgrind shows: (gdb) catch syscall ==3687== Thread 1: ==3687== Invalid free() / delete / delete[] / realloc() ==3687== at 0x4C29CF0: free (vg_replace_malloc.c:530) ==3687== by 0x610862: xfree(void*) (common-utils.c:101) ==3687== by 0x440D5D: gdb::xfree_deleter::operator()(char*) const (gdb_unique_ptr.h:34) ==3687== by 0x446CC6: std::unique_ptr >::reset(char*) (unique_ptr.h:344) ==3687== by 0x81BE50: xml_fetch_content_from_file(char const*, void*) (xml-support.c:1042) ==3687== by 0x81DA86: xml_init_syscalls_info(char const*) (xml-syscall.c:366) ==3687== by 0x81DBDD: init_syscalls_info(gdbarch*) (xml-syscall.c:398) ==3687== by 0x81E131: get_syscall_by_number(gdbarch*, int, syscall*) (xml-syscall.c:599) ==3687== by 0x5BE86F: catch_syscall_command_1(char*, int, cmd_list_element*) (break-catch-syscall.c:481) ==3687== by 0x4B46B1: do_sfunc(cmd_list_element*, char*, int) (cli-decode.c:138) ==3687== by 0x4B76B8: cmd_func(cmd_list_element*, char*, int) (cli-decode.c:1952) ==3687== by 0x7E91C7: execute_command(char*, int) (top.c:615) ==3687== Address 0x14332ae0 is 0 bytes inside a block of size 4,096 free'd ==3687== at 0x4C2AB8B: realloc (vg_replace_malloc.c:785) ==3687== by 0x610792: xrealloc (common-utils.c:62) ==3687== by 0x81BE3E: xml_fetch_content_from_file(char const*, void*) (xml-support.c:1042) ==3687== by 0x81DA86: xml_init_syscalls_info(char const*) (xml-syscall.c:366) ==3687== by 0x81DBDD: init_syscalls_info(gdbarch*) (xml-syscall.c:398) ==3687== by 0x81E131: get_syscall_by_number(gdbarch*, int, syscall*) (xml-syscall.c:599) ==3687== by 0x5BE86F: catch_syscall_command_1(char*, int, cmd_list_element*) (break-catch-syscall.c:481) ==3687== by 0x4B46B1: do_sfunc(cmd_list_element*, char*, int) (cli-decode.c:138) ==3687== by 0x4B76B8: cmd_func(cmd_list_element*, char*, int) (cli-decode.c:1952) ==3687== by 0x7E91C7: execute_command(char*, int) (top.c:615) ==3687== by 0x6A422D: command_handler(char*) (event-top.c:583) ==3687== by 0x6A45F2: command_line_handler(char*) (event-top.c:773) [...] The problem is that if xrealloc decides it needs a new memory block, it frees the previous block/pointer, and then text.reset() frees it again. gdb/ChangeLog: 2017-10-17 Pedro Alves * xml-support.c (xml_fetch_content_from_file): Call unique_ptr::release() instead unique_ptr::get() when passing through xrealloc. --- gdb/ChangeLog | 6 ++++++ gdb/xml-support.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6a8d16f..65952c4 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2017-10-17 Pedro Alves + + * xml-support.c (xml_fetch_content_from_file): Call + unique_ptr::release() instead unique_ptr::get() when passing + through xrealloc. + 2017-10-17 Yao Qi * regcache.c (regcache::xfer_part): Remove parameters read and diff --git a/gdb/xml-support.c b/gdb/xml-support.c index 76d03b9..42a4c91 100644 --- a/gdb/xml-support.c +++ b/gdb/xml-support.c @@ -1039,7 +1039,7 @@ xml_fetch_content_from_file (const char *filename, void *baton) break; len = len * 2; - text.reset ((char *) xrealloc (text.get (), len)); + text.reset ((char *) xrealloc (text.release (), len)); } text.get ()[offset] = '\0'; -- 2.5.5