From ca84f5b7952e174927a7064a40e2c1d4a1b4f329 Mon Sep 17 00:00:00 2001 From: Marsman Date: Tue, 10 Feb 2026 02:45:24 +0000 Subject: [PATCH] fix: handle invalid `pshared` in `pthread_rwlockattr_setpshared` --- src/header/pthread/rwlock.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/header/pthread/rwlock.rs b/src/header/pthread/rwlock.rs index e4682f067c..af943966ec 100644 --- a/src/header/pthread/rwlock.rs +++ b/src/header/pthread/rwlock.rs @@ -1,6 +1,6 @@ use super::*; -use crate::header::errno::EBUSY; +use crate::header::errno::{EBUSY, EINVAL}; use crate::pthread::Pshared; @@ -97,9 +97,11 @@ pub unsafe extern "C" fn pthread_rwlockattr_setpshared( attr: *mut pthread_rwlockattr_t, pshared: c_int, ) -> c_int { - (unsafe { *attr.cast::() }).pshared = - Pshared::from_raw(pshared).expect("invalid pshared in pthread_rwlockattr_setpshared"); + let Some(pshared) = Pshared::from_raw(pshared) else { + return EINVAL; + }; + (unsafe { *attr.cast::() }).pshared = pshared; 0 }