Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass comment as CString #329

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tduda-fudosecurity
Copy link

The libssh2_knownhost_addc() expects comment to be a C string: it copies commentlen + 1 bytes internally from the buffer pointed by comment pointer. Granted, this is misleading: one would expect that if a function takes a pointer and length of data, it wouldn't access memory past this limit.

Passing a &str as a pointer and its length is incorrect and results in segmentation fault with rustc > 1.78.0 on macOS 14.6.1 (23G93) and FreeBSD 14 - we pass empty &str literal to the function.

The `libssh2_knownhost_addc()` expects `comment` to be a C string: it
copies `commentlen + 1` bytes internally from the buffer pointed by
`comment` pointer. Granted, this is misleading: one would expect that
if a function takes a pointer and length of data, it wouldn't access
memory past this limit.

Passing a `&str` as a pointer and its length is incorrect and results
in segmentation fault with `rustc` > 1.78.0 on macOS 14.6.1 (23G93)
and FreeBSD 14 - we pass empty &str literal to the function.
Method `count_bytes()` has been added fairly recently, in 1.79.0.
This change is to support older compilers.
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.

1 participant