diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-02-22 17:16:14 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-02-22 17:16:14 +0000 |
commit | f7758913542fff6447e9641fbfa5c50fb81effab (patch) | |
tree | d21c5482da09861e22d6231ba532ea341a04fcb3 | |
parent | 488e9934253ff342bb4df4e01cea151ac6d2d3d0 (diff) | |
download | rspamd-f7758913542fff6447e9641fbfa5c50fb81effab.tar.gz rspamd-f7758913542fff6447e9641fbfa5c50fb81effab.zip |
Update from the recent libucl
-rw-r--r-- | contrib/libucl/ucl_parser.c | 13 | ||||
-rw-r--r-- | contrib/libucl/ucl_util.c | 70 |
2 files changed, 53 insertions, 30 deletions
diff --git a/contrib/libucl/ucl_parser.c b/contrib/libucl/ucl_parser.c index ac3fe0543..7a935a5c7 100644 --- a/contrib/libucl/ucl_parser.c +++ b/contrib/libucl/ucl_parser.c @@ -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; } diff --git a/contrib/libucl/ucl_util.c b/contrib/libucl/ucl_util.c index f6d83f163..6376d6a42 100644 --- a/contrib/libucl/ucl_util.c +++ b/contrib/libucl/ucl_util.c @@ -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); } |