Skip to content

Commit 0681609

Browse files
committed
common/json_parse_simple: drop redundant and wrong json_str_to_u64()
The json_str_to_u64() function contains incorrect logic. It chops one character off of the beginning and end of the JSMN token and then parses the remainder as a u64, but JSMN_STRING tokens already do not include the enclosing quotation marks, so json_str_to_u64() would actually parse the JSON string "1234" into the integer 23. Oops! Also note that it would simply fail on all input strings shorter than two characters since tok->end would wind up *before* tok->start. Just drop the function entirely. It was only used in one place, and that place explicitly doesn't care whether its input is a JSON number or a numeric string, and it was already calling json_to_u64() as an alternative, and that function already accepts both JSON strings and JSON numbers as input, so the call to json_str_to_u64() would have been entirely redundant if it had been correct. Changelog-Fixed: The `keysend` command no longer corrupts the type numbers of extra TLVs when they are specified as numeric strings longer than 2 digits.
1 parent 2b8b709 commit 0681609

File tree

3 files changed

+1
-19
lines changed

3 files changed

+1
-19
lines changed

common/json_param.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,7 @@ struct command_result *param_extra_tlvs(struct command *cmd, const char *name,
975975
/* Accept either bare ints as keys (not spec
976976
* compliant, but simpler), or ints in strings, which
977977
* are JSON spec compliant. */
978-
if (!(json_str_to_u64(buffer, curr, &f->numtype) ||
979-
json_to_u64(buffer, curr, &f->numtype))) {
978+
if (!json_to_u64(buffer, curr, &f->numtype)) {
980979
return command_fail(
981980
cmd, JSONRPC2_INVALID_PARAMS,
982981
"\"%s\" is not a valid numeric TLV type.",

common/json_parse_simple.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,6 @@ bool json_to_s64(const char *buffer, const jsmntok_t *tok, s64 *num)
112112
return true;
113113
}
114114

115-
bool json_str_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num)
116-
{
117-
jsmntok_t temp;
118-
if (tok->type != JSMN_STRING)
119-
return false;
120-
121-
temp = *tok;
122-
temp.start += 1;
123-
temp.end -= 1;
124-
125-
return json_to_u64(buffer, &temp, num);
126-
}
127-
128115
bool json_to_double(const char *buffer, const jsmntok_t *tok, double *num)
129116
{
130117
char *end;

common/json_parse_simple.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ bool json_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num);
3838
/* Extract signed 64 bit integer from this (may be a string, or a number literal) */
3939
bool json_to_s64(const char *buffer, const jsmntok_t *tok, s64 *num);
4040

41-
/* Extract number from string. The number must be the entirety of the
42-
* string between the '"' */
43-
bool json_str_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num);
44-
4541
/* Extract number from this (may be a string, or a number literal) */
4642
bool json_to_u32(const char *buffer, const jsmntok_t *tok, u32 *num);
4743

0 commit comments

Comments
 (0)