From patchwork Thu Sep 5 10:12:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1981187 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=J560ZnXK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WzwDQ3MQDz1yfv for ; Thu, 5 Sep 2024 20:13:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B22CF386583C for ; Thu, 5 Sep 2024 10:13:24 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 73CB538654B5 for ; Thu, 5 Sep 2024 10:13:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73CB538654B5 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 73CB538654B5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725531188; cv=none; b=rV6pRiJAaOqoXtKpdSeXOwPoIeRA6/6noPDnDv5KaKFu2nubTKTILrrI72YaPS7ComggamAyTvu/puPIvN5lfJq5zVDGdLA5JFf+3nGkB9PIGnjsHTf7ktmfuH0IWVZjtEAdv/dogApiA5q49IpyuhYSsdB9RXAEHtqP7z0GXDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725531188; c=relaxed/simple; bh=hKPG0PBDXgjuNvm/MeuA857mqJc1Dd3CQTEq5iWjPz8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ODdw8UqN+Rz2BGBYc+eqRuJ9UysDgxIKVkFdQpbnu9VdC+ORnjz98KE0xFa9cOd3+ZIV/B3ZgJoxgKz3Ll60JHdWcNGBrJXsqFsnt+ssB+ap2Y9uRl/Gfv7jJXmEnRZ8+LpumhcJXCNCAxnWaTnc+/yzG7T6gxnqRw37XRP45Bo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725531184; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=bvjOG2rEvXsyXJGAOYtku3EL4OrQg65oh0wqCpe32D8=; b=J560ZnXKt4100unWCzaPj7udoJEe7NIwVAzv+ad0lPXBnjkG+aOMW+uVCRpe0hF+EhPZ0z s4X6FhElN/IvV/Z5cyil6kqsDijgGpdFOwT6vTS12MSvuw9SUIIBakzfEKusVLypc3RPbc +j/QpiXohXJHyeDH2p/mKoGqpG9iXc0= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-597-saaUe7PmMI6YLROsxI2GlQ-1; Thu, 05 Sep 2024 06:13:01 -0400 X-MC-Unique: saaUe7PmMI6YLROsxI2GlQ-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DF4181956077 for ; Thu, 5 Sep 2024 10:13:00 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.26]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 11D03195608A for ; Thu, 5 Sep 2024 10:12:59 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH COMMITTED] Linux: readdir_r needs to report getdents failures (bug 32124) Date: Thu, 05 Sep 2024 12:12:57 +0200 Message-ID: <87mskmflxy.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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~incoming=patchwork.ozlabs.org@sourceware.org I botched patch split, so this is what I committed. The combination of the two patches is identical to what DJ reviewed. ---8<--- Upon error, return the errno value set by the __getdents call in __readdir_unlocked. Previously, kernel-reported errors were ignored. Reviewed-by: DJ Delorie --- sysdeps/unix/sysv/linux/readdir_r.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) base-commit: 3b1d32177635023e37bec7fbfd77c3cfb2659eb1 diff --git a/sysdeps/unix/sysv/linux/readdir_r.c b/sysdeps/unix/sysv/linux/readdir_r.c index ffd5262cf5..1d595688f7 100644 --- a/sysdeps/unix/sysv/linux/readdir_r.c +++ b/sysdeps/unix/sysv/linux/readdir_r.c @@ -25,14 +25,22 @@ __readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result) { struct dirent *dp; size_t reclen; + int saved_errno = errno; __libc_lock_lock (dirp->lock); while (1) { + /* If errno is changed from 0, the NULL return value indicates + an actual error. It overrides a pending ENAMETOOLONG error. */ + __set_errno (0); dp = __readdir_unlocked (dirp); if (dp == NULL) - break; + { + if (errno != 0) + dirp->errcode = errno; + break; + } reclen = dp->d_reclen; if (reclen <= offsetof (struct dirent, d_name) + NAME_MAX + 1) @@ -61,6 +69,7 @@ __readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result) __libc_lock_unlock (dirp->lock); + __set_errno (saved_errno); return dp != NULL ? 0 : dirp->errcode; }