Skip to content

common/json_parse_simple: drop redundant and wrong json_str_to_u64() #8413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

whitslack
Copy link
Collaborator

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.

Checklist

Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:

  • The changelog has been updated in the relevant commit(s) according to the guidelines.
  • Tests have been added or modified to reflect the changes. I'm not confident that I know how to do this well, but I could take a crack at it if it's really necessary.
  • Documentation has been reviewed and updated as needed. The logic was previously wrong, so presumably this fix brings the behavior in line with the existing documentation.
  • Related issues have been listed and linked, including any that this PR closes. I didn't find any.

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.
Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACk 0681609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants