From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by sourceware.org (Postfix) with ESMTPS id 072673857C74 for ; Wed, 17 Feb 2021 15:57:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 072673857C74 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rtems.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=joel.sherrill@gmail.com Received: by mail-lf1-f42.google.com with SMTP id h26so22406374lfm.1 for ; Wed, 17 Feb 2021 07:57:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:from:date:message-id :subject:to; bh=hRsxibHbz1vOckLJ+pytNxWHfSD9djznNuEJaJF2hAs=; b=DYMCzmnV4olvu65VOW8g/kdp/lIXmzAZ23gcsjC4Kq80ooKgjAu2vFzrGTXlxKpKHM qfyBNFvvgoccg1P+LN0qxM//6drUshtQ89N2jvfYl5K1xgRtpCD/wHZJgsg9FcmzvXtp iFwR6GVI3TpgXsT8PaBQUcqEf7XlIKzUE569ccGTkmcQ0ZsM+AE7KVGFB61WkUZws8Qf XS54MXYKZokIWfRnXLA8pF4ab7fbR/JH37DWjUkgc2Z3xCzV7pkSGnl/e0Drd4dz1Tbh uOLV/NetCndSonYpDuyrh+U81is0Qe0u5RYCLabo3Qt+cXjBdP7B5EdEH01X0g3Ju6C6 Vnhw== X-Gm-Message-State: AOAM5325gfumeFYaO9R3JVJdlo87DXXvR1zYFkCNJ4PO64ATDtoiXd6h YKHI3aAp4O7vxdyPq50e3N98XeOWuak= X-Google-Smtp-Source: ABdhPJyXNR6AaBEoM34VzwwYDf0fFfK7voKoKsX1/PTgUXNKODxhWHx11xbtmz2XvVFg0QgqGKC9TQ== X-Received: by 2002:a19:ef1e:: with SMTP id n30mr15786005lfh.514.1613577476442; Wed, 17 Feb 2021 07:57:56 -0800 (PST) Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com. [209.85.167.42]) by smtp.gmail.com with ESMTPSA id q13sm288936lfc.72.2021.02.17.07.57.55 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 Feb 2021 07:57:56 -0800 (PST) Received: by mail-lf1-f42.google.com with SMTP id p21so22272545lfu.11 for ; Wed, 17 Feb 2021 07:57:55 -0800 (PST) X-Received: by 2002:a19:ec1a:: with SMTP id b26mr15052555lfa.123.1613577475457; Wed, 17 Feb 2021 07:57:55 -0800 (PST) MIME-Version: 1.0 Reply-To: joel@rtems.org From: Joel Sherrill Date: Wed, 17 Feb 2021 09:57:44 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: fileno() Does Not Check for NULL To: Newlib , Ryan Long X-Spam-Status: No, score=-3031.9 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Feb 2021 15:57:59 -0000 Hi In looking at Coverity issues, we are seeing that calls to fileno() are getting flagged as potential NULL dereferences. Looking at the POSIX definition, it seems that it should return an -1/EBADF because NULL isn't a valid stream. https://pubs.opengroup.org/onlinepubs/9699919799/functions/fileno.html I know there is a pattern of not having NULL checks assuming that the environment would catch the fault. But in the embedded environments newlib is used in, there isn't anything to catch the fault. I don't want to add application code to check for a NULL before calling a standard method that isn't robustly checking its arguments. I don't know if it would address the Coverity issue but would adding the nonnull attribute on more methods be acceptable and help? It is defined and used in a few places now. What's the right approach to addressing this? Thanks. --joel