Page MenuHomeFreeBSD

lib{c,openbsd}: use ckd_mul() for overflow checking in re(c)allocarray
ClosedPublic

Authored by fuz on Thu, Oct 2, 1:30 PM.
Tags
None
Referenced Files
F133078557: D52854.diff
Wed, Oct 22, 6:53 PM
Unknown Object (File)
Mon, Oct 20, 1:05 AM
Unknown Object (File)
Sat, Oct 11, 3:28 PM
Unknown Object (File)
Sat, Oct 11, 3:27 PM
Unknown Object (File)
Sat, Oct 11, 3:27 PM
Unknown Object (File)
Sat, Oct 11, 6:56 AM
Unknown Object (File)
Thu, Oct 9, 1:56 AM
Unknown Object (File)
Sun, Oct 5, 5:42 PM
Subscribers
None

Details

Summary

This makes the code easier to understand and slightly faster,
but requires C23. calloc() would benefit, too, but I didn't
want to touch the imported jemalloc code base.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

fuz requested review of this revision.Thu, Oct 2, 1:30 PM
fuz created this revision.
kib added inline comments.
lib/libopenbsd/recallocarray.c
36

I would wrote

if (ckd_mul(&newsize, newnmemb, size) ||
    ckd_mul(&oldsize, oldnmemb, size)) {
             errno = EINVAL;
             return NULL;
}

since there are much simpler conditions now.

This revision is now accepted and ready to land.Thu, Oct 2, 11:00 PM
lib/libopenbsd/recallocarray.c
36

This cannot be done as one needs to fail with ENOMEM while the other fails with EINVAL.

lib/libopenbsd/recallocarray.c
36

Indeed, missed that.