From patchwork Tue Apr 12 20:31:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Pokorn=C3=BD?= X-Patchwork-Id: 701841 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3CKVK79030113 for ; Tue, 12 Apr 2011 20:31:20 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756803Ab1DLUbT (ORCPT ); Tue, 12 Apr 2011 16:31:19 -0400 Received: from fep20.mx.upcmail.net ([62.179.121.40]:36102 "EHLO fep20.mx.upcmail.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756056Ab1DLUbS (ORCPT ); Tue, 12 Apr 2011 16:31:18 -0400 Received: from edge03.upcmail.net ([192.168.13.238]) by viefep20-int.chello.at (InterMail vM.8.01.02.02 201-2260-120-106-20100312) with ESMTP id <20110412203114.IOLE13781.viefep20-int.chello.at@edge03.upcmail.net>; Tue, 12 Apr 2011 22:31:14 +0200 Received: from [192.168.42.128] ([94.112.231.238]) by edge03.upcmail.net with edge id WkX91g00d59GDcW03kXBUe; Tue, 12 Apr 2011 22:31:14 +0200 X-SourceIP: 94.112.231.238 Message-ID: <4DA4B68B.9000907@seznam.cz> Date: Tue, 12 Apr 2011 22:31:07 +0200 From: =?ISO-8859-1?Q?Jan_Pokorn=FD?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Lightning/1.0b2 Thunderbird/3.1.8 MIME-Version: 1.0 To: sparse@chrisli.org CC: linux-sparse@vger.kernel.org Subject: [PATCH] show_instruction: tolerate NULL sym for OP_SYMADDR X-Enigmail-Version: 1.1.1 X-Cloudmark-Analysis: v=1.1 cv=zlRBWuFCZaNL9+WHNm1pWLowY5Lx061w2zJBJiDkNAU= c=1 sm=0 a=gr3JKtqGReIA:10 a=hIc-8aFMrYsA:10 a=8nJEP1OIZ-IA:10 a=GGlVx9puu5YMFH0VQPMA:9 a=fyJ_Ewe_s-WwRYdJjQIA:7 a=wPNLvfGTeEIA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 12 Apr 2011 20:31:20 +0000 (UTC) The corner case addressed by this patch can be triggered, e.g., with this command (`sparse' can be substituted with `test-linearize' in which case `-ventry' is not required): $ ./sparse -vv -ventry compat/mmap-blob.c compat/mmap-blob.c:20:21: error: undefined identifier 'CHUNK' compat/mmap-blob.c:21:17: error: undefined identifier 'die' compat/mmap-blob.c:22:20: error: undefined identifier 'NULL' compat/mmap-blob.c:24:23: error: undefined identifier 'NULL' compat/mmap-blob.c:30:31: error: undefined identifier 'CHUNK' compat/mmap-blob.c:31:17: error: undefined identifier 'die' blob_alloc: ep 0xb74f700c: blob_alloc .L0xb74ef00c: compat/mmap-blob.c:16 # snop.32 VOID -> 0[size] # lnop.32 %r1 <- 0[size] Segmentation fault The problem here is that no semantical meaning is found for `CHUNK' identifier (sparse emits an error for this properly) so the respective symbol is stored as a "missing" (NULL) reference in the resulting semantical tree, connected with OP_SYMADDR instruction. With described example, we would normally never have encountered this as the problematic instruction is inactive -- unless we use "be double-verbose" (-vv) switch. This makes sparse library output also such inactive instructions, and when it comes to our OP_SYMADDR, it does segfault due to NULL pointer dereference. The underscore convention mimics the usage of other angle-bracketed labels (namely "" in tokenize.c). Signed-off-by: Jan Pokorny --- linearize.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/linearize.c b/linearize.c index f2034ce..e29ebe8 100644 --- a/linearize.c +++ b/linearize.c @@ -313,6 +313,10 @@ const char *show_instruction(struct instruction *insn) struct symbol *sym = insn->symbol->sym; buf += sprintf(buf, "%s <- ", show_pseudo(insn->target)); + if (!sym) { + buf += sprintf(buf, ""); + break; + } if (sym->bb_target) { buf += sprintf(buf, ".L%p", sym->bb_target); break;