From b6e8c6b585cd5658266248f83a5889f16a1bc72c Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 23 Oct 2024 20:38:29 -0300 Subject: [PATCH] Fix two instances of non-null-terminated strings in FFI calls Regression introduced by commit a2eb883b6c4f. Reported-by: Christian Hopps Signed-off-by: Renato Westphal --- src/data.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/data.rs b/src/data.rs index 1376b43..2d418f8 100644 --- a/src/data.rs +++ b/src/data.rs @@ -496,11 +496,12 @@ impl<'a> DataTree<'a> { ) -> Result> { let mut rnode = std::ptr::null_mut(); let rnode_ptr = &mut rnode; + let cdata = CString::new(data.as_ref()).unwrap(); let ret = unsafe { ffi::lyd_parse_data_mem( context.raw, - data.as_ref().as_ptr() as _, + cdata.as_ptr() as _, format as u32, parser_options.bits(), validation_options.bits(), @@ -525,10 +526,10 @@ impl<'a> DataTree<'a> { let rnode_ptr = &mut rnode; // Create input handler. + let cdata = CString::new(data.as_ref()).unwrap(); let mut ly_in = std::ptr::null_mut(); - let ret = unsafe { - ffi::ly_in_new_memory(data.as_ref().as_ptr() as _, &mut ly_in) - }; + let ret = + unsafe { ffi::ly_in_new_memory(cdata.as_ptr() as _, &mut ly_in) }; if ret != ffi::LY_ERR::LY_SUCCESS { return Err(Error::new(context)); }