Skip to content

Commit

Permalink
Merge pull request #120 from datachainlab/audit-202409-lcp-8
Browse files Browse the repository at this point in the history
LCP-8: Add `panic-logging` feature to `enclave-runtime` crate

Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele authored Nov 19, 2024
2 parents d6ebfb5 + e99cbd3 commit fc3803f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions enclave-modules/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ host-api = { path = "../host-api" }
ecall-handler = { path = "../ecall-handler" }
enclave-environment = { path = "../environment" }
ecall-commands = { path = "../../modules/ecall-commands", default-features = false }

[features]
default = []
panic-logging = []
9 changes: 6 additions & 3 deletions enclave-modules/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ mod errors;
static ALLOC: sgx_alloc::System = sgx_alloc::System;

#[cfg(not(test))]
#[allow(unused_variables)]
#[panic_handler]
fn begin_panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
#[cfg(feature = "panic-logging")]
let msg = alloc::format!("[enclave] panic: {:?}\n", info).into_bytes();
#[cfg(not(feature = "panic-logging"))]
let msg = alloc::format!("[enclave] panic\n").into_bytes();
let _ = host_api::api::execute_command(host_api::ocall_commands::Command::Log(
host_api::ocall_commands::LogCommand {
msg: alloc::format!("[enclave] panic: {:?}\n", info).into_bytes(),
},
host_api::ocall_commands::LogCommand { msg },
));
sgx_abort();
}
Expand Down
5 changes: 4 additions & 1 deletion enclave/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ name = "proxy_enclave"
crate-type = ["staticlib"]

[features]
default = []
default = ["panic-logging"]
panic-logging = [
"enclave-runtime/panic-logging",
]

[dependencies]
enclave-runtime = { path = "../enclave-modules/runtime" }
Expand Down

0 comments on commit fc3803f

Please sign in to comment.