Skip to content
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

Fix formats #19

Merged
merged 3 commits into from
Sep 24, 2023
Merged

Fix formats #19

merged 3 commits into from
Sep 24, 2023

Conversation

elric1
Copy link
Contributor

@elric1 elric1 commented Sep 23, 2023

We solve a buffer overflow here. In these commits, we:

  • add an output buffer size parameter to most tz_format_*() functions. This allows us to fail if we are going to overflow any buffers. The current documentation in headers says that it is the caller's responsibility to ensure that the buffers are large enough to contain the formatted string, but without some sort of verification it is too easy to make an error. Now, we doublecheck,
  • we fix some sizes that were actually incorrect, and
  • the macro TZ_BASE58CHECK_BUFFER_SIZE() did not evaluate to the correct number, because the macro TZ_BASE58_BUFFER_SIZE() did not put brackets to ensure that order of operations did not fail. As a drive by, I used _ in front of each argument in the macros to make it less likely that the arguments conflict with variables in the existing namespace.

We just return an error if we don't fit.  This shouldn't happen unless
there is a mistake in the code, but failing gracefully is vastly superior
to having a buffer overflow.
@emturner emturner merged commit 0119169 into main Sep 24, 2023
@emturner emturner deleted the elric1@fix-formats branch September 24, 2023 18:34
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