mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
lws_json_simple: allow running into end
If the arg is unquoted, it's normal to run into the end finding its extent.
This commit is contained in:
parent
865f2e4a6c
commit
1db26f0c64
2 changed files with 22 additions and 4 deletions
|
@ -405,7 +405,7 @@ lws_json_simple_find(const char *buf, size_t len, const char *name, size_t *alen
|
|||
while (np < end && (*np == ' ' || *np == '\t'))
|
||||
np++;
|
||||
|
||||
if (np >= end - 1)
|
||||
if (np >= end)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
|
@ -432,9 +432,6 @@ lws_json_simple_find(const char *buf, size_t len, const char *name, size_t *alen
|
|||
np++;
|
||||
}
|
||||
|
||||
if (np == end)
|
||||
return NULL;
|
||||
|
||||
*alen = lws_ptr_diff(np, as);
|
||||
|
||||
return as;
|
||||
|
|
|
@ -184,6 +184,27 @@ int main(int argc, const char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
const char *cs;
|
||||
size_t cslen;
|
||||
cs = lws_json_simple_find("{\"blah\":123,\"ext\":{\"authorized\":1}}", 35,
|
||||
"\"ext\":", &cslen);
|
||||
if (!cs) {
|
||||
lwsl_err("%s: simple_find failed\n", __func__);
|
||||
e++;
|
||||
} else {
|
||||
if (lws_json_simple_strcmp(cs, cslen,
|
||||
"\"authorized\":", "1"))
|
||||
e++;
|
||||
}
|
||||
cs = lws_json_simple_find("{\"blah\":123,\"auth_user\":\"andy@warmcat.com\",\"thing\":\"yeah\"}", 57,
|
||||
"\"auth_user\":", &cslen);
|
||||
if (cslen != 16) {
|
||||
lwsl_err("%s: wrong string len %d isolated\n", __func__, (int)cslen);
|
||||
e++;
|
||||
}
|
||||
}
|
||||
|
||||
if (e)
|
||||
goto bail;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue