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

struct-lejp: handle no path match

For some patterns of JSON we return to parse at the outermost level and
meet a situation path_match is 0.  In some places we're looking at things
from perspective of path_match - 1... that does not seem to cause trouble on
x86_64 but can on aarch64, which is how it got noticed.

This logically protects those accesses by checking !!path_match.
This commit is contained in:
Andy Green 2020-07-09 19:28:23 +01:00
parent 1ae6ce37d3
commit 2b20f62e55

View file

@ -106,8 +106,8 @@ matched:
a->map_st[ctx->pst_sp] = map->child_map;
a->map_entries_st[ctx->pst_sp] = map->child_map_size;
lwsl_notice("%s: child map ofs_clist %d\n", __func__,
(int)a->map_st[ctx->pst_sp]->ofs_clist);
// lwsl_notice("%s: child map ofs_clist %d\n", __func__,
// (int)a->map_st[ctx->pst_sp]->ofs_clist);
if (imp)
return cb(ctx, reason);
@ -153,10 +153,10 @@ lws_struct_default_lejp_cb(struct lejp_ctx *ctx, char reason)
return 0;
}
if (reason == LEJPCB_ARRAY_START) {
if (reason == LEJPCB_ARRAY_START && ctx->path_match) {
map = &args->map_st[ctx->pst_sp][ctx->path_match - 1];
if (map->type == LSMT_LIST)
if (map->type == LSMT_LIST && ctx->path[0])
lws_struct_lejp_push(ctx, args, map, NULL);
return 0;
@ -165,7 +165,7 @@ lws_struct_default_lejp_cb(struct lejp_ctx *ctx, char reason)
if (ctx->pst_sp)
pmap = &args->map_st[ctx->pst_sp - 1]
[ctx->pst[ctx->pst_sp - 1].path_match - 1];
map = &args->map_st[ctx->pst_sp][ctx->path_match - 1];
map = &args->map_st[ctx->pst_sp][ctx->path_match ? ctx->path_match - 1 : 0];
n = args->map_entries_st[ctx->pst_sp];
if (reason == LEJPCB_OBJECT_START) {