X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=util.c;h=12aec9bd3596103741b564198cd969e97207a165;hp=f16a378b307ae5468a332bd0427828acec044ff8;hb=950437eecd6048dd29eb3e11f4343372b2ddce60;hpb=b342283d2dda28083322e99ffae874ba92839c74 diff --git a/util.c b/util.c index f16a378..12aec9b 100644 --- a/util.c +++ b/util.c @@ -69,18 +69,22 @@ __private char *uci_strdup(struct uci_context *ctx, const char *str) * for names, only alphanum and _ is allowed (shell compatibility) * for types, we allow more characters */ -__private bool uci_validate_str(const char *str, bool name) +__private bool uci_validate_str(const char *str, bool name, bool package) { if (!*str) return false; - while (*str) { + for (; *str; str++) { unsigned char c = *str; - if (!isalnum(c) && c != '_') { - if (name || (c < 33) || (c > 126)) - return false; - } - str++; + + if (isalnum(c) || c == '_') + continue; + + if (c == '-' && package) + continue; + + if (name || (c < 33) || (c > 126)) + return false; } return true; }