We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
CString::from_vec_unchecked requires that the argument does not contain interior nuls.
CString::from_vec_unchecked
The function to_cstr does not guard against interior nuls in the argument:
to_cstr
libpq.rs/src/ffi.rs
Lines 3 to 5 in 9e161c3
This function is called on user input in several places, such as here:
libpq.rs/src/connection/_exec.rs
Lines 78 to 79 in 9e161c3
Which means the safety requirement of CString::from_vec_unchecked can be violated by passing e.g. "\0" to Connection::prepare.
"\0"
Connection::prepare
The function new_cstring likewise violates the safety requirement when given any non-zero argument.
new_cstring
The text was updated successfully, but these errors were encountered:
I don’t understand why CString::from_vec_unchecked has marked as unsafe, all called functions internally are safe.
Calling Connection::exec with a string containing a null bit work as expected:
Connection::exec
fn main() { let conn = libpq::Connection::new("host=localhost").unwrap(); let results = conn.exec("\0select 1;"); assert_eq!(results.status(), libpq::Status::EmptyQuery); }
The old behavior is to panic. From my point of view it seems less acceptable.
Sorry, something went wrong.
According to this, this call is marked as unsafe due to a design contract and this is not related to memory safety: CString is guaranteed to not have interior nulls, as the documentation states that CString is "A type representing an owned, C-compatible, nul-terminated string with no nul bytes in the middle."
IMHO, This clarification renders this issue safe to be closed.
Thank you.
No branches or pull requests
CString::from_vec_unchecked
requires that the argument does not contain interior nuls.The function
to_cstr
does not guard against interior nuls in the argument:libpq.rs/src/ffi.rs
Lines 3 to 5 in 9e161c3
This function is called on user input in several places, such as here:
libpq.rs/src/connection/_exec.rs
Lines 78 to 79 in 9e161c3
Which means the safety requirement of
CString::from_vec_unchecked
can be violated by passing e.g."\0"
toConnection::prepare
.The function
new_cstring
likewise violates the safety requirement when given any non-zero argument.The text was updated successfully, but these errors were encountered: