From patchwork Wed Oct 21 14:15:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 40799 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 A5F203953CF3; Wed, 21 Oct 2020 14:15:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A5F203953CF3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1603289754; bh=2UWYOnNWO1WrdIrUEplNyIb6gfP0wBN8L2vEo63nJ10=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=DnsM/uAJQE+m1GxXyQu4Mv8QalDeE+8k6uOyGmCAcxONXdcnTcX3fkpVEPfrUCHzD ZXDhn+fs2YrTjHmV9pQEVOgcqMGqojs6LfaKngxcFx+luffygRqWrvkiZHIf2/bT8A Dw7LIYoiNaNuk8SzAgrTlu4Q2hRSsu/5t0AQzgNI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by sourceware.org (Postfix) with ESMTPS id 0FC843953CF3 for ; Wed, 21 Oct 2020 14:15:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0FC843953CF3 Received: by mail-qk1-x744.google.com with SMTP id i22so2551190qkn.9 for ; Wed, 21 Oct 2020 07:15:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2UWYOnNWO1WrdIrUEplNyIb6gfP0wBN8L2vEo63nJ10=; b=jqu5AzC1fVcwyJtrH0IyHy5q+NtjCsNoE1Nik6hEESWXR5l/WAFP0xyXQYZfCw7K0C 8LdQGqZtuUXOnGYh6NvNCTit8oIWwhgEzO/CG/K/Ap3MjXJ6JkUgvRROEJZF9BfaIqcg ikDhzNCvOn1XtT1VQy+DudYWbq/7a+26Ys5jqPPO/R4XZ4klySaziShR0v7yIhgogt0X w0oR7c9jebPmn+cZmJ8oznvwIhrw//1BHAeWq+r4qzqp/MawiWN7HnZUkckLshAWKO22 b8Fn4iJJQkSTGlbMwhwfuLBKi+R+954sHXcAYEpGZGExYDnsOg+0xvU3Ciq/LbL0uS9N gjOg== X-Gm-Message-State: AOAM533jLQ/v+KXxW6KGbzF47d2bfn/3LhI7i7PLfnaas5QbCtIJtj6x quM9daLRnxnBQ/QA9Dl1Ze3yPIfk6MGW6w== X-Google-Smtp-Source: ABdhPJx/6qWgHdLG5gNdX2k/Jedb68eQapX0l8lRxFcERch5XoruaJ7aWOT/iDcvwuXJgxk58IEX/g== X-Received: by 2002:a37:6790:: with SMTP id b138mr3426268qkc.355.1603289751329; Wed, 21 Oct 2020 07:15:51 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e17sm1187952qts.54.2020.10.21.07.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 07:15:50 -0700 (PDT) To: libc-alpha@sourceware.org, Florian Weimer Subject: [PATCH v3 1/7] linux: Do not skip entries with zero d_ino values [BZ #12165] Date: Wed, 21 Oct 2020 11:15:36 -0300 Message-Id: <20201021141542.2003377-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201021141542.2003377-1-adhemerval.zanella@linaro.org> References: <20201021141542.2003377-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: James Clarke , John Paul Adrian Glaubitz Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" According to Linux commit 2adc376c55194 (vfs: avoid creation of inode number 0 in get_next_ino) Linux did not treat d_ino == 0 as a special case (it is a valid inode number). This patch fixes readdir{64} by not ignoring entried with d_ino being 0. Checked on x86_64-linux-gnu and i686-linux-gnu. --- sysdeps/unix/sysv/linux/readdir.c | 59 +++++++++++------------------ sysdeps/unix/sysv/linux/readdir64.c | 59 +++++++++++------------------ 2 files changed, 44 insertions(+), 74 deletions(-) diff --git a/sysdeps/unix/sysv/linux/readdir.c b/sysdeps/unix/sysv/linux/readdir.c index ca2a8964e9..1a9820e475 100644 --- a/sysdeps/unix/sysv/linux/readdir.c +++ b/sysdeps/unix/sysv/linux/readdir.c @@ -25,51 +25,36 @@ struct dirent * __readdir_unlocked (DIR *dirp) { - struct dirent *dp; - int saved_errno = errno; + const int saved_errno = errno; - do + if (dirp->offset >= dirp->size) { - size_t reclen; - - if (dirp->offset >= dirp->size) + /* We've emptied out our buffer. Refill it. */ + ssize_t bytes = __getdents (dirp->fd, dirp->data, dirp->allocation); + if (bytes <= 0) { - /* We've emptied out our buffer. Refill it. */ - - size_t maxread = dirp->allocation; - ssize_t bytes; - - bytes = __getdents (dirp->fd, dirp->data, maxread); - if (bytes <= 0) - { - /* On some systems getdents fails with ENOENT when the - open directory has been rmdir'd already. POSIX.1 - requires that we treat this condition like normal EOF. */ - if (bytes < 0 && errno == ENOENT) - bytes = 0; - - /* Don't modifiy errno when reaching EOF. */ - if (bytes == 0) - __set_errno (saved_errno); - dp = NULL; - break; - } - dirp->size = (size_t) bytes; - - /* Reset the offset into the buffer. */ - dirp->offset = 0; + /* On some systems getdents fails with ENOENT when the + open directory has been rmdir'd already. POSIX.1 + requires that we treat this condition like normal EOF. */ + if (bytes < 0 && errno == ENOENT) + bytes = 0; + + /* Don't modifiy errno when reaching EOF. */ + if (bytes == 0) + __set_errno (saved_errno); + return NULL; } + dirp->size = bytes; - dp = (struct dirent *) &dirp->data[dirp->offset]; - - reclen = dp->d_reclen; + /* Reset the offset into the buffer. */ + dirp->offset = 0; + } - dirp->offset += reclen; + struct dirent *dp = (struct dirent *) &dirp->data[dirp->offset]; - dirp->filepos = dp->d_off; + dirp->offset += dp->d_reclen; - /* Skip deleted files. */ - } while (dp->d_ino == 0); + dirp->filepos = dp->d_off; return dp; } diff --git a/sysdeps/unix/sysv/linux/readdir64.c b/sysdeps/unix/sysv/linux/readdir64.c index 1aa6e2664f..d35a4595f6 100644 --- a/sysdeps/unix/sysv/linux/readdir64.c +++ b/sysdeps/unix/sysv/linux/readdir64.c @@ -30,55 +30,40 @@ struct dirent64 * __readdir64 (DIR *dirp) { - struct dirent64 *dp; - int saved_errno = errno; + const int saved_errno = errno; #if IS_IN (libc) __libc_lock_lock (dirp->lock); #endif - do + if (dirp->offset >= dirp->size) { - size_t reclen; - - if (dirp->offset >= dirp->size) + /* We've emptied out our buffer. Refill it. */ + ssize_t bytes = __getdents64 (dirp->fd, dirp->data, dirp->allocation); + if (bytes <= 0) { - /* We've emptied out our buffer. Refill it. */ - - size_t maxread = dirp->allocation; - ssize_t bytes; - - bytes = __getdents64 (dirp->fd, dirp->data, maxread); - if (bytes <= 0) - { - /* On some systems getdents fails with ENOENT when the - open directory has been rmdir'd already. POSIX.1 - requires that we treat this condition like normal EOF. */ - if (bytes < 0 && errno == ENOENT) - bytes = 0; - - /* Don't modifiy errno when reaching EOF. */ - if (bytes == 0) - __set_errno (saved_errno); - dp = NULL; - break; - } - dirp->size = (size_t) bytes; - - /* Reset the offset into the buffer. */ - dirp->offset = 0; + /* On some systems getdents fails with ENOENT when the + open directory has been rmdir'd already. POSIX.1 + requires that we treat this condition like normal EOF. */ + if (bytes < 0 && errno == ENOENT) + bytes = 0; + + /* Don't modifiy errno when reaching EOF. */ + if (bytes == 0) + __set_errno (saved_errno); + return NULL; } + dirp->size = bytes; - dp = (struct dirent64 *) &dirp->data[dirp->offset]; - - reclen = dp->d_reclen; + /* Reset the offset into the buffer. */ + dirp->offset = 0; + } - dirp->offset += reclen; + struct dirent64 *dp = (struct dirent64 *) &dirp->data[dirp->offset]; - dirp->filepos = dp->d_off; + dirp->offset += dp->d_reclen; - /* Skip deleted files. */ - } while (dp->d_ino == 0); + dirp->filepos = dp->d_off; #if IS_IN (libc) __libc_lock_unlock (dirp->lock);