Make sure that Rust strings with nul byte are rejected
MODIFY
src/error.rs
src/error.rs
-use std::fmt;
+use std::{
+ ffi::NulError,
+ fmt,
+};
+
+use crate::core;
#[derive(Debug)]
pub struct Error {
@@ -18,6 +23,12 @@ impl fmt::Display for Error {
}
}
+impl From<NulError> for Error {
+ fn from(_: NulError) -> Self {
+ Self::new(core::StsBadArg, "Passed Rust string contains nul byte".into())
+ }
+}
+
impl std::error::Error for Error {}
pub type Result<T, E = Error> = ::std::result::Result<T, E>;

MODIFY
src/templ.rs
src/templ.rs
@@ -5,7 +5,7 @@ use std::{
macro_rules! string_arg {
($name: ident) => {
- let $name = $crate::templ::cstring_new_infallible($name);
+ let $name = std::ffi::CString::new($name)?;
};
}

Make sure that Rust strings with nul byte are rejected