From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794591626; b=Urn7quZkudfT96BqyMXtPHD5yUJrznY+akmPA07hsoMyp++f/OSd07E+JBeC0eul7DGH J5rqhYmpBcvvzusUIqoHJGp2NVd/UOwgQYdxnJN88C74HqXhEW626kFT/4cTYdvMsMCBo Nf7TEj+6C0KNAm6LCKCeEWQmHIH5K9FQmVQyfFxfKcpcATI04jCO1ax+7TKhngXM5HpNW SVYV9q4p9tvSfi9kXvod+C8tbJb3MpSZ5R3kQmsh09+bgcCuOMDjtaGLZVENYQjtv8rxF /GbC6C2Rz4BnDSArX6HJv/QkASUc3gMup3dICQjiaYQSwCJw8RTNVQpGKxmOqQxGNzA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794591626; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=zsyvCkxY2obpmbx35F1gyYIwem2VdGrlGbN3rkWIGY0=; b=zPL5D0qv//1IhFKjR4yREji7HIriOtT5vOemqOtiPwCA9AS9i/5n5j6YRj/GGMoMI3ua E02BbNV92fI+/qCyEtlwiPzf7Xw/DyqH/1QjPW1C33SM3n4C61iTIGu3+sfwD5A8uZaZ9 fzJU7KliDGEKdjujfV+jzMrzuSPEC9k3ZtdyyuBa56yiWU+Y/8cRM6HHJMwSINr80NZWi C/IBlNO95b413aeCsW8lC67KLe7V0USgtAKOhCcFbX8LBBs2EEZE6oYH6qZZ2CC0mcQWO WGM0LwjaRK8/IbduBgKGN/iCneo8j9wuZY0DQ4X7sXNS+NmPCIyPWaVqwaX3VS8TeGw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=mXS8zEuY; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BB94606E654; Fri, 13 Nov 2026 17:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=mXS8zEuY Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E9871F000C4; Fri, 13 Nov 2026 17:40:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794591626; bh=zsyvCkxY2obpmbx35F1gyYIwem2VdGrlGbN3rkWIGY0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mXS8zEuYCQAKGAPVhcYpl3n2Po2fyCh64urjf/9JjHpIRDpLoBuj08d7YX6fKD/m9 x6NefgprbhemV/3B5Ok7tFkuVcgJlCbQWp8rI3cVPRDG7BuuaenNgByFfk1kcnUHSu i2/RQ6sOrcZqlfEa2BRlWi4/cJTWdpcMeCZk9Gs4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shuvam Pandey , Andy Shevchenko , Neel Natu , Dmitry Antipov , "Darrick J. Wong" , Kees Cook , Andrew Morton , Sasha Levin Subject: [PATCH 6.12 666/670] lib/tests: extend cmdline KUnit with next_arg() tests Date: Fri, 13 Nov 2026 10:53:50 -0500 Message-ID: <20261113153834.461901438@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153811.177190860@linuxfoundation.org> References: <20261113153811.177190860@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shuvam Pandey [ Upstream commit dcc8a57815534e3844f342b28ecfb6e626a816a0 ] The cmdline KUnit suite covers get_option() and get_options(), but it does not exercise next_arg(). Extend the suite with one test for a quoted value containing spaces and one regression test for a bare quote token after a normal parameter. The regression test covers the bare quote token path fixed by commit 9847f21225c4 ("lib/cmdline: avoid page fault in next_arg"). [shuvampandey1@gmail.com: extend cmdline next_arg() coverage with mixed tokens] Link: https://lore.kernel.org/20260316211249.88601-1-shuvampandey1@gmail.com Link: https://lore.kernel.org/20260316101227.15807-1-shuvampandey1@gmail.com Signed-off-by: Shuvam Pandey Reviewed-by: Andy Shevchenko Cc: Neel Natu Cc: Dmitry Antipov Cc: "Darrick J. Wong" Cc: Kees Cook Signed-off-by: Andrew Morton Stable-dep-of: 5d72266218b1 ("lib/cmdline: fix get_options() count and overflow with large ranges") Signed-off-by: Sasha Levin --- lib/cmdline_kunit.c | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/lib/cmdline_kunit.c b/lib/cmdline_kunit.c index c1602f797637b..af44ae9e92c3e 100644 --- a/lib/cmdline_kunit.c +++ b/lib/cmdline_kunit.c @@ -139,11 +139,73 @@ static void cmdline_test_range(struct kunit *test) } while (++i < ARRAY_SIZE(cmdline_test_range_strings)); } +static void cmdline_test_next_arg_quoted_value(struct kunit *test) +{ + char in[] = "foo=\"bar baz\" qux=1"; + char *next, *param, *val; + + next = next_arg(in, ¶m, &val); + KUNIT_EXPECT_STREQ(test, param, "foo"); + KUNIT_ASSERT_NOT_NULL(test, val); + KUNIT_EXPECT_STREQ(test, val, "bar baz"); + KUNIT_EXPECT_STREQ(test, next, "qux=1"); + + next = next_arg(next, ¶m, &val); + KUNIT_EXPECT_STREQ(test, param, "qux"); + KUNIT_ASSERT_NOT_NULL(test, val); + KUNIT_EXPECT_STREQ(test, val, "1"); + KUNIT_EXPECT_STREQ(test, next, ""); +} + +static void cmdline_test_next_arg_bare_quote_regression(struct kunit *test) +{ + char in[] = "foo=bar \""; + char *next, *param, *val; + + next = next_arg(in, ¶m, &val); + KUNIT_EXPECT_STREQ(test, param, "foo"); + KUNIT_ASSERT_NOT_NULL(test, val); + KUNIT_EXPECT_STREQ(test, val, "bar"); + KUNIT_EXPECT_STREQ(test, next, "\""); + + /* This hits the i == 0 quoted-token case fixed by 9847f21225c4. */ + next = next_arg(next, ¶m, &val); + KUNIT_EXPECT_STREQ(test, param, ""); + KUNIT_EXPECT_PTR_EQ(test, val, NULL); + KUNIT_EXPECT_STREQ(test, next, ""); +} + +static void cmdline_test_next_arg_mixed_tokens(struct kunit *test) +{ + char in[] = "bbb= jjj kkk=\"a=b\""; + char *next, *param, *val; + + next = next_arg(in, ¶m, &val); + KUNIT_EXPECT_STREQ(test, param, "bbb"); + KUNIT_ASSERT_NOT_NULL(test, val); + KUNIT_EXPECT_STREQ(test, val, ""); + KUNIT_EXPECT_STREQ(test, next, "jjj kkk=\"a=b\""); + + next = next_arg(next, ¶m, &val); + KUNIT_EXPECT_STREQ(test, param, "jjj"); + KUNIT_EXPECT_NULL(test, val); + KUNIT_EXPECT_STREQ(test, next, "kkk=\"a=b\""); + + next = next_arg(next, ¶m, &val); + KUNIT_EXPECT_STREQ(test, param, "kkk"); + KUNIT_ASSERT_NOT_NULL(test, val); + KUNIT_EXPECT_STREQ(test, val, "a=b"); + KUNIT_EXPECT_STREQ(test, next, ""); +} + static struct kunit_case cmdline_test_cases[] = { KUNIT_CASE(cmdline_test_noint), KUNIT_CASE(cmdline_test_lead_int), KUNIT_CASE(cmdline_test_tail_int), KUNIT_CASE(cmdline_test_range), + KUNIT_CASE(cmdline_test_next_arg_quoted_value), + KUNIT_CASE(cmdline_test_next_arg_bare_quote_regression), + KUNIT_CASE(cmdline_test_next_arg_mixed_tokens), {} }; -- 2.53.0