Skip to content

Commit e8e9bd6

Browse files
committed
Remove and prevent use of assert* in hyperlight_host
Signed-off-by: Simon Davies <[email protected]>
1 parent 23058ec commit e8e9bd6

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

src/hyperlight_host/src/clippy.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
disallowed-macros = [
2+
{ path = "std::assert", reason = "no asserts in release builds" },
3+
{ path = "std::assert_eq", reason = "no asserts in release builds" },
4+
{ path = "std::assert_ne", reason = "no asserts in release builds" },
5+
{ path = "std::assert_true", reason = "no asserts in release builds" },
6+
{ path = "std::assert_false", reason = "no asserts in release builds" },
7+
]

src/hyperlight_host/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ limitations under the License.
2020
#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::panic))]
2121
#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::expect_used))]
2222
#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::unwrap_used))]
23+
#![cfg_attr(any(test,debug_assertions),allow(clippy::disallowed_macros))]
2324

2425
use std::sync::Once;
2526

src/hyperlight_host/src/mem/shared_mem.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,13 @@ impl ExclusiveSharedMemory {
328328
.checked_add(2 * PAGE_SIZE_USIZE) // guard page around the memory
329329
.ok_or_else(|| new_error!("Memory required for sandbox exceeded usize::MAX"))?;
330330

331-
assert!(
332-
total_size % PAGE_SIZE_USIZE == 0,
333-
"shared memory must be a multiple of 4096"
334-
);
331+
if total_size % PAGE_SIZE_USIZE != 0 {
332+
return Err(new_error!(
333+
"shared memory must be a multiple of {}",
334+
PAGE_SIZE_USIZE
335+
));
336+
}
337+
335338
// usize and isize are guaranteed to be the same size, and
336339
// isize::MAX should be positive, so this cast should be safe.
337340
if total_size > isize::MAX as usize {

src/hyperlight_host/src/metrics/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ fn get_histogram_opts(name: &str, help: &str, buckets: Vec<f64>) -> HistogramOpt
259259
opts.buckets(buckets)
260260
}
261261

262+
#[allow(clippy::disallowed_macros)]
262263
/// Provides functionality to help with testing Hyperlight Metrics
263264
pub mod tests {
264265
use std::collections::HashSet;

src/hyperlight_host/src/sandbox/uninitialized_evolve.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ where
7676

7777
{
7878
let dispatch_function_addr = hshm.as_ref().get_pointer_to_dispatch_function()?;
79-
assert_ne!(dispatch_function_addr, 0);
79+
if dispatch_function_addr == 0 {
80+
return Err(new_error!("Dispatch function address is null"));
81+
}
8082
hv_handler.set_dispatch_function_addr(RawPtr::from(dispatch_function_addr))?;
8183
}
8284

0 commit comments

Comments
 (0)