Remove null checks, fall through to UB upon deref
This commit is contained in:
parent
79f3307f30
commit
100141f57c
@ -179,11 +179,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
fn pthread_mutexattr_init(&mut self, attr_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let attr = this.read_scalar(attr_op)?.not_undef()?;
|
||||
if this.is_null(attr)? {
|
||||
return this.eval_libc_i32("EINVAL");
|
||||
}
|
||||
|
||||
let default_kind = this.eval_libc("PTHREAD_MUTEX_DEFAULT")?;
|
||||
mutexattr_set_kind(this, attr_op, default_kind)?;
|
||||
|
||||
@ -197,11 +192,6 @@ fn pthread_mutexattr_settype(
|
||||
) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let attr = this.read_scalar(attr_op)?.not_undef()?;
|
||||
if this.is_null(attr)? {
|
||||
return this.eval_libc_i32("EINVAL");
|
||||
}
|
||||
|
||||
let kind = this.read_scalar(kind_op)?.not_undef()?;
|
||||
if kind == this.eval_libc("PTHREAD_MUTEX_NORMAL")?
|
||||
|| kind == this.eval_libc("PTHREAD_MUTEX_ERRORCHECK")?
|
||||
@ -219,11 +209,6 @@ fn pthread_mutexattr_settype(
|
||||
fn pthread_mutexattr_destroy(&mut self, attr_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let attr = this.read_scalar(attr_op)?.not_undef()?;
|
||||
if this.is_null(attr)? {
|
||||
return this.eval_libc_i32("EINVAL");
|
||||
}
|
||||
|
||||
mutexattr_set_kind(this, attr_op, ScalarMaybeUndef::Undef)?;
|
||||
|
||||
Ok(0)
|
||||
@ -236,11 +221,6 @@ fn pthread_mutex_init(
|
||||
) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let mutex = this.read_scalar(mutex_op)?.not_undef()?;
|
||||
if this.is_null(mutex)? {
|
||||
return this.eval_libc_i32("EINVAL");
|
||||
}
|
||||
|
||||
let attr = this.read_scalar(attr_op)?.not_undef()?;
|
||||
let kind = if this.is_null(attr)? {
|
||||
this.eval_libc("PTHREAD_MUTEX_DEFAULT")?
|
||||
@ -257,11 +237,6 @@ fn pthread_mutex_init(
|
||||
fn pthread_mutex_lock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let mutex = this.read_scalar(mutex_op)?.not_undef()?;
|
||||
if this.is_null(mutex)? {
|
||||
return this.eval_libc_i32("EINVAL");
|
||||
}
|
||||
|
||||
let kind = mutex_get_kind(this, mutex_op)?.not_undef()?;
|
||||
let locked_count = mutex_get_locked_count(this, mutex_op)?.to_u32()?;
|
||||
|
||||
@ -295,11 +270,6 @@ fn pthread_mutex_lock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx
|
||||
fn pthread_mutex_trylock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let mutex = this.read_scalar(mutex_op)?.not_undef()?;
|
||||
if this.is_null(mutex)? {
|
||||
return this.eval_libc_i32("EINVAL");
|
||||
}
|
||||
|
||||
let kind = mutex_get_kind(this, mutex_op)?.not_undef()?;
|
||||
let locked_count = mutex_get_locked_count(this, mutex_op)?.to_u32()?;
|
||||
|
||||
@ -328,11 +298,6 @@ fn pthread_mutex_trylock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'
|
||||
fn pthread_mutex_unlock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let mutex = this.read_scalar(mutex_op)?.not_undef()?;
|
||||
if this.is_null(mutex)? {
|
||||
return this.eval_libc_i32("EINVAL");
|
||||
}
|
||||
|
||||
let kind = mutex_get_kind(this, mutex_op)?.not_undef()?;
|
||||
let locked_count = mutex_get_locked_count(this, mutex_op)?.to_u32()?;
|
||||
|
||||
@ -371,11 +336,6 @@ fn pthread_mutex_unlock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'t
|
||||
fn pthread_mutex_destroy(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let mutex = this.read_scalar(mutex_op)?.not_undef()?;
|
||||
if this.is_null(mutex)? {
|
||||
return this.eval_libc_i32("EINVAL");
|
||||
}
|
||||
|
||||
if mutex_get_locked_count(this, mutex_op)?.to_u32()? != 0 {
|
||||
return this.eval_libc_i32("EBUSY");
|
||||
}
|
||||
@ -389,11 +349,6 @@ fn pthread_mutex_destroy(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'
|
||||
fn pthread_rwlock_rdlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let rwlock = this.read_scalar(rwlock_op)?.not_undef()?;
|
||||
if this.is_null(rwlock)? {
|
||||
return this.eval_libc_i32("EINVAL");
|
||||
}
|
||||
|
||||
let readers = rwlock_get_readers(this, rwlock_op)?.to_u32()?;
|
||||
let writers = rwlock_get_writers(this, rwlock_op)?.to_u32()?;
|
||||
if writers != 0 {
|
||||
@ -414,11 +369,6 @@ fn pthread_rwlock_rdlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<
|
||||
fn pthread_rwlock_tryrdlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let rwlock = this.read_scalar(rwlock_op)?.not_undef()?;
|
||||
if this.is_null(rwlock)? {
|
||||
return this.eval_libc_i32("EINVAL");
|
||||
}
|
||||
|
||||
let readers = rwlock_get_readers(this, rwlock_op)?.to_u32()?;
|
||||
let writers = rwlock_get_writers(this, rwlock_op)?.to_u32()?;
|
||||
if writers != 0 {
|
||||
@ -437,11 +387,6 @@ fn pthread_rwlock_tryrdlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResu
|
||||
fn pthread_rwlock_wrlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let rwlock = this.read_scalar(rwlock_op)?.not_undef()?;
|
||||
if this.is_null(rwlock)? {
|
||||
return this.eval_libc_i32("EINVAL");
|
||||
}
|
||||
|
||||
let readers = rwlock_get_readers(this, rwlock_op)?.to_u32()?;
|
||||
let writers = rwlock_get_writers(this, rwlock_op)?.to_u32()?;
|
||||
if readers != 0 {
|
||||
@ -461,11 +406,6 @@ fn pthread_rwlock_wrlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<
|
||||
fn pthread_rwlock_trywrlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let rwlock = this.read_scalar(rwlock_op)?.not_undef()?;
|
||||
if this.is_null(rwlock)? {
|
||||
return this.eval_libc_i32("EINVAL");
|
||||
}
|
||||
|
||||
let readers = rwlock_get_readers(this, rwlock_op)?.to_u32()?;
|
||||
let writers = rwlock_get_writers(this, rwlock_op)?.to_u32()?;
|
||||
if readers != 0 || writers != 0 {
|
||||
@ -479,11 +419,6 @@ fn pthread_rwlock_trywrlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResu
|
||||
fn pthread_rwlock_unlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let rwlock = this.read_scalar(rwlock_op)?.not_undef()?;
|
||||
if this.is_null(rwlock)? {
|
||||
return this.eval_libc_i32("EINVAL");
|
||||
}
|
||||
|
||||
let readers = rwlock_get_readers(this, rwlock_op)?.to_u32()?;
|
||||
let writers = rwlock_get_writers(this, rwlock_op)?.to_u32()?;
|
||||
if let Some(new_readers) = readers.checked_sub(1) {
|
||||
@ -500,11 +435,6 @@ fn pthread_rwlock_unlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<
|
||||
fn pthread_rwlock_destroy(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let rwlock = this.read_scalar(rwlock_op)?.not_undef()?;
|
||||
if this.is_null(rwlock)? {
|
||||
return this.eval_libc_i32("EINVAL");
|
||||
}
|
||||
|
||||
if rwlock_get_readers(this, rwlock_op)?.to_u32()? != 0 {
|
||||
return this.eval_libc_i32("EBUSY");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user