From 6d526bff1ad6087da6ff08a746aaa6cb55ce3545 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Fri, 21 Nov 2025 18:55:25 +0100 Subject: Check the settings on installation --- FICS/settings.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'FICS/settings.cpp') diff --git a/FICS/settings.cpp b/FICS/settings.cpp index ad1cc02..388a3cc 100644 --- a/FICS/settings.cpp +++ b/FICS/settings.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -85,6 +86,46 @@ is_recognized_setting(const char *name) return false; } +static bool +is_setting_ok(const char *value, enum setting_type type) +{ + if (value == nullptr) + return false; + + switch (type) { + case STYPE_BOOLEAN: { + if (!strings_match(value, "yes") && + !strings_match(value, "YES") && + !strings_match(value, "no") && + !strings_match(value, "NO")) { + warnx("%s: booleans must be either: " + "yes, YES, no or NO", __func__); + return false; + } + break; + } + case STYPE_INTEGER: { + if (!is_numeric(value)) { + warnx("%s: integer not all numeric", __func__); + return false; + } + break; + } + case STYPE_STRING: { + if (strpbrk(value, " \f\n\r\t\v\"") != NULL) { + warnx("%s: illegal characters in string", __func__); + return false; + } + break; + } + default: + errx(1, "%s: statement reached unexpectedly", __func__); + break; + } + + return true; +} + static int install_setting(const char *name, const char *value) { @@ -92,8 +133,12 @@ install_setting(const char *name, const char *value) return EINVAL; for (auto it = settings.begin(); it != settings.end(); ++it) { if (strings_match((*it).name.c_str(), name)) { - (*it).value.assign(value); - return 0; + if (!is_setting_ok(value, (*it).type)) { + return EINVAL; + } else { + (*it).value.assign(value); + return 0; + } } } return ENOENT; -- cgit v1.2.3