]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Do not allow syntax errors in include files...
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 12 Nov 2018 16:37:25 +0000 (16:37 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 12 Nov 2018 16:37:25 +0000 (16:37 +0000)
contrib/libucl/ucl_util.c

index b7b4712050f4d92d5a5e442d33310599f5ec011f..279e9f3c669c44a25746b3dd372aee12254e2aee 100644 (file)
@@ -1333,57 +1333,49 @@ ucl_include_file_single (const unsigned char *data, size_t len,
        res = ucl_parser_add_chunk_full (parser, buf, buflen, params->priority,
                        params->strat, params->parse_type);
 
-       if (!res) {
-               if (!params->must_exist) {
-                       /* Free error */
-                       utstring_free (parser->err);
-                       parser->err = NULL;
-                       res = true;
+       if (res) {
+               /* Stop nesting the include, take 1 level off the stack */
+               if (params->prefix != NULL && nest_obj != NULL) {
+                       parser->stack = st->next;
+                       UCL_FREE (sizeof (struct ucl_stack), st);
                }
-       }
-
-       /* Stop nesting the include, take 1 level off the stack */
-       if (params->prefix != NULL && nest_obj != NULL) {
-               parser->stack = st->next;
-               UCL_FREE (sizeof (struct ucl_stack), st);
-       }
 
-       /* Remove chunk from the stack */
-       chunk = parser->chunks;
-       if (chunk != NULL) {
-               parser->chunks = chunk->next;
-               ucl_chunk_free (chunk);
-               parser->recursion --;
-       }
+               /* Remove chunk from the stack */
+               chunk = parser->chunks;
+               if (chunk != NULL) {
+                       parser->chunks = chunk->next;
+                       ucl_chunk_free (chunk);
+                       parser->recursion--;
+               }
 
-       /* Restore old file vars */
-       if (parser->cur_file) {
-               free (parser->cur_file);
-       }
+               /* Restore old file vars */
+               if (parser->cur_file) {
+                       free (parser->cur_file);
+               }
 
-       parser->cur_file = old_curfile;
-       DL_FOREACH_SAFE (parser->variables, cur_var, tmp_var) {
-               if (strcmp (cur_var->var, "CURDIR") == 0 && old_curdir) {
-                       DL_DELETE (parser->variables, cur_var);
-                       free (cur_var->var);
-                       free (cur_var->value);
-                       UCL_FREE (sizeof (struct ucl_variable), cur_var);
+               parser->cur_file = old_curfile;
+               DL_FOREACH_SAFE (parser->variables, cur_var, tmp_var) {
+                       if (strcmp (cur_var->var, "CURDIR") == 0 && old_curdir) {
+                               DL_DELETE (parser->variables, cur_var);
+                               free (cur_var->var);
+                               free (cur_var->value);
+                               UCL_FREE (sizeof (struct ucl_variable), cur_var);
+                       } else if (strcmp (cur_var->var, "FILENAME") == 0 && old_filename) {
+                               DL_DELETE (parser->variables, cur_var);
+                               free (cur_var->var);
+                               free (cur_var->value);
+                               UCL_FREE (sizeof (struct ucl_variable), cur_var);
+                       }
                }
-               else if (strcmp (cur_var->var, "FILENAME") == 0 && old_filename) {
-                       DL_DELETE (parser->variables, cur_var);
-                       free (cur_var->var);
-                       free (cur_var->value);
-                       UCL_FREE (sizeof (struct ucl_variable), cur_var);
+               if (old_filename) {
+                       DL_APPEND (parser->variables, old_filename);
+               }
+               if (old_curdir) {
+                       DL_APPEND (parser->variables, old_curdir);
                }
-       }
-       if (old_filename) {
-               DL_APPEND (parser->variables, old_filename);
-       }
-       if (old_curdir) {
-               DL_APPEND (parser->variables, old_curdir);
-       }
 
-       parser->state = prev_state;
+               parser->state = prev_state;
+       }
 
        if (buflen > 0) {
                ucl_munmap (buf, buflen);