common/json.c: Have json_add_literal *use* len argument.

The current `json_add_literal` does not use its `len` argument, at all:

09c2fef4a4/common/json.c (L1076-L1083)

Which is something of a WTF, why even require the `len` argument if it
is not even used in the function?
This would have been acceptable if it were a callback and the
callback-requiring function passed it in always, but this function is
not intended to be a callback but instead to be called directly.

Existing callers always pass in `strlen(literal)`, so this bug was not
noticed before:

09c2fef4a4/lightningd/jsonrpc.c (L511)
09c2fef4a4/lightningd/jsonrpc.c (L583)
09c2fef4a4/lightningd/options.c (L1408-L1409)
This commit is contained in:
ZmnSCPxj jxPCSnmZ 2021-10-05 13:46:37 +08:00 committed by Christian Decker
parent a418cf5654
commit 20fe5c6ab1

View file

@ -1077,9 +1077,9 @@ void json_add_literal(struct json_stream *result, const char *fieldname,
const char *literal, int len)
{
/* Literal may contain quotes, so bypass normal checks */
char *dest = json_member_direct(result, fieldname, strlen(literal));
char *dest = json_member_direct(result, fieldname, len);
if (dest)
memcpy(dest, literal, strlen(literal));
memcpy(dest, literal, len);
}
void json_add_stringn(struct json_stream *result, const char *fieldname,