mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
json: allow strange characters through our JSON parser.
Fixes: #387 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
9f7d4312ff
commit
ed9093fcbd
@ -225,22 +225,11 @@ const jsmntok_t *json_delve(const char *buffer,
|
||||
return tok;
|
||||
}
|
||||
|
||||
static bool strange_chars(const char *str, size_t len)
|
||||
{
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (!cisprint(str[i]) || str[i] == '"' || str[i] == '\\')
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
jsmntok_t *json_parse_input(const char *input, int len, bool *valid)
|
||||
{
|
||||
jsmn_parser parser;
|
||||
jsmntok_t *toks;
|
||||
int ret;
|
||||
size_t i;
|
||||
|
||||
toks = tal_arr(input, jsmntok_t, 10);
|
||||
|
||||
@ -267,19 +256,6 @@ again:
|
||||
toks[ret].type = -1;
|
||||
toks[ret].start = toks[ret].end = toks[ret].size = 0;
|
||||
|
||||
/* Don't allow tokens to contain weird characters (outside toks ok). */
|
||||
for (i = 0; i < ret; i++) {
|
||||
if (toks[i].type != JSMN_STRING
|
||||
&& toks[i].type != JSMN_PRIMITIVE)
|
||||
continue;
|
||||
|
||||
if (strange_chars(input + toks[i].start,
|
||||
toks[i].end - toks[i].start)) {
|
||||
*valid = false;
|
||||
return tal_free(toks);
|
||||
}
|
||||
}
|
||||
|
||||
return toks;
|
||||
}
|
||||
|
||||
|
@ -456,7 +456,6 @@ class LightningDTests(BaseLightningDTests):
|
||||
# separator, and not for example "lnbcrt1m1....".
|
||||
assert b11.count('1') == 1
|
||||
|
||||
@unittest.expectedFailure
|
||||
def test_invoice_weirdstring(self):
|
||||
l1 = self.node_factory.get_node()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user