Skip to content

Commit 568e901

Browse files
Rust wrapper: validate WOLFSSL_PREFIX in build.rs
1 parent c685293 commit 568e901

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

wrapper/rust/wolfssl-wolfcrypt/build.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,19 @@ fn wolfssl_repo_lib_dir() -> Result<String> {
3737
Ok(format!("{}/src/.libs", wolfssl_repo_base_dir()?))
3838
}
3939

40+
fn wolfssl_user_prefix() -> Option<String> {
41+
match env::var("WOLFSSL_PREFIX") {
42+
Ok(prefix) if !prefix.contains('\n') => Some(prefix),
43+
_ => None,
44+
}
45+
}
46+
4047
/// Returns the include directory for wolfssl headers.
4148
///
4249
/// If `WOLFSSL_PREFIX` is set, returns `{WOLFSSL_PREFIX}/include`.
4350
/// Otherwise falls back to the repo root if it exists (for in-tree host builds).
4451
fn wolfssl_include_dir() -> Result<Option<String>> {
45-
if let Ok(prefix) = env::var("WOLFSSL_PREFIX") {
52+
if let Some(prefix) = wolfssl_user_prefix() {
4653
let include_dir = format!("{}/include", prefix);
4754
let wolfssl_dir = Path::new(&include_dir).join("wolfssl");
4855
if !wolfssl_dir.is_dir() {
@@ -69,8 +76,14 @@ fn wolfssl_include_dir() -> Result<Option<String>> {
6976
/// If `WOLFSSL_PREFIX` is set, returns `{WOLFSSL_PREFIX}/lib`.
7077
/// Otherwise falls back to the in-tree build output directory if it exists.
7178
fn wolfssl_lib_dir() -> Result<Option<String>> {
72-
if let Ok(prefix) = env::var("WOLFSSL_PREFIX") {
73-
Ok(Some(format!("{}/lib", prefix)))
79+
if let Some(prefix) = wolfssl_user_prefix() {
80+
let lib_dir = format!("{}/lib", prefix);
81+
let lib_path = Path::new(&lib_dir);
82+
if !lib_path.is_dir() {
83+
println!("cargo:warning=WOLFSSL_PREFIX is set but {} does not exist", lib_dir);
84+
return Ok(None);
85+
}
86+
Ok(Some(lib_dir))
7487
} else {
7588
let repo_lib_dir = wolfssl_repo_lib_dir()?;
7689
if Path::new(&repo_lib_dir).exists() {

0 commit comments

Comments
 (0)