Skip to content

Commit 100141f

Browse files
committed
Remove null checks, fall through to UB upon deref
1 parent 79f3307 commit 100141f

File tree

1 file changed

+0
-70
lines changed

1 file changed

+0
-70
lines changed

src/shims/sync.rs

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
179179
fn pthread_mutexattr_init(&mut self, attr_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
180180
let this = self.eval_context_mut();
181181

182-
let attr = this.read_scalar(attr_op)?.not_undef()?;
183-
if this.is_null(attr)? {
184-
return this.eval_libc_i32("EINVAL");
185-
}
186-
187182
let default_kind = this.eval_libc("PTHREAD_MUTEX_DEFAULT")?;
188183
mutexattr_set_kind(this, attr_op, default_kind)?;
189184

@@ -197,11 +192,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
197192
) -> InterpResult<'tcx, i32> {
198193
let this = self.eval_context_mut();
199194

200-
let attr = this.read_scalar(attr_op)?.not_undef()?;
201-
if this.is_null(attr)? {
202-
return this.eval_libc_i32("EINVAL");
203-
}
204-
205195
let kind = this.read_scalar(kind_op)?.not_undef()?;
206196
if kind == this.eval_libc("PTHREAD_MUTEX_NORMAL")?
207197
|| kind == this.eval_libc("PTHREAD_MUTEX_ERRORCHECK")?
@@ -219,11 +209,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
219209
fn pthread_mutexattr_destroy(&mut self, attr_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
220210
let this = self.eval_context_mut();
221211

222-
let attr = this.read_scalar(attr_op)?.not_undef()?;
223-
if this.is_null(attr)? {
224-
return this.eval_libc_i32("EINVAL");
225-
}
226-
227212
mutexattr_set_kind(this, attr_op, ScalarMaybeUndef::Undef)?;
228213

229214
Ok(0)
@@ -236,11 +221,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
236221
) -> InterpResult<'tcx, i32> {
237222
let this = self.eval_context_mut();
238223

