Skip to content

src: misc tidy-ups - #1877

Closed
vszakats wants to merge 4 commits into
libssh2:masterfrom
vszakats:cq1
Closed

vszakats wants to merge 4 commits into
libssh2:masterfrom
vszakats:cq1

Conversation

@vszakats

@vszakats vszakats commented Apr 23, 2026 •

Copy link
Copy Markdown
Member
  • packet: replace ALLOC + memset with CALLOC. Also syncing usage with
    similar code nearby.
  • packet: fix error message.
  • packet: fix typo in comment.
  • userauth: make a error message consistent with others.
  • wincng: drop redundant unused variable silencers.

Pointed out by GitHub Code Quality

@vszakats vszakats changed the title misc: tidy-ups src: misc tidy-ups Apr 23, 2026
@vszakats
vszakats requested a review from Copilot April 23, 2026 18:55

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

Note

Copilot was unable to run its full agentic suite in this review.

This PR performs small cleanups across packet handling, user authentication, and WinCNG code paths to improve consistency and reduce redundant code.

Changes:

  • Replace ALLOC + memset with CALLOC for channel allocation in packet auth-agent open.
  • Fix/standardize several error messages and correct a comment typo.
  • Remove redundant unused-variable silencers and tighten variable scope in _libssh2_key_sign_algorithm().

Reviewed changes

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

File Description
src/packet.c Improves allocation/zeroing pattern, updates an error message, and fixes a comment typo.
src/userauth.c Standardizes an allocation error message and scopes version-parsing variables more tightly.
src/wincng.c Removes redundant (void) unused-variable silencers.

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

Comment thread src/userauth.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 3 out of 3 changed files in this pull request and generated 3 comments.


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

Comment thread src/userauth.c Outdated
const char *remote_ver = remote_ver_start + strlen(remote_ver_pre);
int SSH_BUG_SIGTYPE = is_version_less_than_78(remote_ver);
if(SSH_BUG_SIGTYPE && *key_method_len == method_len &&
memcmp(key_method, method, method_len)) {

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

memcmp is comparing key_method (type unsigned char **, e.g. &session->userauth_pblc_method) against the method string, so it reads bytes from the session struct rather than the method buffer. This makes the OpenSSH<=7.7 cert handling effectively incorrect/fragile. Compare *key_method to method instead, and adjust the condition to match the intent in the comment (i.e., trigger when the key method actually is the cert method).

Suggested change
memcmp(key_method, method, method_len)) {
memcmp(*key_method, method, method_len) == 0) {

Copilot uses AI. Check for mistakes.
Comment thread src/userauth.c Resolved
Comment thread src/userauth.c Outdated
memcmp(key_method,
"[email protected]", *key_method_len)) {
if(*key_method_len == method_len &&
memcmp(key_method, method, method_len)) {

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

Same issue as above: memcmp(key_method, method, method_len) compares the pointer-to-pointer rather than the method buffer. It should compare *key_method to method; once fixed, ensure the branch condition matches the intended behavior (append the cert suffix only when the original key method is the cert variant).

Suggested change
memcmp(key_method, method, method_len)) {
memcmp(*key_method, method, method_len) == 0) {

Copilot uses AI. Check for mistakes.
@vszakats vszakats closed this in ea14e9a Apr 23, 2026
@vszakats
vszakats deleted the cq1 branch April 23, 2026 23:10
vszakats added a commit that referenced this pull request Apr 24, 2026
- dedupe constant, and replace magic number with `sizeof()`.
- drop useless check for non-NULL `filtered_algs` on exit.
- fix leaking `filtered_algs` on an error path.
- fix to pass `*key_method` to `memcmp()` (was: `key_method`).
- fix to compare `memcmp()` against `0` (was: non-zero).
- add missing NULL-check before using `*key_method`.
- drop redundant `*key_method` NULL-check after use.
- scope variables.
- avoid camelcase in variable name.
- fix formatting.

Ref: #1314 (comment)
Ref: #1877 (comment)
Ref: #1877 (comment)
Follow-up to 3a6ab70 #1314

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