From patchwork Mon May 16 08:43:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 54017 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4D473857C50 for ; Mon, 16 May 2022 09:02:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4D473857C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652691755; bh=UkoXhO0s5kmBmEyNg2oZi/7wdFIfgfQvlSaqlDyfWtc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Xas5o7n62Z+bLNgiRXTLDtZ6PmDb7Claw7wM1lfrlq4cXu4d2KYbOTnAwLuQFWI7O Uw50MmllfWVux5jiGyCZJhAGXi5AwFlkXS13z54wm2eDZVjwjY6GoFu84SFFHHqU5D 8Abb2rW3kcX+G3bBLR6qVDNBOlEF+oN5LDFbDrHU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id E661E385734C for ; Mon, 16 May 2022 08:43:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E661E385734C Received: by mail-wr1-x433.google.com with SMTP id d21so3555050wra.10 for ; Mon, 16 May 2022 01:43:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=UkoXhO0s5kmBmEyNg2oZi/7wdFIfgfQvlSaqlDyfWtc=; b=ILTXgUrKd11xkt1mT7y1r7dEPOJglEMrWnCorqYVr5eDtaDxPqJcNzpS1GUXjLniR/ H3HZ29dQoZGcLY03Pb+PABACrA00CQeMQiENar4VRywSXIWk2e1slcuOG4nyiaiRK832 6fwyOW3mqYsp/VxK030iHKxkJY/OZ0+v95Bz6CGwMd1GATYwJtJhr61Dy5nlpizagunw iUsocfRoQlSu6cjALq0AQxaLFKz4GnMWmj2jcQVm99nNpO/yfZ8vbwiVhv6tgqRRD9tN FmEN3DYWhqy1jUv8JN/EPL2gC9REhNc+DLScW3uE5XZkmMU8S9flFEzg+5jz+biBye7F 4d6g== X-Gm-Message-State: AOAM531FeNXc1AHfhFrTFeCdoFZRKqRVNZqeOPIwnQZ98mtuznCBCY19 EzmqIrelQxvuGuAev2AlmxJ7+e63E3cncg== X-Google-Smtp-Source: ABdhPJzqzei7aPs8dD1xqJTf8ubYggCFCjZpMG8bf/OEhtNSFA5TysBjlP/6qcgfCr6vWZBf7ihk+Q== X-Received: by 2002:a5d:460a:0:b0:20d:1029:5cff with SMTP id t10-20020a5d460a000000b0020d10295cffmr577350wrq.335.1652690595542; Mon, 16 May 2022 01:43:15 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id j25-20020adfa799000000b0020c5253d8dbsm8963938wrc.39.2022.05.16.01.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 01:43:15 -0700 (PDT) Date: Mon, 16 May 2022 08:43:14 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] sigaction result not properly checked in __gnat_install_handler (QNX) Message-ID: <20220516084314.GA3843704@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Joel Brobecker Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The QNX version of __gnat_install_handler calls sigaction for a number of signals, and then prints an error message when the the call failed. But unfortunately, except for the first call, we forgot to store sigaction's return value, so the check that ensues uses a potentially uninitialized variable, which the compiler does detect (this is how we found this issue). This change fixes this by make sure we store the result of each sigaction call before checking it. While at it, we noticed a thinko in the error messages all alerting about the SIGFPE signal, rather than the signal it just tested. Most likely a copy/paste thinko. Fixed by this change as well. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * init.c (__gnat_install_handler) [__QNX__]: Save sigaction's return value in err before checking err's value. Fix incorrect signal names in perror messages. diff --git a/gcc/ada/init.c b/gcc/ada/init.c --- a/gcc/ada/init.c +++ b/gcc/ada/init.c @@ -2625,26 +2625,26 @@ __gnat_install_handler (void) } } if (__gnat_get_interrupt_state (SIGILL) != 's') { - sigaction (SIGILL, &act, NULL); + err = sigaction (SIGILL, &act, NULL); if (err == -1) { err = errno; - perror ("error while attaching SIGFPE"); + perror ("error while attaching SIGILL"); perror (strerror (err)); } } if (__gnat_get_interrupt_state (SIGSEGV) != 's') { - sigaction (SIGSEGV, &act, NULL); + err = sigaction (SIGSEGV, &act, NULL); if (err == -1) { err = errno; - perror ("error while attaching SIGFPE"); + perror ("error while attaching SIGSEGV"); perror (strerror (err)); } } if (__gnat_get_interrupt_state (SIGBUS) != 's') { - sigaction (SIGBUS, &act, NULL); + err = sigaction (SIGBUS, &act, NULL); if (err == -1) { err = errno; - perror ("error while attaching SIGFPE"); + perror ("error while attaching SIGBUS"); perror (strerror (err)); } }