Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5869695rwl; Mon, 9 Jan 2023 00:32:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXvf+I1sUPwUop4o/XZ+qvoOH26eod3R6b8X6FKfC/AeJNo8SaJJV5UbekQV/oCJNsbgKSs7 X-Received: by 2002:a05:6402:541b:b0:499:b672:ee30 with SMTP id ev27-20020a056402541b00b00499b672ee30mr1617114edb.11.1673253149653; Mon, 09 Jan 2023 00:32:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673253149; cv=none; d=google.com; s=arc-20160816; b=DqMLEzSruL1+EAb80Rxjkxw35XIGayOPlYN/hvKa0q5DVGWtS0MwcARyNaze18svAo r9KmAJo4JZR712082wWVAFTadeHrqa4MIOy744pCjWnKXCBGT8KvwOprQpMzm5vKJNqd TBLdpsD8H7lEs+Zz5I/jbI1jjiuN0YzaaqrTh9grDTjCj2eBswAMeZfMntHwNIVn6FFQ Guwiyi7wKZ5gOo4a40xaWsmhB7/VyYk8bVJeOyNm4mVwdgXhj+rUTttXRtnDf/4vDF76 GrbfCK3R7gghZLQDJPfXwt1BOqPDRITVUDRSjdaUuqjd2GwlGMfaFpz7cVfS3v1VrCpC 9OeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=JDYL89Q5GUgmBQuPMiIAC3auyZxcbG2S6dcv46Yl8sw=; b=A2EQf77qDU7/gadoCJjBzuMWFSoZI9hFO0Q740RaSByTMnvPe6ZIEbaxvmUHU0elzJ RPapS3Ot4ESptx9Ot7l1z1Lo4HbFmAi8ijg03Ewaj9hRSQ/AjD0Ad6EfMz7BvM/W4Qe7 SqR4PP/Bp8JO0Fk8lUrX63ZrCcfzbZQHhHEyHZXeWhIUyA8OS5hINPR4YlwxVpDTGH9J 6xQN9yvK/P5KccL/EjlWcKvOq6AzfzT39VJd5q91prMY5iOqmZij6OCgWiRzLnuG3I6o 1jJhnBjmA/8FeMkX4pLkUTNCIFUQojt3uIPLIf6mW8F02oaGF1zDRwkgWZEomCacw9YI obZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u12-20020a50eacc000000b00484111b4313si7917678edp.177.2023.01.09.00.32.16; Mon, 09 Jan 2023 00:32:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234221AbjAIHzd (ORCPT + 54 others); Mon, 9 Jan 2023 02:55:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236181AbjAIHzZ (ORCPT ); Mon, 9 Jan 2023 02:55:25 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D128913DE9 for ; Sun, 8 Jan 2023 23:55:15 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 3097sos7026016; Mon, 9 Jan 2023 08:54:50 +0100 From: Willy Tarreau To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Warner Losh , Willy Tarreau Subject: [PATCH 2/6] tools/nolibc: Fix S_ISxxx macros Date: Mon, 9 Jan 2023 08:54:38 +0100 Message-Id: <20230109075442.25963-3-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20230109075442.25963-1-w@1wt.eu> References: <20230109075442.25963-1-w@1wt.eu> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Warner Losh The mode field has the type encoded as an value in a field, not as a bit mask. Mask the mode with S_IFMT instead of each type to test. Otherwise, false positives are possible: eg S_ISDIR will return true for block devices because S_IFDIR = 0040000 and S_IFBLK = 0060000 since mode is masked with S_IFDIR instead of S_IFMT. These macros now match the similar definitions in tools/include/uapi/linux/stat.h. Signed-off-by: Warner Losh Signed-off-by: Willy Tarreau --- tools/include/nolibc/types.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h index 300e0ff1cd58..f1d64fca7cf0 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -26,13 +26,13 @@ #define S_IFSOCK 0140000 #define S_IFMT 0170000 -#define S_ISDIR(mode) (((mode) & S_IFDIR) == S_IFDIR) -#define S_ISCHR(mode) (((mode) & S_IFCHR) == S_IFCHR) -#define S_ISBLK(mode) (((mode) & S_IFBLK) == S_IFBLK) -#define S_ISREG(mode) (((mode) & S_IFREG) == S_IFREG) -#define S_ISFIFO(mode) (((mode) & S_IFIFO) == S_IFIFO) -#define S_ISLNK(mode) (((mode) & S_IFLNK) == S_IFLNK) -#define S_ISSOCK(mode) (((mode) & S_IFSOCK) == S_IFSOCK) +#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) +#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) +#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) +#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) +#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) /* dirent types */ #define DT_UNKNOWN 0x0 -- 2.35.3