Skip to content

Commit 2ec29e3

Browse files
fix(security): resolve code-scanning alerts #20, #66, #67, SAST #25 (#134)
- Remove #![allow(clippy::missing_safety_doc)] from runtime/lib.rs - Add missing # Safety documentation to all unsafe functions in list.rs - Add justification comment for .unwrap_or() in vram-cache/lib.rs These changes address: - Missing safety documentation for unsafe extern C functions - Unchecked unwrap patterns flagged by SAST scanners - Code scanning violations for unsafe code without justification
1 parent 979eb70 commit 2ec29e3

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/ephapax-runtime/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//! This provides the memory management primitives used by generated code.
88
99
#![cfg_attr(not(feature = "std"), no_std)]
10-
#![allow(clippy::missing_safety_doc)]
1110

1211
// Additional modules for self-hosting compiler
1312
pub mod list;

src/ephapax-runtime/src/list.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,20 @@ pub unsafe extern "C" fn __ephapax_list_clear(handle: ListHandle) {
186186
// ============================================================================
187187

188188
/// Create new empty string list
189+
///
190+
/// # Safety
191+
///
192+
/// Requires bump allocator to be initialized
189193
#[no_mangle]
190194
pub unsafe extern "C" fn __ephapax_string_list_new(initial_capacity: u32) -> ListHandle {
191195
__ephapax_list_new(initial_capacity)
192196
}
193197

194198
/// Append string to string list
199+
///
200+
/// # Safety
201+
///
202+
/// handle must be valid list handle
195203
#[no_mangle]
196204
pub unsafe extern "C" fn __ephapax_string_list_append(
197205
handle: ListHandle,
@@ -201,6 +209,10 @@ pub unsafe extern "C" fn __ephapax_string_list_append(
201209
}
202210

203211
/// Get string from string list
212+
///
213+
/// # Safety
214+
///
215+
/// handle must be valid list handle
204216
#[no_mangle]
205217
pub unsafe extern "C" fn __ephapax_string_list_get(handle: ListHandle, idx: i32) -> u32 {
206218
__ephapax_list_get(handle, idx) as u32

src/ephapax-vram-cache/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ impl VramCache {
145145

146146
// Calculate max entries based on average entry size (estimate 1KB per IR for safety)
147147
// Use generous limit so we evict based on bytes, not entry count
148+
// Safe: (max_size_bytes / 1024).max(1000) is always >= 1000, so try_into::<usize> will succeed
148149
let max_entries = ((max_size_bytes / 1024).max(1000) as u64)
149150
.try_into()
150151
.unwrap_or(10000);

0 commit comments

Comments
 (0)