]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Update from the recent libucl
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 22 Feb 2016 17:16:14 +0000 (17:16 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 22 Feb 2016 17:16:14 +0000 (17:16 +0000)
contrib/libucl/ucl_parser.c
contrib/libucl/ucl_util.c

index ac3fe054381030abc258063a0d20a8c4c2022e3f..7a935a5c7ca652be15d8507c4ac27a0dd89d1e76 100644 (file)
@@ -2298,7 +2298,7 @@ ucl_state_machine (struct ucl_parser *parser)
                                        ucl_chunk_skipc (chunk, p);
                                }
                                else {
-                                       if (p - c > 0) {
+                                       if (c != NULL && p - c > 0) {
                                                /* We got macro name */
                                                macro_len = (size_t) (p - c);
                                                HASH_FIND (hh, parser->macroes, c, macro_len, macro);
@@ -2351,7 +2351,7 @@ ucl_state_machine (struct ucl_parser *parser)
                                        macro_start, macro_len);
                        parser->state = parser->prev_state;
 
-                       if (macro_escaped == NULL) {
+                       if (macro_escaped == NULL && macro != NULL) {
                                if (macro->is_context) {
                                        ret = macro->h.context_handler (macro_start, macro_len,
                                                        macro_args,
@@ -2363,7 +2363,7 @@ ucl_state_machine (struct ucl_parser *parser)
                                                        macro->ud);
                                }
                        }
-                       else {
+                       else if (macro != NULL) {
                                if (macro->is_context) {
                                        ret = macro->h.context_handler (macro_escaped, macro_len,
                                                        macro_args,
@@ -2377,15 +2377,22 @@ ucl_state_machine (struct ucl_parser *parser)
 
                                UCL_FREE (macro_len + 1, macro_escaped);
                        }
+                       else {
+                               ret = false;
+                               ucl_set_err (parser, UCL_EINTERNAL,
+                                               "internal error: parser has macro undefined", &parser->err);
+                       }
 
                        /*
                         * Chunk can be modified within macro handler
                         */
                        chunk = parser->chunks;
                        p = chunk->pos;
+
                        if (macro_args) {
                                ucl_object_unref (macro_args);
                        }
+
                        if (!ret) {
                                return false;
                        }
index f6d83f163cb9368b78f4f2abf7b39df2dd57656c..6376d6a428ded2cca398c91a4126fc9bbcc18488 100644 (file)
@@ -27,7 +27,7 @@
 #include "ucl_chartable.h"
 #include "kvec.h"
 #include <stdarg.h>
-#include <stdio.h> /* for asprintf */
+#include <stdio.h> /* for snprintf */
 
 #ifndef _WIN32
 #include <glob.h>
@@ -51,6 +51,8 @@ typedef kvec_t(ucl_object_t *) ucl_array_t;
 #endif
 
 #ifdef CURL_FOUND
+/* Seems to be broken */
+#define CURL_DISABLE_TYPECHECK 1
 #include <curl/curl.h>
 #endif
 #ifdef HAVE_FETCH_H
@@ -771,6 +773,8 @@ ucl_fetch_file (const unsigned char *filename, unsigned char **buf, size_t *bufl
                        close (fd);
                        ucl_create_err (err, "cannot mmap file %s: %s",
                                        filename, strerror (errno));
+                       *buf = NULL;
+
                        return false;
                }
                *buflen = st.st_size;
@@ -987,12 +991,12 @@ ucl_include_file_single (const unsigned char *data, size_t len,
                        ucl_create_err (&parser->err, "cannot verify file %s: %s",
                                                        filebuf,
                                                        ERR_error_string (ERR_get_error (), NULL));
-                       if (siglen > 0) {
+                       if (sigbuf) {
                                ucl_munmap (sigbuf, siglen);
                        }
                        return false;
                }
-               if (siglen > 0) {
+               if (sigbuf) {
                        ucl_munmap (sigbuf, siglen);
                }
 #endif
@@ -1059,7 +1063,7 @@ ucl_include_file_single (const unsigned char *data, size_t len,
 
                        if (nest_obj == NULL) {
                                ucl_create_err (&parser->err, "cannot allocate memory for an object");
-                               if (buflen > 0) {
+                               if (buf) {
                                        ucl_munmap (buf, buflen);
                                }
 
@@ -1083,7 +1087,7 @@ ucl_include_file_single (const unsigned char *data, size_t len,
                                nest_obj = ucl_object_new_full (UCL_OBJECT, params->priority);
                                if (nest_obj == NULL) {
                                        ucl_create_err (&parser->err, "cannot allocate memory for an object");
-                                       if (buflen > 0) {
+                                       if (buf) {
                                                ucl_munmap (buf, buflen);
                                        }
 
@@ -1099,7 +1103,7 @@ ucl_include_file_single (const unsigned char *data, size_t len,
                                new_obj = ucl_object_typed_new (UCL_ARRAY);
                                if (new_obj == NULL) {
                                        ucl_create_err (&parser->err, "cannot allocate memory for an object");
-                                       if (buflen > 0) {
+                                       if (buf) {
                                                ucl_munmap (buf, buflen);
                                        }
 
@@ -1114,7 +1118,7 @@ ucl_include_file_single (const unsigned char *data, size_t len,
                                nest_obj = ucl_object_new_full (UCL_OBJECT, params->priority);
                                if (nest_obj == NULL) {
                                        ucl_create_err (&parser->err, "cannot allocate memory for an object");
-                                       if (buflen > 0) {
+                                       if (buf) {
                                                ucl_munmap (buf, buflen);
                                        }
 
@@ -1138,7 +1142,7 @@ ucl_include_file_single (const unsigned char *data, size_t len,
                                ucl_create_err (&parser->err,
                                                "Conflicting type for key: %s",
                                                params->prefix);
-                               if (buflen > 0) {
+                               if (buf) {
                                        ucl_munmap (buf, buflen);
                                }
 
@@ -1149,22 +1153,21 @@ ucl_include_file_single (const unsigned char *data, size_t len,
                 /* Put all of the content of the include inside that object */
                parser->stack->obj->value.ov = container;
 
-               if (nest_obj != NULL) {
-                       st = UCL_ALLOC (sizeof (struct ucl_stack));
-                       if (st == NULL) {
-                               ucl_create_err (&parser->err, "cannot allocate memory for an object");
-                               ucl_object_unref (nest_obj);
-                               if (buflen > 0) {
-                                       ucl_munmap (buf, buflen);
-                               }
+               st = UCL_ALLOC (sizeof (struct ucl_stack));
+               if (st == NULL) {
+                       ucl_create_err (&parser->err, "cannot allocate memory for an object");
+                       ucl_object_unref (nest_obj);
 
-                               return false;
+                       if (buf) {
+                               ucl_munmap (buf, buflen);
                        }
-                       st->obj = nest_obj;
-                       st->level = parser->stack->level;
-                       LL_PREPEND (parser->stack, st);
-                       parser->cur_obj = nest_obj;
+
+                       return false;
                }
+               st->obj = nest_obj;
+               st->level = parser->stack->level;
+               LL_PREPEND (parser->stack, st);
+               parser->cur_obj = nest_obj;
        }
 
        res = ucl_parser_add_chunk_full (parser, buf, buflen, params->priority,
@@ -1631,14 +1634,15 @@ ucl_load_handler (const unsigned char *data, size_t len,
        }
 
        if (len > 0) {
-               asprintf (&load_file, "%.*s", (int)len, data);
-
+               load_file = malloc (len + 1);
                if (!load_file) {
                        ucl_create_err (&parser->err, "cannot allocate memory for suffix");
 
                        return false;
                }
 
+               snprintf (load_file, len + 1, "%.*s", (int)len, data);
+
                if (!ucl_fetch_file (load_file, &buf, &buflen, &parser->err,
                                !try_load)) {
                        free (load_file);
@@ -1653,7 +1657,7 @@ ucl_load_handler (const unsigned char *data, size_t len,
 
                if (old_obj != NULL) {
                        ucl_create_err (&parser->err, "Key %s already exists", prefix);
-                       if (buflen > 0) {
+                       if (buf) {
                                ucl_munmap (buf, buflen);
                        }
 
@@ -1668,12 +1672,24 @@ ucl_load_handler (const unsigned char *data, size_t len,
                        }
                }
                else if (strcasecmp (target, "int") == 0) {
-                       asprintf(&tmp, "%.*s", (int)buflen, buf);
-                       iv = strtoll(tmp, NULL, 10);
+                       tmp = malloc (buflen + 1);
+
+                       if (tmp == NULL) {
+                               ucl_create_err (&parser->err, "Memory allocation failed");
+                               if (buf) {
+                                       ucl_munmap (buf, buflen);
+                               }
+
+                               return false;
+                       }
+
+                       snprintf (tmp, buflen + 1, "%.*s", (int)buflen, buf);
+                       iv = strtoll (tmp, NULL, 10);
                        obj = ucl_object_fromint (iv);
+                       free (tmp);
                }
 
-               if (buflen > 0) {
+               if (buf) {
                        ucl_munmap (buf, buflen);
                }