From ea985c458569c739cd13f944162fc1761516f256 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Mon, 17 Jun 2019 22:29:12 +0200 Subject: [PATCH] =?utf8?q?Verify=20value=20in=20=E2=80=9Cccache=20-o=20key?= =?utf8?q?=3Dvalue=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Based on a suggestion by Henri Houder. --- src/conf.c | 6 ++++++ unittest/test_conf.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) 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) -- 2.47.2