]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
src: handle NULL options in cgroup_parse_rules_options
authorSam James <sam@gentoo.org>
Fri, 23 May 2025 00:13:51 +0000 (01:13 +0100)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 23 May 2025 15:51:24 +0000 (09:51 -0600)
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 <sam@gentoo.org>
Acked-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 7ff095e72466b4ac194a7da6bd774f9607178f65..44032f502c2e0e6ff9d367a99a86eb62a1511f28 100644 (file)
--- 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);