From patchwork Thu Jan 16 17:48:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 11337479 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D1236C1 for ; Thu, 16 Jan 2020 17:48:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E58002468D for ; Thu, 16 Jan 2020 17:48:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XvWMEfbI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394343AbgAPRsv (ORCPT ); Thu, 16 Jan 2020 12:48:51 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:34931 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2394372AbgAPRsu (ORCPT ); Thu, 16 Jan 2020 12:48:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579196929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Q/9dDHwRWNQXoX58uAcweA8Z/0wxyOZ+fRZtSsKmpX0=; b=XvWMEfbIXNZEWJZvPOo3xPTAfQEIGRHLrXO55RsnaGjohPSt5zqgkFLFmaskQe9AEm2DDv AlyaygLtqmOmdctaQNXFhbOrJo9UX5dY+GlirhnyKAd4oQ2b83ntS3/6KykUXFVC/w33EC FsTaG1NYLoPDWl7T1N6UTsxss9C+bnY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-204-gzBSZOZwMEKW6n9RFhEhkw-1; Thu, 16 Jan 2020 12:48:45 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 63DDD800D41; Thu, 16 Jan 2020 17:48:44 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (ovpn-204-21.brq.redhat.com [10.40.204.21]) by smtp.corp.redhat.com (Postfix) with SMTP id 8CB375C1D8; Thu, 16 Jan 2020 17:48:40 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 16 Jan 2020 18:48:43 +0100 (CET) Date: Thu, 16 Jan 2020 18:48:38 +0100 From: Oleg Nesterov To: Luc Van Oostenryck Cc: Alexey Gladkov , linux-sparse@vger.kernel.org Subject: [PATCH] show_parse: avoid null pointer dereference in do_show_type() Message-ID: <20200116174838.GA32100@redhat.com> MIME-Version: 1.0 User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: gzBSZOZwMEKW6n9RFhEhkw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org do_show_type() checks sym->type inside the "if (!sym || ...)" block. While at it, remove the trailing whitespaces. Fixes: 0fe7ebb9 ("show-parse: do not display base type's redundant specifiers") Reported-by: Alexey Gladkov Signed-off-by: Oleg Nesterov --- show-parse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/show-parse.c b/show-parse.c index f0ea9ca..044465e 100644 --- a/show-parse.c +++ b/show-parse.c @@ -300,12 +300,12 @@ deeper: if (as) prepend(name, "%s ", show_as(as)); - if (sym->type == SYM_BASETYPE || sym->type == SYM_ENUM) + if (sym && (sym->type == SYM_BASETYPE || sym->type == SYM_ENUM)) mod &= ~MOD_SPECIFIER; s = modifier_string(mod); len = strlen(s); - name->start -= len; - memcpy(name->start, s, len); + name->start -= len; + memcpy(name->start, s, len); mod = 0; as = NULL; }