From patchwork Mon Jun 23 15:12:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 114890 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 51852384A418 for ; Mon, 23 Jun 2025 15:14:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51852384A418 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Qw6Vmg0H X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 13BE03860C3A for ; Mon, 23 Jun 2025 15:12:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13BE03860C3A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 13BE03860C3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::329 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1750691572; cv=none; b=Dxg/I2iuj+VQJhh1MTAZKgRX2yPf5rC2yNjb+w3UzJXfp9mNknH66dNhdlS+UhmtIckDlz34D1VCB5jPXOpXacx6+NBc14p2JouT+46geKRkFqAmHy0ba5DAFZiZ+Vfm2XoKbszA+OreeT3XNIH18q9SNkL9E6xNn9mdRMqJMAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1750691572; c=relaxed/simple; bh=cXg49pTmBKzkajqmpe+AuYFw2nL/X+2YE6WG0YLj78s=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=m08sHrytMm7cq/EF9qY3kt5On7c+zi+ZrObcUvs+VIIUVEhaIrI8eL52A0ESXDBV7dK3aPz5IFbe9AhH4ORVVr5CbAZ/u5XZYD8FEG5hhnGfWVxtr4LluipMghLEfABOuIutpRvt1wvXXx9Xs9x9xImPm5dgRQD7Mg0mjdC6x2Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13BE03860C3A Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-453749aef9eso4534835e9.3 for ; Mon, 23 Jun 2025 08:12:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750691570; x=1751296370; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7AXwhZLyTHbJ2tR5TW5JfKsZJ87qD7mF0Qzue5EqrHA=; b=Qw6Vmg0HoekB7qpd6xjDDEmY37JWMC0VV8zRemS4yEvDaIP02OLGrb1a9Ej8W7o0P5 R626IjcVMfUklweMDAiBtrfpBbvWHHJ+TzgNrqzfJoZjyu2SHOvSmppdj1ubPagglyDm ird9D6lDJsPixE4d7W8jiRBH3tyjoEd8qAtiJdbsv+oTUb7h6WwCVt2TFje5mf13Bj72 yzpreDoy3ZkysxNRbJy+O2d7Ef0bSKympkMJ8Xd4sj3agftOaabEGF6s6w18Wf+vTDd0 oil99aGjKQtisfhKG/r/kSsLy2XttbxpabKoNfrZ28BVNpFtH6dQk4gjQ4HOVVcT7BFV N5Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750691570; x=1751296370; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7AXwhZLyTHbJ2tR5TW5JfKsZJ87q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mr106438125e9.1.1750691570325; Mon, 23 Jun 2025 08:12:50 -0700 (PDT) Received: from fedorarm.. (net-37-182-2-165.cust.vodafonedsl.it. [37.182.2.165]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a6d145e520sm9574170f8f.20.2025.06.23.08.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jun 2025 08:12:49 -0700 (PDT) From: Matteo Croce To: libc-alpha@sourceware.org Cc: Adhemerval Zanella Netto , Matteo Croce Subject: [PATCH v4] fstat: add test and documentation for an edge case. Date: Mon, 23 Jun 2025 17:12:47 +0200 Message-ID: <20250623151247.456811-1-technoboy85@gmail.com> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Matteo Croce The fstatat behaviour when the target is a dangling symlink is different if flags contains AT_SYMLINK_NOFOLLOW or not. Add a test for this and document it. --- io/tst-stat.c | 17 ++++++++++++++++- manual/filesys.texi | 5 +++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/io/tst-stat.c b/io/tst-stat.c index 61bdbfb638..932014a7f9 100644 --- a/io/tst-stat.c +++ b/io/tst-stat.c @@ -62,12 +62,23 @@ fstatat_check (int fd, const char *path, struct stat *st) TEST_COMPARE (fstatat (fd, path, st, 0), 0); } +static void +fstatat_link (const char *path, struct stat *st) +{ + TEST_COMPARE (fstatat (AT_FDCWD, path, st, 0), -1); + TEST_COMPARE (errno, ENOENT); + + TEST_COMPARE (fstatat (AT_FDCWD, path, st, AT_SYMLINK_NOFOLLOW), 0); + TEST_COMPARE (!S_ISLNK(st->st_mode), 0); +} + typedef void (*test_t)(int, const char *path, struct stat *); static int do_test (void) { char *path; + const char *linkame = "tst-fstat.linkname"; int fd = create_temp_file ("tst-fstat.", &path); TEST_VERIFY_EXIT (fd >= 0); support_write_file_string (path, "abc"); @@ -81,13 +92,13 @@ do_test (void) printf ("warning: timestamp with nanoseconds not supported\n"); struct statx stx; + struct stat st; TEST_COMPARE (statx (fd, path, 0, STATX_BASIC_STATS, &stx), 0); test_t tests[] = { stat_check, lstat_check, fstat_check, fstatat_check }; for (int i = 0; i < array_length (tests); i++) { - struct stat st; tests[i](fd, path, &st); TEST_COMPARE (stx.stx_dev_major, major (st.st_dev)); @@ -111,6 +122,10 @@ do_test (void) } } + symlink ("tst-fstat.target", linkame); + add_temp_file (linkame); + fstatat_link (linkame, &st); + return 0; } diff --git a/manual/filesys.texi b/manual/filesys.texi index d0ced84bf6..4406201dab 100644 --- a/manual/filesys.texi +++ b/manual/filesys.texi @@ -2397,8 +2397,9 @@ The descriptor @var{filedes} is not associated with a directory, and @var{filename} is a relative file name. @item ENOENT -The file named by @var{filename} does not exist, or @var{filename} is an -empty string and @var{flags} does not contain @code{AT_EMPTY_PATH}. +The file named by @var{filename} does not exist, it's a dangling symbolic link +and @var{flags} does not contain @code{AT_SYMLINK_NOFOLLOW}, or @var{filename} +is an empty string and @var{flags} does not contain @code{AT_EMPTY_PATH}. @end table When the sources are compiled with @code{_FILE_OFFSET_BITS == 64} this