From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0E90E3858C2F for ; Sat, 2 Jul 2022 15:32:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0E90E3858C2F Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-670-Bl60z7uKMhiNjcQpeWNZ_Q-1; Sat, 02 Jul 2022 11:32:55 -0400 X-MC-Unique: Bl60z7uKMhiNjcQpeWNZ_Q-1 Received: by mail-qt1-f200.google.com with SMTP id f28-20020ac8015c000000b003183eca483bso2813284qtg.2 for ; Sat, 02 Jul 2022 08:32:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=MuBl4YDSjyA94xN9qE2t6XNXkJarI3PH40Jg50q+ybo=; b=wM/yFtjisNH9ikH4vvPAtwyhUvTq5Z2ExtaXi0myXq4ngtSYJjiqtS1HcNxOLguR2m qgOPnhLmJ1QZE1BIlIcF2QrS92kqwiaNX1w3LJf/jDGkpzEBUxHHBk3WChCSLWDUlgTC 9CNCMPiFBejNqKUbG4poX9zXNsgNjFDta7ARLQFETXyhIobUHigsH31tCqyswqBHYIcc n9fJHlcfiJJsN5ePUtiP1o9Ta632jVBOivrw73i/69KfRQcxMAuI1zka3KauYARanv5z bheX6zJY+ICum0O61BfRes+pEaOMU5VCg8XvQMgR3/8hueUxnJSbqSEr239Nr0/uFgp+ 9P+g== X-Gm-Message-State: AJIora8uMreHfnRRSblKO23nRwStu5ao9NqYgsRnq5qF5jVHo2bzx+sz gMYa5zbt6p7o1gzC7D1MXSj6dIRqt54UP43M06RuA+/Bl5pprTj6avvMjfzAxURwoekXu3yenJR B1pWQ0/E= X-Received: by 2002:a05:620a:2234:b0:6af:692:1fbf with SMTP id n20-20020a05620a223400b006af06921fbfmr13945500qkh.579.1656775974857; Sat, 02 Jul 2022 08:32:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s2jXdNyFzm9ToyEzO6ilQKoT60JuBiZ2hEvICrvMAgn1IUa2yyo4n6WnocfX9gcTZgfeyGlQ== X-Received: by 2002:a05:620a:2234:b0:6af:692:1fbf with SMTP id n20-20020a05620a223400b006af06921fbfmr13945476qkh.579.1656775974576; Sat, 02 Jul 2022 08:32:54 -0700 (PDT) Received: from t14s.localdomain (c-73-69-212-193.hsd1.nh.comcast.net. [73.69.212.193]) by smtp.gmail.com with ESMTPSA id 196-20020a3704cd000000b006a6ae9150fesm19587582qke.41.2022.07.02.08.32.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Jul 2022 08:32:53 -0700 (PDT) Message-ID: <601493a0acd0f6cb6261f528ab8f36e5ce046077.camel@redhat.com> Subject: Re: [PATCH] PR 106003 From: David Malcolm To: Mir Immad , gcc@gcc.gnu.org Date: Sat, 02 Jul 2022 11:32:53 -0400 In-Reply-To: References: User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, SUBJ_ALL_CAPS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Jul 2022 15:32:58 -0000 On Sat, 2022-07-02 at 19:34 +0530, Mir Immad wrote: > From 62b7b7736975172f03b30783436fbc9217324223 Mon Sep 17 00:00:00 2001 > From: mir > Date: Sat, 2 Jul 2022 15:04:37 +0530 > Subject: [PATCH] analyzer: implement five new warnings for misuse of > POSIX >  file descriptor APIs [PR106003]. > > This patch adds a new state machine to the analyzer for checking usage > of > POSIX file descriptor > APIs with five new warnings. > > It adds: > - check for FD leaks (CWE 775). > - check for double "close" of a FD (CWE-1341). > - check for read/write of a closed file descriptor. > - check whether a file descriptor was used without being checked for > validity. > - check for read/write of a descriptor opened for just writing/reading. > > gcc/ChangeLog: > PR analyzer/106003 > * Makefile.in (ANALYZER_OBJS): Add sm-fd.o. > * doc/invoke.texi:  Add -Wanalyzer-fd-double-close, -Wanalyzer-fd-leak, > -Wanalyzer-fd-access-mode-mismatch, -Wanalyzer-fd-use-without-check, > -Wanalyzer-fd-use-after-close. > > gcc/analyzer/ChangeLog: > PR analyzer/106003 > * analyzer.opt (Wanalyzer-fd-leak): New option. > (Wanalyzer-fd-access-mode-mismatch): New option. > (Wanalyzer-fd-use-without-check): New option. > (Wanalyzer-fd-double-close): New option. > (Wanalyzer-fd-use-after-close): New option. > * sm.h (make_fd_state_machine): New decl. > * sm.cc (make_checkers): Call make_fd_state_machine. > * sm-fd.cc: New file. > > gcc/testsuite/ChangeLog: > PR analyzer/106003 > * gcc.dg/analyzer/fd-1.c: New test. > * gcc.dg/analyzer/fd-2.c: New test. > * gcc.dg/analyzer/fd-3.c: New test. > * gcc.dg/analyzer/fd-4.c: New test. [...snip...] Hi Immad. Thanks for the updated patch. For everyone else, we've been discussing this patch off-list. We've had some issues with gmail mangling patches; FWIW a pristine version of the patch can be seen at: https://mirimmad.github.io/patch-02-07.txt As discussed off-list, you've successfully bootstrapped this patch and run the testsuite without regressions (and a bunch of extra PASSes), so this patch is ready for you to push it to the "master" git branch (aka trunk). Please go ahead with that (or let me know if you need help [1]). Note that Tim's first analyzer patch is also ready to push, so there's a chance that your patches might conflict with each other (though I think you're touching different areas of the analyzer, so I'm hoping that won't happen). There's plenty of scope for followups, such as adding attributes for parameters that expect an open file-descriptor, or for handling socket APIs, etc. Also, Murphy's Law means that there's sure to be at least something we missed in review :/ Let's move followup patches to the gcc-patches mailing list, rather than the "gcc" list. Thanks Dave [1] though I'll only be checking email intermittently this weekend and on Monday (which is a holiday here in the USA).