From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 8BD741F4B4 for ; Sat, 9 Jan 2021 07:25:19 +0000 (UTC) Received: from localhost ([::1]:54560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ky8cg-0007oh-Ow for normalperson@yhbt.net; Sat, 09 Jan 2021 02:25:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ky8cd-0007n6-7I for bug-gnulib@gnu.org; Sat, 09 Jan 2021 02:25:15 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([85.215.255.20]:27694) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ky8cb-0000GF-BK for bug-gnulib@gnu.org; Sat, 09 Jan 2021 02:25:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1610177111; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:From:Subject:Sender; bh=MAltumVAl9ys7xXRyeJied2a5kY4CMNyIC4lei44bUA=; b=hMhLbDpNUjajLWR3U82O4Wxi610MXknt86hTDHVxPIKvBYiqMKbUr5UsRoCk3bciD+ +BCybF3UqNUlR/+izD2nUw3e5PkrFcfG7ukL93u1+UN8iFIbNWMqJYEhq+cXw3AM1TJX AC123rwMi+g7WAm9eUALSarEtewEs90jTbDEZCLGF+FLYNCMG65ljAdhYyWwShQCKwdP 1JwtzvmggOjYYBCbVax3AtX9fLfwFDEwllan3+t9gE5JYRS1WU6qul0ltAD5RwcLs/Tk OizCdFpC8RtDX9kujlojtvswj9S5XvuGEtZeF/TmWVafEc+Mcb9XM+v6bG4BktLS6HTM rIgw== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOHqfyyvs=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 47.12.1 DYNA|AUTH) with ESMTPSA id u0aa20x097PBDSL (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Sat, 9 Jan 2021 08:25:11 +0100 (CET) From: Bruno Haible To: bug-gnulib@gnu.org Subject: fchmod-tests, fchmodat tests, lchmod tests: Add more tests Date: Sat, 09 Jan 2021 08:25:10 +0100 Message-ID: <3704556.0YkK4g5aho@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-197-generic; KDE/5.18.0; x86_64; ; ) MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: none client-ip=85.215.255.20; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" It smells like additional tests for fchmod(), fchmodat(), lchmod() could uncover bugs on some platforms. So I'm adding more tests. 2021-01-09 Bruno Haible fchmod-tests, fchmodat tests, lchmod tests: Add more tests. * tests/test-fchmod.c: Include . (BASE): New macro. (main): Add more tests. * tests/test-fchmodat.c (main): Add more tests. * tests/test-lchmod.c (main): Likewise. diff --git a/tests/test-fchmod.c b/tests/test-fchmod.c index 43b70ac..f8db9e5 100644 --- a/tests/test-fchmod.c +++ b/tests/test-fchmod.c @@ -22,10 +22,13 @@ SIGNATURE_CHECK (fchmod, int, (int, mode_t)); #include +#include #include #include "macros.h" +#define BASE "test-fchmod." + int main (void) { @@ -42,5 +45,24 @@ main (void) ASSERT (errno == EBADF); } + /* Test that fchmod works on regular files. */ + { + struct stat statbuf; + int fd; + + unlink (BASE "file"); + ASSERT (close (creat (BASE "file", 0600)) == 0); + fd = open (BASE "file", O_RDWR); + ASSERT (fd >= 0); + ASSERT (fchmod (fd, 0400) == 0); + ASSERT (stat (BASE "file", &statbuf) >= 0); + ASSERT ((statbuf.st_mode & 0700) == 0400); + ASSERT (close (fd) == 0); + + /* Clean up. */ + ASSERT (chmod (BASE "file", 0600) == 0); + ASSERT (unlink (BASE "file") == 0); + } + return 0; } diff --git a/tests/test-fchmodat.c b/tests/test-fchmodat.c index 5e4d2b0..6d430fa 100644 --- a/tests/test-fchmodat.c +++ b/tests/test-fchmodat.c @@ -46,6 +46,39 @@ main (void) ASSERT (errno == EBADF); } + /* Test that fchmodat works on regular files. */ + { + struct stat statbuf; + + unlink (BASE "file"); + ASSERT (close (creat (BASE "file", 0600)) == 0); + ASSERT (fchmodat (AT_FDCWD, BASE "file", 0400, 0) == 0); + ASSERT (stat (BASE "file", &statbuf) >= 0); + ASSERT ((statbuf.st_mode & 0700) == 0400); + + errno = 0; + ASSERT (fchmodat (AT_FDCWD, BASE "file/", 0600, 0) == -1); + ASSERT (errno == ENOTDIR); + + /* Clean up. */ + ASSERT (chmod (BASE "file", 0600) == 0); + ASSERT (unlink (BASE "file") == 0); + } + + /* Test that fchmodat works on directories. */ + { + struct stat statbuf; + rmdir (BASE "dir"); + ASSERT (mkdir (BASE "dir", 0700) == 0); + ASSERT (fchmodat (AT_FDCWD, BASE "dir", 0500, 0) == 0); + ASSERT (stat (BASE "dir", &statbuf) >= 0); + ASSERT ((statbuf.st_mode & 0700) == 0500); + ASSERT (fchmodat (AT_FDCWD, BASE "dir/", 0700, 0) == 0); + + /* Clean up. */ + ASSERT (rmdir (BASE "dir") == 0); + } + /* Test that fchmodat works on non-symlinks, when given the AT_SYMLINK_NOFOLLOW flag. */ { diff --git a/tests/test-lchmod.c b/tests/test-lchmod.c index 7b8e8a1..d4c811e 100644 --- a/tests/test-lchmod.c +++ b/tests/test-lchmod.c @@ -33,7 +33,7 @@ SIGNATURE_CHECK (lchmod, int, (const char *, mode_t)); int main (void) { - /* Test that lchmod works on non-symlinks. */ + /* Test that lchmod works on regular files. */ { struct stat statbuf; unlink (BASE "file"); @@ -41,11 +41,31 @@ main (void) ASSERT (lchmod (BASE "file", 0400) == 0); ASSERT (stat (BASE "file", &statbuf) >= 0); ASSERT ((statbuf.st_mode & 0700) == 0400); + + errno = 0; + ASSERT (lchmod (BASE "file/", 0600) == -1); + ASSERT (errno == ENOTDIR); + /* Clean up. */ ASSERT (chmod (BASE "file", 0600) == 0); ASSERT (unlink (BASE "file") == 0); } + /* Test that lchmod works on directories. */ + { + struct stat statbuf; + + rmdir (BASE "dir"); + ASSERT (mkdir (BASE "dir", 0700) == 0); + ASSERT (lchmod (BASE "dir", 0500) == 0); + ASSERT (stat (BASE "dir", &statbuf) >= 0); + ASSERT ((statbuf.st_mode & 0700) == 0500); + ASSERT (lchmod (BASE "dir/", 0700) == 0); + + /* Clean up. */ + ASSERT (rmdir (BASE "dir") == 0); + } + /* Test that lchmod on symlinks does not modify the symlink target. */ { unlink (BASE "file");