Repository navigation
Conversation
strlen() → sizeof()strlen() on literals with sizeof()
There was a problem hiding this comment.
Pull request overview
This PR is a follow-up to #2432, continuing the refactor of replacing strlen() calls on string literals with sizeof(...) - 1 to compute lengths at compile time and avoid runtime overhead.
Changes:
- Update PEM parsing to use an array-backed literal for
crypt_annotationand switch tosizeof(...) - 1for its length. - Update
test_hostkeyexpected hostkey literals to array form and usesizeof(...) - 1when decoding.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_hostkey.c | Converts expected hostkey literals to char[] so sizeof(...) - 1 can be used for base64 decode input lengths. |
| src/pem.c | Converts crypt_annotation to char[] and uses sizeof(...) - 1 for the compare length in PEM parsing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
194
to
+195
| if(passphrase && | ||
| !memcmp(line, crypt_annotation, strlen(crypt_annotation))) { | ||
| !memcmp(line, crypt_annotation, sizeof(crypt_annotation) - 1)) { |
Member
Author
There was a problem hiding this comment.
There we go again. Separate issue.
Member
Author
There was a problem hiding this comment.
The worst case here is matching Proc-Type: 4,ENCRYPTEDSOMETHING in a legacy-encrypted PEM file.
vszakats
added a commit
to vszakats/libssh2
that referenced
this pull request
Jul 28, 2026
Reported by Copilot libssh2#2438 (comment) Follow-up to 386e012
vszakats
added a commit
that referenced
this pull request
Jul 28, 2026
Before this patch it matched if the header had extra characters appended to it. Reported by Copilot #2438 (comment) Follow-up to 386e012 Closes #2440
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to 2eeae1e #2432