Skip to content

mbedtls: drop no-op checks from mbed_mpi_write_binary() - #2278

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:mbed-wr-fix-boundary-check
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:mbed-wr-fix-boundary-check

Conversation

@vszakats

@vszakats vszakats commented Jul 12, 2026 •

Copy link
Copy Markdown
Member

To sync with ossl_write_bn() sibling function.

Reported by GitHub Code Quality
Follow-up to 5528f3d #385


https://github.com/libssh2/libssh2/pull/2278/files?w=1

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request adjusts the mbedTLS ECDSA signature encoding helper in src/mbedtls.c to add explicit buffer-length bounds checks, consolidate conditional logic, and rename variables for improved readability while writing MPIs into the SSH wire-format signature buffer.

Changes:

  • Extend mbed_mpi_write_binary() to accept an explicit buf_len and add bounds checks.
  • Consolidate conditional branches around MPI writing and leading-zero stripping.
  • Update ECDSA signing code to use the revised helper signature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/mbedtls.c Resolved
Comment thread src/mbedtls.c Resolved
Comment thread src/mbedtls.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread src/mbedtls.c Resolved
Comment thread src/mbedtls.c Resolved
Comment thread src/mbedtls.c Resolved
@vszakats
vszakats force-pushed the mbed-wr-fix-boundary-check branch 3 times, most recently from fa540a0 to a82d7c8 Compare July 12, 2026 20:36
@vszakats
vszakats requested a review from Copilot July 12, 2026 20:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

Comment thread src/mbedtls.c Resolved
Comment thread src/mbedtls.c Resolved
Comment thread src/mbedtls.c Resolved
Comment thread src/mbedtls.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread src/mbedtls.c Resolved
Comment thread src/mbedtls.c Resolved
Comment thread src/mbedtls.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread src/mbedtls.c Resolved
Comment thread src/mbedtls.c Resolved
mbedtls.c fix bounds check in mbed_mpi_write_binary

"The condition `sizeof(&p) / sizeof(p[0])` computes the size of a
pointer divided by the size of `unsigned char` (which is 1), yielding 4
on 32-bit or 8 on 64-bit platforms. This expression is never less than 4
on any supported architecture, so the guard `goto done` is dead code and
the function always proceeds to write to `p` without the intended safety
check. The intended check is likely a compile-time buffer size guard and
should be reformulated correctly."

rename to try fix clang-tidy false positive

cleanups

backtrack on rename for a cleaner diff

fixups

sync with openssl
@vszakats
vszakats force-pushed the mbed-wr-fix-boundary-check branch from 2abebd3 to 767e111 Compare July 12, 2026 21:28
@vszakats vszakats changed the title mbedtls: fix bounds check in mbed_mpi_write_binary() mbedtls: drop no-op check from mbed_mpi_write_binary() Jul 12, 2026
@vszakats
vszakats requested a review from Copilot July 12, 2026 21:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@vszakats vszakats changed the title mbedtls: drop no-op check from mbed_mpi_write_binary() mbedtls: drop no-op check from mbed_mpi_write_binary(), sync with ossl_write_bn() Jul 12, 2026
@vszakats vszakats changed the title mbedtls: drop no-op check from mbed_mpi_write_binary(), sync with ossl_write_bn() mbedtls: drop no-op checks from mbed_mpi_write_binary() Jul 12, 2026
@vszakats vszakats closed this in 346a317 Jul 12, 2026
@vszakats
vszakats deleted the mbed-wr-fix-boundary-check branch July 12, 2026 21:44
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