X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=util.c;h=12aec9bd3596103741b564198cd969e97207a165;hp=09f18171cede5399a020610050b9f202dd476ee7;hb=5ad59ad412a784c5c478e31d1701ce39568ffd58;hpb=f8f9decc545a7e9fc7b4c92534f4bf2b1db4a4f0 diff --git a/util.c b/util.c index 09f1817..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; } @@ -89,12 +93,10 @@ bool uci_validate_text(const char *str) { while (*str) { unsigned char c = *str; - if (((c < 32) && - (c != '\t') && - (c != '\n') && - (c != '\r'))) { + + if (c < 32 && c != '\t' && c != '\n' && c != '\r') return false; - } + str++; } return true;