]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
integritysetup: Check args to prevent assert
authorTony Asleson <tasleson@redhat.com>
Wed, 27 Oct 2021 17:00:59 +0000 (12:00 -0500)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 28 Oct 2021 11:54:41 +0000 (20:54 +0900)
The utility function parse_integrity_options is used to both validate
integritytab options or validate and return values.  In the case where
we are validating only and we have specific value options we will
assert.

src/integritysetup/integrity-util.c

index 5970a136b8c5f138231fb8af7cb9dfd39ab54545..c2d2f950de56d05848ea09e1506b2b4381accf73 100644 (file)
@@ -48,16 +48,20 @@ int parse_integrity_options(
                         if (ret_commit_time)
                                 *ret_commit_time = tmp_commit_time;
                 } else if ((val = startswith(word, "data-device="))) {
-                        r = free_and_strdup(ret_data_device, val);
-                        if (r < 0)
-                                return log_oom();
+                        if (ret_data_device) {
+                                r = free_and_strdup(ret_data_device, val);
+                                if (r < 0)
+                                        return log_oom();
+                        }
                 } else if ((val = startswith(word, "integrity-algorithm="))) {
-                        r = free_and_strdup(ret_integrity_alg, val);
-                        if (r < 0)
-                                return log_oom();
-                        r = supported_integrity_algorithm(*ret_integrity_alg);
+                        r = supported_integrity_algorithm(val);
                         if (r < 0)
                                 return r;
+                        if (ret_integrity_alg) {
+                                r = free_and_strdup(ret_integrity_alg, val);
+                                if (r < 0)
+                                        return log_oom();
+                        }
                 } else
                         log_warning("Encountered unknown option '%s', ignoring.", word);
         }