aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libucl/ucl_msgpack.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-05 20:01:28 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-05 21:17:18 +0100
commit8c18e5c97c77d73eda809ef474354ab0efbaf773 (patch)
treef2d9d9af656f218c72734654408a53bea87a4465 /contrib/libucl/ucl_msgpack.c
parent2e216b23b14ef9485e358989b63aa23dde094f5a (diff)
downloadrspamd-8c18e5c97c77d73eda809ef474354ab0efbaf773.tar.gz
rspamd-8c18e5c97c77d73eda809ef474354ab0efbaf773.zip
[Fix] Slashing: backport chunk logic from libucl
Diffstat (limited to 'contrib/libucl/ucl_msgpack.c')
-rw-r--r--contrib/libucl/ucl_msgpack.c47
1 files changed, 18 insertions, 29 deletions
diff --git a/contrib/libucl/ucl_msgpack.c b/contrib/libucl/ucl_msgpack.c
index bd7c3a1ce..b075c9d7f 100644
--- a/contrib/libucl/ucl_msgpack.c
+++ b/contrib/libucl/ucl_msgpack.c
@@ -434,7 +434,6 @@ static ssize_t ucl_msgpack_parse_ignore (struct ucl_parser *parser,
#define MSGPACK_FLAG_EXT (1 << 3)
#define MSGPACK_FLAG_ASSOC (1 << 4)
#define MSGPACK_FLAG_KEY (1 << 5)
-#define MSGPACK_CONTAINER_BIT (1ULL << 62)
/*
* Search tree packed in array
@@ -768,7 +767,6 @@ ucl_msgpack_get_container (struct ucl_parser *parser,
assert (obj_parser != NULL);
if (obj_parser->flags & MSGPACK_FLAG_CONTAINER) {
- assert ((len & MSGPACK_CONTAINER_BIT) == 0);
/*
* Insert new container to the stack
*/
@@ -779,6 +777,8 @@ ucl_msgpack_get_container (struct ucl_parser *parser,
ucl_create_err (&parser->err, "no memory");
return NULL;
}
+
+ parser->stack->chunk = parser->chunks;
}
else {
stack = calloc (1, sizeof (struct ucl_stack));
@@ -788,11 +788,12 @@ ucl_msgpack_get_container (struct ucl_parser *parser,
return NULL;
}
+ stack->chunk = parser->chunks;
stack->next = parser->stack;
parser->stack = stack;
}
- parser->stack->level = len | MSGPACK_CONTAINER_BIT;
+ parser->stack->e.len = len;
#ifdef MSGPACK_DEBUG_PARSER
stack = parser->stack;
@@ -823,16 +824,11 @@ ucl_msgpack_get_container (struct ucl_parser *parser,
static bool
ucl_msgpack_is_container_finished (struct ucl_stack *container)
{
- uint64_t level;
-
assert (container != NULL);
- if (container->level & MSGPACK_CONTAINER_BIT) {
- level = container->level & ~MSGPACK_CONTAINER_BIT;
- if (level == 0) {
- return true;
- }
+ if (container->e.len == 0) {
+ return true;
}
return false;
@@ -843,12 +839,11 @@ ucl_msgpack_insert_object (struct ucl_parser *parser,
const unsigned char *key,
size_t keylen, ucl_object_t *obj)
{
- uint64_t level;
struct ucl_stack *container;
container = parser->stack;
assert (container != NULL);
- assert (container->level > 0);
+ assert (container->e.len > 0);
assert (obj != NULL);
assert (container->obj != NULL);
@@ -875,10 +870,7 @@ ucl_msgpack_insert_object (struct ucl_parser *parser,
return false;
}
- if (container->level & MSGPACK_CONTAINER_BIT) {
- level = container->level & ~MSGPACK_CONTAINER_BIT;
- container->level = (level - 1) | MSGPACK_CONTAINER_BIT;
- }
+ container->e.len--;
return true;
}
@@ -887,7 +879,7 @@ static struct ucl_stack *
ucl_msgpack_get_next_container (struct ucl_parser *parser)
{
struct ucl_stack *cur = NULL;
- uint64_t level;
+ uint64_t len;
cur = parser->stack;
@@ -895,17 +887,16 @@ ucl_msgpack_get_next_container (struct ucl_parser *parser)
return NULL;
}
- if (cur->level & MSGPACK_CONTAINER_BIT) {
- level = cur->level & ~MSGPACK_CONTAINER_BIT;
+ len = cur->e.len;
- if (level == 0) {
- /* We need to switch to the previous container */
- parser->stack = cur->next;
- parser->cur_obj = cur->obj;
- free (cur);
+ if (len == 0) {
+ /* We need to switch to the previous container */
+ parser->stack = cur->next;
+ parser->cur_obj = cur->obj;
+ free (cur);
#ifdef MSGPACK_DEBUG_PARSER
- cur = parser->stack;
+ cur = parser->stack;
while (cur) {
fprintf(stderr, "-");
cur = cur->next;
@@ -913,8 +904,7 @@ ucl_msgpack_get_next_container (struct ucl_parser *parser)
fprintf(stderr, "-%s -> %d\n", parser->cur_obj->type == UCL_OBJECT ? "object" : "array", (int)parser->cur_obj->len);
#endif
- return ucl_msgpack_get_next_container (parser);
- }
+ return ucl_msgpack_get_next_container (parser);
}
/*
@@ -1311,8 +1301,7 @@ ucl_msgpack_consume (struct ucl_parser *parser)
/* Rewind to the top level container */
ucl_msgpack_get_next_container (parser);
- assert (parser->stack == NULL ||
- (parser->stack->level & MSGPACK_CONTAINER_BIT) == 0);
+ assert (parser->stack == NULL);
return true;
}