From patchwork Fri May 31 18:33:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Warren X-Patchwork-Id: 2645261 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 9E5863FD4E for ; Fri, 31 May 2013 18:33:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754725Ab3EaSdM (ORCPT ); Fri, 31 May 2013 14:33:12 -0400 Received: from avon.wwwdotorg.org ([70.85.31.133]:33542 "EHLO avon.wwwdotorg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753696Ab3EaSdL (ORCPT ); Fri, 31 May 2013 14:33:11 -0400 Received: from severn.wwwdotorg.org (unknown [192.168.65.5]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by avon.wwwdotorg.org (Postfix) with ESMTPS id 976396369; Fri, 31 May 2013 12:40:18 -0600 (MDT) Received: from swarren-lx1.nvidia.com (localhost [127.0.0.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by severn.wwwdotorg.org (Postfix) with ESMTPSA id EB9A2E460E; Fri, 31 May 2013 12:33:08 -0600 (MDT) From: Stephen Warren To: David Gibson , jdl@jdl.com Cc: devicetree-discuss@lists.ozlabs.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, mmarek@suse.cz, rob.herring@calxeda.com, grant.likely@secretlab.ca, linux-kbuild@vger.kernel.org, Stephen Warren Subject: [PATCH V2] dtc: ensure #line directives don't consume data from the next line Date: Fri, 31 May 2013 12:33:04 -0600 Message-Id: <1370025184-23808-1-git-send-email-swarren@wwwdotorg.org> X-Mailer: git-send-email 1.7.10.4 X-NVConfidentiality: public X-Virus-Scanned: clamav-milter 0.97.7 at avon.wwwdotorg.org X-Virus-Status: Clean Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org From: Stephen Warren Previously, the #line parsing regex ended with ({WS}+[0-9]+)?. The {WS} could match line-break characters. If the #line directive did not contain the optional flags field at the end, this could cause any integer data on the next line to be consumed as part of the #line directive parsing. This could cause syntax errors (i.e. #line parsing consuming the leading 0 from a hex literal 0x1234, leaving x1234 to be parsed as cell data, which is a syntax error), or invalid compilation results (i.e. simply consuming literal 1234 as part of the #line processing, thus removing it from the cell data). Fix this by replacing {WS} with [ \t] so that it can't match line-breaks. Convert all instances of {WS}, even though the other instances should be irrelevant for any well-formed #line directive. This is done for consistency and ultimate safety. Reported-by: Ian Campbell Signed-off-by: Stephen Warren Acked-by: David Gibson --- v2: Convert all instances of {WS} in the regex. This is a patch for dtc upstream, in response to thread "DTB build failure due to preproccessing". If/when it's accepted into dtc, I'll follow up with a kernel patch that makes the same fix. --- dtc-lexer.l | 2 +- tests/line_directives.dts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/dtc-lexer.l b/dtc-lexer.l index 254d5af..3b41bfc 100644 --- a/dtc-lexer.l +++ b/dtc-lexer.l @@ -71,7 +71,7 @@ static int pop_input_file(void); push_input_file(name); } -<*>^"#"(line)?{WS}+[0-9]+{WS}+{STRING}({WS}+[0-9]+)? { +<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? { char *line, *tmp, *fn; /* skip text before line # */ line = yytext; diff --git a/tests/line_directives.dts b/tests/line_directives.dts index e9d0800..046ef37 100644 --- a/tests/line_directives.dts +++ b/tests/line_directives.dts @@ -8,4 +8,14 @@ # 6 "bar.dts" / { +/* + * Make sure optional flags don't consume integer data on next line. The issue + * was that the {WS} in the trailing ({WS}+[0-9]+)? could cross the * line- + * break, and consume the leading "0" of the hex constant, leaving "x12345678" + * to be parsed as a number, which is invalid syntax. + */ + prop1 = < +# 10 "qux.dts" + 0x12345678 + >; };