From nobody Thu Nov 30 23:48:47 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ShCZR34CWz52yfv; Thu, 30 Nov 2023 23:48:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ShCZR2SQrz3gdF; Thu, 30 Nov 2023 23:48:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701388127; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lpFZtcvD6JXPRO3IhoHJAKf2ddvru8xsh9MIuu9LZww=; b=bqi7yJkORikNskP7n/3tZ+gs23ckSEadrVb3QoFOAQ3D9yo177axGLhRTN3BrEhEkA6Jpk TQ/2599+SjXUB22ZQ2MF3jQCp2XganHDmjgwxveu4gUeZME0YDH4bMalwKBUD4v6Xtsz5/ Rlkg6nHdVq/VKSnRvemQfsI7/ZnoC/Tu5U1R8r+riJKP7NxB8XHYu7VIY1gXNxo25od9KD TASi5J1qJzzU+7fFw2bBO9inIfta8pIY/3eoPUt+5nAvtSFP7Yh3xSvBlL/KNRk2dXQOh3 UTpGQRwAIXT+pfGbhHOmUL6xdGSetT66Lqswa7aWlFnCPn5dVT6kT1hw/xiHOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701388127; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lpFZtcvD6JXPRO3IhoHJAKf2ddvru8xsh9MIuu9LZww=; b=S8XTtP89Kzilxg4jaEE+pvE2OEV/8Kvt9DAFZywsNSCFzP9xr5JLoQoeFgBEhafQUWv5Eg gMLWQGHdiFB5pbs7SnewpC6QJlmxS/0/z4uR2ZovuhI9+WBHaxLfpcODzwsA1FzaI2yAEB ss3kT7x428O4X35yViSvcVC3xDenBwQYn4nW06/hHjt3VcSEmxZxWD9cW6R9pIM9nKOBVZ 4q4ZjVM4JrdFYBjdKRGRy0Rz63K2BI029pvjwHJOsynRdXiX0v4E/Hw9hTugz9gp54R+KK D3p/007cbFVzcZe8ZBjocMIWa9WOXIYxGVOzZ6WaqXyVBU44t8f8nVvo+5Nhzg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1701388127; a=rsa-sha256; cv=none; b=MYkrPPIsRJoTLGR/OwOE1b+Wvl0XkH7NrNrcAVd/ioWbGWe53S1r632E0KNjTqUba+oNUv le2tXszRagLp8iRReua9k2+28giQnMHpROoyMhUn1cRGdvM7wwSejlWvwlHrZEs/srE3A2 Lbe2JRJ0h3OoqRGsVO0DgqNf/xJBk4kCYxghI2aG31/WOgfn6EGiUHVRhbFcwuuqFO/Qap RVoxCm6P1TAF3TbH4CkIzPlgRCCVZ9wgjvERAZF++lI0E1elsOjTU55wLI3T2pLuOQtkA7 UxxyKalNRqTueKH0WKVQxjY4ogPyGerGN7pCa/nhitfF5dLMlYipmMuJYmpcfQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4ShCZR1TbGz19Mk; Thu, 30 Nov 2023 23:48:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3AUNmlQ0072987; Thu, 30 Nov 2023 23:48:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AUNml49072984; Thu, 30 Nov 2023 23:48:47 GMT (envelope-from git) Date: Thu, 30 Nov 2023 23:48:47 GMT Message-Id: <202311302348.3AUNml49072984@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: e8dd46ee96c8 - stable/13 - fusefs: add more readdir tests for misbehaving servers List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e8dd46ee96c82ed06e5d79f503203a40719fb8d8 Auto-Submitted: auto-generated The branch stable/13 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=e8dd46ee96c82ed06e5d79f503203a40719fb8d8 commit e8dd46ee96c82ed06e5d79f503203a40719fb8d8 Author: Alan Somers AuthorDate: 2023-10-05 16:13:05 +0000 Commit: Alan Somers CommitDate: 2023-11-30 20:41:53 +0000 fusefs: add more readdir tests for misbehaving servers Inspired by PR 274268 Sponsored by: Axcient (cherry picked from commit 6a773a0582ba936cc19734b21ee5a7bed49cfdec) --- tests/sys/fs/fusefs/readdir.cc | 87 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/tests/sys/fs/fusefs/readdir.cc b/tests/sys/fs/fusefs/readdir.cc index 5fd8f25e8bb7..6b78e3a70697 100644 --- a/tests/sys/fs/fusefs/readdir.cc +++ b/tests/sys/fs/fusefs/readdir.cc @@ -321,6 +321,50 @@ TEST_F(Readdir, nodots) leakdir(dir); } +/* + * FUSE_READDIR returns a path with an embedded NUL. Obviously illegal, but + * nothing bad should happen. + */ +TEST_F(Readdir, nul) +{ + const char FULLPATH[] = "mountpoint/some_dir"; + const char RELPATH[] = "some_dir"; + uint64_t ino = 42; + DIR *dir; + struct dirent *de; + vector ents(1); + vector empty_ents(0); + const char nul[] = "foo\0bar"; + + expect_lookup(RELPATH, ino); + expect_opendir(ino); + ents[0].d_fileno = 4; + ents[0].d_off = 4000; + ents[0].d_namlen = sizeof(nul); + ents[0].d_type = DT_REG; + strncpy(ents[0].d_name, nul, ents[0].d_namlen); + expect_readdir(ino, 0, ents); + expect_readdir(ino, 4000, empty_ents); + + errno = 0; + dir = opendir(FULLPATH); + ASSERT_NE(nullptr, dir) << strerror(errno); + + errno = 0; + de = readdir(dir); + ASSERT_NE(nullptr, de) << strerror(errno); + EXPECT_EQ(4ul, de->d_fileno); + EXPECT_EQ(DT_REG, de->d_type); + EXPECT_EQ(sizeof(nul), de->d_namlen); + EXPECT_EQ(0, strcmp(nul, de->d_name)); + + ASSERT_EQ(nullptr, readdir(dir)); + ASSERT_EQ(0, errno); + + leakdir(dir); +} + + /* telldir(3) and seekdir(3) should work with fuse */ TEST_F(Readdir, seekdir) { @@ -397,6 +441,49 @@ TEST_F(Readdir, seekdir) leakdir(dir); } +/* + * FUSE_READDIR returns a path with an embedded /. Obviously illegal, but + * nothing bad should happen. + */ +TEST_F(Readdir, slash) +{ + const char FULLPATH[] = "mountpoint/some_dir"; + const char RELPATH[] = "some_dir"; + uint64_t ino = 42; + DIR *dir; + struct dirent *de; + vector ents(1); + vector empty_ents(0); + const char foobar[] = "foo/bar"; + + expect_lookup(RELPATH, ino); + expect_opendir(ino); + ents[0].d_fileno = 4; + ents[0].d_off = 4000; + ents[0].d_namlen = sizeof(foobar); + ents[0].d_type = DT_REG; + strncpy(ents[0].d_name, foobar, ents[0].d_namlen); + expect_readdir(ino, 0, ents); + expect_readdir(ino, 4000, empty_ents); + + errno = 0; + dir = opendir(FULLPATH); + ASSERT_NE(nullptr, dir) << strerror(errno); + + errno = 0; + de = readdir(dir); + ASSERT_NE(nullptr, de) << strerror(errno); + EXPECT_EQ(4ul, de->d_fileno); + EXPECT_EQ(DT_REG, de->d_type); + EXPECT_EQ(sizeof(foobar), de->d_namlen); + EXPECT_EQ(0, strcmp(foobar, de->d_name)); + + ASSERT_EQ(nullptr, readdir(dir)); + ASSERT_EQ(0, errno); + + leakdir(dir); +} + TEST_F(Readdir_7_8, nodots) { const char FULLPATH[] = "mountpoint/some_dir";