From 6a4efafa26d6a0424dee593d2091206c6e9f428d Mon Sep 17 00:00:00 2001 From: Franco Giachetta Date: Wed, 8 Jan 2025 17:27:47 +0000 Subject: [PATCH] fix possible segfault when checking runtime's version (#1032) --- runtime/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 417145265..354fd4554 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -42,9 +42,9 @@ pub unsafe extern "C" fn cairo_native__get_version(target: *mut u8, length: usiz let version = env!("CARGO_PKG_VERSION"); assert!(length > version.len(), "version buffer not big enough"); - let target = slice::from_raw_parts_mut(target, version.len()); + let target = slice::from_raw_parts_mut(target, length); - target.copy_from_slice(version.as_bytes()); + target[..version.len()].copy_from_slice(version.as_bytes()); target[version.len()] = b'\0'; version.len()