improve validation, accept more characters in the section type
[project/uci.git] / file.c
diff --git a/file.c b/file.c
index d81bbe8..c0141ac 100644 (file)
--- a/file.c
+++ b/file.c
@@ -342,7 +342,9 @@ static void uci_parse_config(struct uci_context *ctx, char **str)
        /* command string null-terminated by strtok */
        *str += strlen(*str) + 1;
 
-       type = next_arg(ctx, str, true, true);
+       type = next_arg(ctx, str, true, false);
+       if (!uci_validate_str(type, false))
+               uci_parse_error(ctx, type, "invalid character in field");
        name = next_arg(ctx, str, false, true);
        assert_eol(ctx, str);
 
@@ -373,7 +375,7 @@ static void uci_parse_option(struct uci_context *ctx, char **str)
        *str += strlen(*str) + 1;
 
        name = next_arg(ctx, str, true, true);
-       value = next_arg(ctx, str, true, false);
+       value = next_arg(ctx, str, false, false);
        assert_eol(ctx, str);
 
        if (pctx->merge) {
@@ -521,8 +523,8 @@ int uci_import(struct uci_context *ctx, FILE *stream, const char *name, struct u
        /* make sure no memory from previous parse attempts is leaked */
        uci_file_cleanup(ctx);
 
-       pctx = (struct uci_parse_context *) uci_malloc(ctx, sizeof(struct uci_parse_context));
-       ctx->pctx = pctx;
+       uci_alloc_parse_context(ctx);
+       pctx = ctx->pctx;
        pctx->file = stream;
        if (*package && single) {
                pctx->package = *package;
@@ -673,7 +675,7 @@ int uci_commit(struct uci_context *ctx, struct uci_package **package, bool overw
                        /* freed together with the uci_package */
                        path = NULL;
 
-                       /* check for updated history, just in case */
+                       /* check for updated history, flush */
                        uci_load_history(ctx, p, true);
                } else {
                        /* flush history */