Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
This PR performs a repository-wide tidy-up to remove explicit comparisons against literal zero for common C library functions (e.g., strcmp(...) == 0 → !strcmp(...), memcmp(...) != 0 → memcmp(...)), including a few fseek/fstat checks.
Changes:
- Replace
== 0/!= 0comparisons forstrcmp,strncmp,memcmp,strlen,fseek, andfstatwith idiomatic truthy/falsey checks. - Apply the same style cleanup in tests and example programs to keep consistency.
- (Issue found) One updated
strncmpcheck in the Windows CNG backend is inverted and would reject valid keys.
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| vms/man2help.c | Uses !strncmp(...) for section header matching. |
| tests/test_simple.c | Simplifies strcmp equality check in base64 decode test. |
| tests/test_hostkey.c | Simplifies memcmp result check for hostkey equality. |
| tests/test_hostkey_hash.c | Simplifies multiple digest strcmp checks. |
| tests/test_auth_keyboard_info_request.c | Simplifies strcmp check for expected error message. |
| tests/session_fixture.c | Simplifies several strcmp checks in fixture setup/auth. |
| tests/openssh_fixture.c | Simplifies strcmp check for Docker “0.0.0.0” handling. |
| src/wincng.c | Simplifies string/memory comparisons; contains an inverted strncmp check. |
| src/userauth.c | Simplifies strncmp/memcmp equality checks in auth/key-sign algorithm selection. |
| src/sftp.c | Simplifies strncmp check for SFTP extension name. |
| src/publickey.c | Simplifies strncmp checks when parsing response codes/attributes. |
| src/pem.c | Simplifies fseek/strcmp/memcmp/strncmp/strcmp checks in PEM parsing paths. |
| src/packet.c | Simplifies multiple memcmp comparisons used for packet/type matching. |
| src/os400qc3.c | Simplifies memcmp equality check for key method name. |
| src/openssl.c | Simplifies many algorithm strcmp/memcmp equality checks. |
| src/misc.c | Simplifies strncmp mismatch check in ssh2_match_string. |
| src/mbedtls.c | Simplifies strcmp/fseek/memcmp checks in the mbedTLS backend. |
| src/libgcrypt.c | Simplifies memcmp equality check for key method name. |
| src/kex.c | Simplifies strcmp/strncmp equality checks in KEX method matching. |
| src/hostkey.c | Simplifies strncmp equality/mismatch checks for hostkey parsing. |
| example/x11.c | Simplifies strncmp check for DISPLAY parsing. |
| example/ssh2_exec.c | Simplifies strlen(password) non-empty check. |
| example/ssh2_echo.c | Simplifies strlen(password) non-empty check. |
| example/scp_write.c | Simplifies fstat error check. |
| example/scp_write_nonblock.c | Simplifies fstat error check. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
452
to
456
|
|
||
| if(strncmp((const char *)decoded.dataptr, AUTH_MAGIC, | ||
| strlen(AUTH_MAGIC)) != 0) { | ||
| strlen(AUTH_MAGIC))) { | ||
| ret = ssh2_err(session, LIBSSH2_ERROR_PROTO, | ||
| "key auth magic mismatch"); |
Comment on lines
2780
to
2784
| /* Read OPENSSL_PRIVATEKEY_AUTH_MAGIC */ | ||
| if(strncmp(data, OPENSSL_PRIVATEKEY_AUTH_MAGIC, data_len) != 0) { | ||
| if(strncmp(data, OPENSSL_PRIVATEKEY_AUTH_MAGIC, data_len)) { | ||
| result = -1; | ||
| goto cleanup; | ||
| } |
vszakats
added a commit
that referenced
this pull request
Jun 10, 2026
To make sure the null-terminator is present after the magic string. Refs: https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key https://anongit.mindrot.org/openssh.git/tree/PROTOCOL.key Reported by Copilot Bug: #2014 (comment) Bug: #2014 (comment) Follow-up to 3e72343 #1315 Follow-up to 0309229 #248 Closes #2022
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.
Drop from: