1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-07 01:27:11 +03:00

util: check for overflows in xbsearch_r()

This commit is contained in:
Lennart Poettering 2018-03-27 14:56:04 +02:00
parent cf852ff63b
commit 2901f4b31f

View File

@ -181,11 +181,13 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
const void *p; const void *p;
int comparison; int comparison;
assert(!size_multiply_overflow(nmemb, size));
l = 0; l = 0;
u = nmemb; u = nmemb;
while (l < u) { while (l < u) {
idx = (l + u) / 2; idx = (l + u) / 2;
p = (const char *) base + idx * size; p = (const uint8_t*) base + idx * size;
comparison = compar(key, p, arg); comparison = compar(key, p, arg);
if (comparison < 0) if (comparison < 0)
u = idx; u = idx;