1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-30 00:00:16 +01:00

lejp: make sure child object close is not mistaken for parent

This commit is contained in:
Andy Green 2019-04-21 20:07:07 +01:00
parent 80135635bb
commit 0405c0c878
3 changed files with 26 additions and 9 deletions

View file

@ -106,7 +106,7 @@ enum lejp_callbacks {
LEJPCB_ARRAY_END = 15,
LEJPCB_OBJECT_START = 16,
LEJPCB_OBJECT_END = 17
LEJPCB_OBJECT_END = 17,
};
/**

View file

@ -688,22 +688,28 @@ lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len)
/* done, return unused amount */
return len;
}
/* pop */
ctx->sp--;
if (ctx->sp) {
ctx->pst[ctx->pst_sp].ppos = ctx->st[ctx->sp - 1].p;
ctx->ipos = ctx->st[ctx->sp - 1].i;
ctx->pst[ctx->pst_sp].ppos =
ctx->st[ctx->sp].p;
ctx->ipos = ctx->st[ctx->sp].i;
}
ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0';
if (ctx->path_match &&
ctx->pst[ctx->pst_sp].ppos <= ctx->path_match_len)
ctx->pst[ctx->pst_sp].ppos <=
ctx->path_match_len)
/*
* we shrank the path to be
* smaller than the matching point
*/
ctx->path_match = 0;
lejp_check_path_match(ctx);
if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_OBJECT_END)) {
if (ctx->pst[ctx->pst_sp].callback(ctx,
LEJPCB_OBJECT_END)) {
ret = LEJP_REJECT_CALLBACK;
goto reject;
}
@ -757,7 +763,8 @@ emit_string_char:
add_stack_level:
/* push on to the object stack */
if (ctx->pst[ctx->pst_sp].ppos && ctx->st[ctx->sp].s != LEJP_MP_COMMA_OR_END &&
if (ctx->pst[ctx->pst_sp].ppos &&
ctx->st[ctx->sp].s != LEJP_MP_COMMA_OR_END &&
ctx->st[ctx->sp].s != LEJP_MP_ARRAY_END)
ctx->path[ctx->pst[ctx->pst_sp].ppos++] = '.';

View file

@ -42,6 +42,7 @@ static const char * const reason_names[] = {
"LEJPCB_ARRAY_END",
"LEJPCB_OBJECT_START",
"LEJPCB_OBJECT_END",
"LEJPCB_OBJECT_END_PRE",
};
static const char * const tok[] = {
@ -52,6 +53,11 @@ static signed char
cb(struct lejp_ctx *ctx, char reason)
{
char buf[1024], *p = buf, *end = &buf[sizeof(buf)];
int n;
for (n = 0; n < ctx->sp; n++)
*p++ = ' ';
*p = '\0';
if (reason & LEJP_FLAG_CB_IS_VALUE) {
p += lws_snprintf(p, p - end, " value '%s' ", ctx->buf);
@ -73,13 +79,17 @@ cb(struct lejp_ctx *ctx, char reason)
switch (reason) {
case LEJPCB_COMPLETE:
lwsl_notice("Parsing Completed (LEJPCB_COMPLETE)\n");
lwsl_notice("%sParsing Completed (LEJPCB_COMPLETE)\n", buf);
break;
case LEJPCB_PAIR_NAME:
lwsl_notice("path: '%s' (LEJPCB_PAIR_NAME)\n", ctx->path);
lwsl_notice("%spath: '%s' (LEJPCB_PAIR_NAME)\n", buf, ctx->path);
break;
}
lwsl_notice("%s%s: path %s match %d statckp %d\r\n", buf, reason_names[(unsigned int)
(reason) & (LEJP_FLAG_CB_IS_VALUE - 1)], ctx->path,
ctx->path_match, ctx->pst[ctx->pst_sp].ppos);
return 0;
}