Skip to content

kex: replace magic number and strlen() with sizeof() - #2400

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:kexmagic
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:kexmagic

Conversation

@vszakats

@vszakats vszakats commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

Also:

  • make const strings static, where missing.
  • move static to top of block, where missing.
  • reduce casts.

Also make const strings static, where missing.
Copilot AI review requested due to automatic review settings July 22, 2026 22:45

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 PR improves maintainability in the SSH key-exchange (kex) implementation by removing hard-coded string lengths and avoiding runtime strlen() where the string is a compile-time constant.

Changes:

  • Replace the magic constant 28 for "[email protected]" with sizeof(...) - 1.
  • Replace strlen() with sizeof(...) - 1 for a constant KEX extension prefix string.
  • Make the affected constant strings static const and adjust placement to match the PR’s stated cleanup goals.

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

@vszakats vszakats closed this in 88c5fd9 Jul 22, 2026
@vszakats
vszakats deleted the kexmagic branch July 22, 2026 23:09
vszakats added a commit that referenced this pull request Jul 25, 2026
This reverts an earlier change doing the opposite. `sizeof()` determines
length at build-time, while `strlen()` does the same at runtime. In case
of literals the results are identical, but the build-time option does it
with zero runtime overhead.

Also:
- fix typo in literal used for determining length. (length was correct.)
  Follow-up to bc4e619 #752
- move literals to the right-side of comparisons, where missing.

Follow-up to 88c5fd9 #2400
Follow-up to af1b501 #2224
Follow-up to 88a960a #1179

Closes #2432
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