]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Verify value in “ccache -o key=value”
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 17 Jun 2019 20:29:12 +0000 (22:29 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 18 Jul 2019 20:05:49 +0000 (22:05 +0200)
Based on a suggestion by Henri Houder.

src/conf.c
unittest/test_conf.c

index 30aa4a40fcb161bf642a56bc1a9b8f43f024ad1a..9ddd14c027a925d85a84db9e565a47cc3cd4ccd8 100644 (file)
@@ -300,6 +300,12 @@ conf_set_value_in_file(const char *path, const char *key, const char *value,
                return false;
        }
 
+       char dummy[8] = {0}; // The maximum entry size in struct conf.
+       if (!item->parser(value, (void *)dummy, errmsg)
+           || (item->verifier && !item->verifier(value, errmsg))) {
+               return false;
+       }
+
        FILE *infile = fopen(path, "r");
        if (!infile) {
                *errmsg = format("%s: %s", path, strerror(errno));
index 9ef6708574256294e625b8d2f1260f73b12c4c3d..886bd28537f0d333285c531af351a468b3595d37 100644 (file)
@@ -369,11 +369,11 @@ TEST(conf_set_new_value)
        char *data;
 
        create_file("ccache.conf", "path = vanilla\n");
-       CHECKM(conf_set_value_in_file("ccache.conf", "stats", "chocolate", &errmsg),
+       CHECKM(conf_set_value_in_file("ccache.conf", "compiler", "chocolate", &errmsg),
               errmsg);
        data = read_text_file("ccache.conf", 0);
        CHECK(data);
-       CHECK_STR_EQ_FREE2("path = vanilla\nstats = chocolate\n", data);
+       CHECK_STR_EQ_FREE2("path = vanilla\ncompiler = chocolate\n", data);
 }
 
 TEST(conf_set_existing_value)