From patchwork Fri Oct 16 16:25:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1383444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=HB+Ar8+G; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CCWj66K7Pz9sSs for ; Sat, 17 Oct 2020 03:25:28 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 732493851C3C; Fri, 16 Oct 2020 16:25:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by sourceware.org (Postfix) with ESMTPS id 21C013857801 for ; Fri, 16 Oct 2020 16:25:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 21C013857801 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qt1-x82d.google.com with SMTP id e6so1927793qtw.10 for ; Fri, 16 Oct 2020 09:25:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=GM+wGYhLp+1As8ZlueYPWEb2Nj/h4D/Qqb5R+tXOSXM=; b=HB+Ar8+Gdnx72MbNhdkb5YujdBkqNGV4hHISOtoI6oxHihROc14M7Be/CxW4i9zXbc pPfXjuLt8dVlFB1ahnk8aU7cMKlamac4BrzzcJUrP5t9vqwJYdRepz8XCS7kiqGneTiH 9JnC8QRgR3Uzq768SGcCK//u7/NKVlBZ21sT65mHVQvubVy9+Vgwmu+anxLMjkUD8FJj RoxdDJYNMDPz+cqleLiRSdtLqvzwffTCzGHO06T9Qq/6ezxZF75Jsub5xAg5CoyvdHBN TF0oL6VrAwKhnmOxXYXi0DM8lzVPzghsKpWg1KcszcgGee18yDXkuTRAbwVX5C4sf6Eq MBXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=GM+wGYhLp+1As8ZlueYPWEb2Nj/h4D/Qqb5R+tXOSXM=; b=af86TRDEr1sy7nsJqIZeAdqn29MSKeJTehj7c9/HyzphyqqrTL5t0ny0LJJ9oZbhS1 Gb7yw4+Rg0GY/fsTWWMTwrEd+i8/9c336Qc1sF4lyxOi5xO/SoVbUZPIyOhKf6w+D1j+ 5DganrgprRZ+D0t97eazmCaoNM9U6OVbJ03yARc68xUH+BJ/RxoxzG84Mwjh6A28mBGg 0ZCyurRbMlF84+dvo8XqNoj4rKcZGN31I4vE8hboLl1bxDs6ENECo6d1Fyr2UXoATGee ewwjnXQmuPROqJxSo+UXy6izuv+lKuBfvMHyKkeMxlT6tM7it6GFj+llAl18JB47RA9P o5BA== X-Gm-Message-State: AOAM532EJaXu5Kk8zMcF7D0TBR697jt7FKbwrHPfgaB9nb+vlK4FI8/8 lBsAQHlWbW3Vtt86wjQa2Bg= X-Google-Smtp-Source: ABdhPJztqXgNnq8VdfwFbzZiH8hKivhSO/WTQPf0dTm2PSY+K8XqafX3syvQLGdVLJNHDHvY7goAug== X-Received: by 2002:ac8:1af2:: with SMTP id h47mr4107433qtk.346.1602865522305; Fri, 16 Oct 2020 09:25:22 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:a104:3710:c1c2:305f? ([2620:10d:c091:480::1:cfb1]) by smtp.googlemail.com with ESMTPSA id t9sm1042609qkt.49.2020.10.16.09.25.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Oct 2020 09:25:21 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: c++: Fix null deref at EOF [PR96258] Message-ID: <5c062fd7-f6c5-7bfa-5525-7929ba2f3ee7@acm.org> Date: Fri, 16 Oct 2020 12:25:19 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" cp_parser_declaration peeks at 1 or 2 tokens, when I changed it not to peek past EOF, I set the second token to NULL. But there are paths through the function that just look at the second token. Fixed by setting that token to EOF rather than NULL in this case. PR c++/96258 gcc/cp/ * parser.c (cp_parser_declaration): Make token2 point to EOF if token1 was EOF. gcc/testsuite/ * g++.dg/parse/pr96258.C: New. pushing to trunk nathan diff --git c/gcc/cp/parser.c w/gcc/cp/parser.c index 592ce95b571..7ec7d42773c 100644 --- c/gcc/cp/parser.c +++ w/gcc/cp/parser.c @@ -13497,10 +13497,8 @@ cp_parser_declaration (cp_parser* parser) /* Try to figure out what kind of declaration is present. */ cp_token *token1 = cp_lexer_peek_token (parser->lexer); - cp_token *token2 = NULL; - - if (token1->type != CPP_EOF) - token2 = cp_lexer_peek_nth_token (parser->lexer, 2); + cp_token *token2 = (token1->type == CPP_EOF + ? token1 : cp_lexer_peek_nth_token (parser->lexer, 2)); /* Get the high-water mark for the DECLARATOR_OBSTACK. */ void *p = obstack_alloc (&declarator_obstack, 0); diff --git c/gcc/testsuite/g++.dg/parse/pr96258.C w/gcc/testsuite/g++.dg/parse/pr96258.C new file mode 100644 index 00000000000..1b642e1fc38 --- /dev/null +++ w/gcc/testsuite/g++.dg/parse/pr96258.C @@ -0,0 +1,5 @@ +// { dg-additional-options -fopenmp } +// { dg-require-effective-target fopenmp } +#pragma omp declare simd // { dg-error "not immediately followed by" } + +// { dg-error "-:expected unqualified-id" "" { target *-*-* } .+1 }