]> 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>
Mon, 17 Jun 2019 20:29:12 +0000 (22:29 +0200)
Based on a suggestion by Henri Houder.

src/conf.c
unittest/test_conf.c

index 93f62a9f31ae84d07fc1a7ce4d4c2c8bd1059431..64bccf5cb1df75581058641d9f94043a5adc84ae 100644 (file)
@@ -299,6 +299,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 393246b15e3b21928b1feba50bc9a9f82f6e9568..e7b0f753c795b67e15e515c76df9c62378cb2ce6 100644 (file)
@@ -366,11 +366,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)