From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 993441F4B5 for ; Tue, 12 Nov 2019 09:40:16 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:cc:references:from:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=vKk31xjOEvh78IgZ pHwNHLxel7QTBe22J/49Kgf/oBHZRIHCv62tevJcL9LJ6Wn2bxqmlwYK3RCAC0SM pyardVvYlSPm9zFditV7C5hM8LXn5I8ndV7is/iYHsfa+DkmPdvmQgdHMsz/qSxA 9g495TxfB4+rHLNTpiRIsBbqrLg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:cc:references:from:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; s=default; bh=9pxX9wB63TWr2AbB4XdQCW vEsu8=; b=adXFq5g5j16wUmDykCzI1W5zgCgN0B5QcctN8Qgzubp8T7Sj32/N/4 KOsdblqvK/7kBP9ndu1I9cRlh++sJNDiiScXJ3Q8j4dtzZ8DPztBSqJs6pwHEgl7 PWpR69IRFD6ZvO50ODBg6kvW6i3C/td+3+KlJMDhMs4xjOnzVnXg8= Received: (qmail 51681 invoked by alias); 12 Nov 2019 09:40:13 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 51673 invoked by uid 89); 12 Nov 2019 09:40:13 -0000 Authentication-Results: sourceware.org; auth=none X-HELO: huawei.com Subject: Re: [PATCH] fix null pointer in mtrace To: Liusirui , CC: , , , References: <1573550539-34259-1-git-send-email-liusirui@huawei.com> From: liqingqing Message-ID: Date: Tue, 12 Nov 2019 17:39:59 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 In-Reply-To: <1573550539-34259-1-git-send-email-liusirui@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On 2019/11/12 17:22, Liusirui wrote: > In a multi-threaded program, some threads request or free memory and try to write trace info > into file which "mallstream" points to. At the same time, another thread calls "muntrace" and > set "mallstream" to NULL. This may cause a segmentation fault. > > The comment in malloc/mtrace.c says "We could be printing a NULL here; that's OK.". Although > the functions mtrace/muntrace are used for debugging, program isn't expected to crash while using > these functions. > > --- > malloc/mtrace.c | 29 ++++++++++++++++------------- > 1 file changed, 16 insertions(+), 13 deletions(-) > > diff --git a/malloc/mtrace.c b/malloc/mtrace.c > index 707f998..33f01b4 100644 > --- a/malloc/mtrace.c > +++ b/malloc/mtrace.c > @@ -44,6 +44,10 @@ > > #define TRACE_BUFFER_SIZE 512 > > +#define mtrace_print(file, format, ...) do { \ > +if (file != NULL) mtrace_print(file, format,##__VA_ARGS__); \ > +} while(0) > + I had tested this scenario, it seems like that the fprintf and other file operation function do not check the invalid argument like the null pointer. does any one knows why fprintf do not check the input? thanks