Skip to content

Commit 71ddba2

Browse files
whitslackrustyrussell
authored andcommitted
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 2e2a085 commit 71ddba2

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
@@ -986,8 +986,7 @@ struct command_result *param_extra_tlvs(struct command *cmd, const char *name,
986986
/* Accept either bare ints as keys (not spec
987987
* compliant, but simpler), or ints in strings, which
988988
* are JSON spec compliant. */
989-
if (!(json_str_to_u64(buffer, curr, &f->numtype) ||
990-
json_to_u64(buffer, curr, &f->numtype))) {
989+
if (!json_to_u64(buffer, curr, &f->numtype)) {
991990
return command_fail(
992991
cmd, JSONRPC2_INVALID_PARAMS,
993992
"\"%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
@@ -109,19 +109,6 @@ bool json_to_s64(const char *buffer, const jsmntok_t *tok, s64 *num)
109109
return true;
110110
}
111111

112-
bool json_str_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num)
113-
{
114-
jsmntok_t temp;
115-
if (tok->type != JSMN_STRING)
116-
return false;
117-
118-
temp = *tok;
119-
temp.start += 1;
120-
temp.end -= 1;
121-
122-
return json_to_u64(buffer, &temp, num);
123-
}
124-
125112
bool json_to_double(const char *buffer, const jsmntok_t *tok, double *num)
126113
{
127114
char *end;

common/json_parse_simple.h

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

45-
/* Extract number from string. The number must be the entirety of the
46-
* string between the '"' */
47-
bool json_str_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num);
48-
4945
/* Extract number from this (may be a string, or a number literal) */
5046
bool json_to_u32(const char *buffer, const jsmntok_t *tok, u32 *num);
5147

0 commit comments

Comments
 (0)