239-
let mutex = this.read_scalar(mutex_op)?.not_undef()?;
240-
if this.is_null(mutex)? {
241-
return this.eval_libc_i32("EINVAL");
242-
}
243-
244224
let attr = this.read_scalar(attr_op)?.not_undef()?;
245225
let kind = if this.is_null(attr)? {
246226
this.eval_libc("PTHREAD_MUTEX_DEFAULT")?
@@ -257,11 +237,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
257237
fn pthread_mutex_lock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
258238
let this = self.eval_context_mut();
259239

260-
let mutex = this.read_scalar(mutex_op)?.not_undef()?;
261-
if this.is_null(mutex)? {
262-
return this.eval_libc_i32("EINVAL");
263-
}
264-
265240
let kind = mutex_get_kind(this, mutex_op)?.not_undef()?;
266241
let locked_count = mutex_get_locked_count(this, mutex_op)?.to_u32()?;
267242

@@ -295,11 +270,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
295270
fn pthread_mutex_trylock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
296271
let this = self.eval_context_mut();
297272

298-
let mutex = this.read_scalar(mutex_op)?.not_undef()?;
299-
if this.is_null(mutex)? {
300-
return this.eval_libc_i32("EINVAL");
301-
}
302-
303273
let kind = mutex_get_kind(this, mutex_op)?.not_undef()?;
304274
let locked_count = mutex_get_locked_count(this, mutex_op)?.to_u32()?;
305275

@@ -328,11 +298,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
328298
fn pthread_mutex_unlock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
329299
let this = self.eval_context_mut();
330300

331-
let mutex = this.read_scalar(mutex_op)?.not_undef()?;
332-
if this.is_null(mutex)? {
333-
return this.eval_libc_i32("EINVAL");
334-
}
335-
336301
let kind = mutex_get_kind(this, mutex_op)?.not_undef()?;
337302
let locked_count = mutex_get_locked_count(this, mutex_op)?.to_u32()?;
338303

@@ -371,11 +336,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
371336
fn pthread_mutex_destroy(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
372337
let this = self.eval_context_mut();
373338

374-
let mutex = this.read_scalar(mutex_op)?.not_undef()?;
375-
if this.is_null(mutex)? {
376-
return this.eval_libc_i32("EINVAL");
377-
}
378-
379339
if mutex_get_locked_count(this, mutex_op)?.to_u32()? != 0 {
380340
return this.eval_libc_i32("EBUSY");
381341
}
@@ -389,11 +349,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
389349
fn pthread_rwlock_rdlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
390350
let this = self.eval_context_mut();
391351

392-
let rwlock = this.read_scalar(rwlock_op)?.not_undef()?;
393-
if this.is_null(rwlock)? {
394-
return this.eval_libc_i32("EINVAL");
395-
}
396-
397352
let readers = rwlock_get_readers(this, rwlock_op)?.to_u32()?;
398353
let writers = rwlock_get_writers(this, rwlock_op)?.to_u32()?;
399354
if writers != 0 {
@@ -414,11 +369,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
414369
fn pthread_rwlock_tryrdlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
415370
let this = self.eval_context_mut();
416371

417-
let rwlock = this.read_scalar(rwlock_op)?.not_undef()?;
418-
if this.is_null(rwlock)? {
419-
return this.eval_libc_i32("EINVAL");
420-
}
421-
422372
let readers = rwlock_get_readers(this, rwlock_op)?.to_u32()?;
423373
let writers = rwlock_get_writers(this, rwlock_op)?.to_u32()?;
424374
if writers != 0 {
@@ -437,11 +387,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
437387
fn pthread_rwlock_wrlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
438388
let this = self.eval_context_mut();
439389

440-
let rwlock = this.read_scalar(rwlock_op)?.not_undef()?;
441-
if this.is_null(rwlock)? {
442-
return this.eval_libc_i32("EINVAL");
443-
}
444-
445390
let readers = rwlock_get_readers(this, rwlock_op)?.to_u32()?;
446391
let writers = rwlock_get_writers(this, rwlock_op)?.to_u32()?;
447392
if readers != 0 {
@@ -461,11 +406,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
461406
fn pthread_rwlock_trywrlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
462407
let this = self.eval_context_mut();
463408

464-
let rwlock = this.read_scalar(rwlock_op)?.not_undef()?;
465-
if this.is_null(rwlock)? {
466-
return this.eval_libc_i32("EINVAL");
467-
}
468-
469409
let readers = rwlock_get_readers(this, rwlock_op)?.to_u32()?;
470410
let writers = rwlock_get_writers(this, rwlock_op)?.to_u32()?;
471411
if readers != 0 || writers != 0 {
@@ -479,11 +419,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
479419
fn pthread_rwlock_unlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
480420
let this = self.eval_context_mut();
481421

482-
let rwlock = this.read_scalar(rwlock_op)?.not_undef()?;
483-
if this.is_null(rwlock)? {
484-
return this.eval_libc_i32("EINVAL");
485-
}
486-
487422
let readers = rwlock_get_readers(this, rwlock_op)?.to_u32()?;
488423
let writers = rwlock_get_writers(this, rwlock_op)?.to_u32()?;
489424
if let Some(new_readers) = readers.checked_sub(1) {
@@ -500,11 +435,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
500435
fn pthread_rwlock_destroy(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
501436
let this = self.eval_context_mut();
502437

503-
let rwlock = this.read_scalar(rwlock_op)?.not_undef()?;
504-
if this.is_null(rwlock)? {
505-
return this.eval_libc_i32("EINVAL");
506-
}
507-
508438
if rwlock_get_readers(this, rwlock_op)?.to_u32()? != 0 {
509439
return this.eval_libc_i32("EBUSY");
510440
}

0 commit comments

Comments
 (0)