From 42cee67adb5415abd0206f8ca0780296716588d1 Mon Sep 17 00:00:00 2001 From: Sam James Date: Fri, 23 May 2025 01:13:51 +0100 Subject: [PATCH] src: handle NULL options in cgroup_parse_rules_options We don't want to pass NULL to strtok: ``` [ RUN ] ParseRulesOptionsTest.RulesOptions_NullOptions ==2006496== Conditional jump or move depends on uninitialised value(s) ==2006496== at 0x520D156: strtok_r (strtok_r.c:49) ==2006496== by 0x403FB7E: cgroup_parse_rules_options (api.c:529) ==2006496== by 0x4005F41: ParseRulesOptionsTest_RulesOptions_NullOptions_Test::TestBody() (002-cgroup_parse_rules_options.cpp:89) ==2006496== by 0x4ABA45D: ??? (in /usr/lib64/libgtest.so.1.15.2) ==2006496== by 0x4ABE5AB: ??? (in /usr/lib64/libgtest.so.1.15.2) ==2006496== by 0x4A9D949: testing::TestInfo::Run() (in /usr/lib64/libgtest.so.1.15.2) ==2006496== by 0x4ABF18A: ??? (in /usr/lib64/libgtest.so.1.15.2) ==2006496== by 0x4AB7467: testing::internal::UnitTestImpl::RunAllTests() (in /usr/lib64/libgtest.so.1.15.2) ==2006496== by 0x4AACC46: testing::UnitTest::Run() (in /usr/lib64/libgtest.so.1.15.2) ==2006496== by 0x4002345: UnknownInlinedFun (gtest.h:2334) ==2006496== by 0x4002345: main (gtest.cpp:15) ==2006496== Error: failed to parse options: (null) ``` Signed-off-by: Sam James Acked-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- src/api.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/api.c b/src/api.c index 7ff095e7..44032f50 100644 --- a/src/api.c +++ b/src/api.c @@ -526,6 +526,11 @@ STATIC int cgroup_parse_rules_options(char *options, struct cgroup_rule * const size_t cmp_len; int ret = 0; + if (!options) { + cgroup_err("failed to parse options: (NULL)\n"); + return -EINVAL; + } + stok_buff = strtok(options, ","); if (!stok_buff) { cgroup_err("failed to parse options: %s\n", options); -- 2.47.3