Skip to content

common: json_to_s64 accept only valid JSON numbers - #9421

Open
guibsa wants to merge 1 commit into
ElementsProject:masterfrom
guibsa:json-number-strict-decimal
Open

common: json_to_s64 accept only valid JSON numbers#9421
guibsa wants to merge 1 commit into
ElementsProject:masterfrom
guibsa:json-number-strict-decimal

Conversation

@guibsa

@guibsa guibsa commented Aug 15, 2026

Copy link
Copy Markdown

bool str_to_s64 parses a decimal s64 from exactly buflen bytes; false on bad chars, overflow, leading +, hex like '0x...' . Similar behavior of json_to_u64 and str_to_u64. Tests added. Partially fixes #9377

Important

26.09 FREEZE August 5th: Non-bugfix PRs not ready by this date will wait for 26.12.

RC1 is scheduled on August 17th

The final release is scheduled for September 7th.

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.
  • Documentation has been reviewed and updated as needed.
  • Related issues have been listed and linked, including any that this PR closes.
  • Important All PRs must consider how to reverse any persistent changes for tools/lightning-downgrade

bool str_to_s64 parses a decimal s64 from exactly buflen bytes; false on bad chars, overflow, leading +, hex like '0x...' . Similar behavior of json_to_u64 and str_to_u64. Tests added.

@Andezion Andezion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

run-utils-str_to_s64.c has no direct test like assert(!str_to_s64("+123", 3, &val)) or assert(!str_to_s64("0x1A", 4, &val)). it only tests --123 and +-123 (mixed/double signs), which is a different case, maybe worth adding something like +123 and a hex string

Comment thread common/utils.c
digit = buf[i] - '0';

if (negative) {
if (val < (INT64_MIN + digit) / 10)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice!

@@ -0,0 +1,234 @@
#include "config.h"
#include <assert.h>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

common/test/run-utils-str_to_s64.c has #include <assert.h> and then #include <assert.h> and #include <stdint.h> again right after /* AUTOGENERATED MOCKS END */. <stdint.h> also looks unused? The test uses s64 and LL/ULL literals, not int64_t/INT64_MIN directly

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.

common: json_to_s64 and json_to_double still accept hex, octal and signs

2 participants