From: Joel Rosdahl Date: Mon, 17 Jun 2019 20:29:12 +0000 (+0200) Subject: Verify value in “ccache -o key=value” X-Git-Tag: v3.7.2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ea985c458569c739cd13f944162fc1761516f256;p=thirdparty%2Fccache.git Verify value in “ccache -o key=value” Based on a suggestion by Henri Houder. --- diff --git a/src/conf.c b/src/conf.c index 30aa4a40f..9ddd14c02 100644 --- a/src/conf.c +++ b/src/conf.c @@ -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)); diff --git a/unittest/test_conf.c b/unittest/test_conf.c index 9ef670857..886bd2853 100644 --- a/unittest/test_conf.c +++ b/unittest/test_conf.c @@ -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)