util: fix overflow checks

This commit is contained in:
Lennart Poettering 2012-09-20 17:53:03 +02:00
parent 3f8cc098d2
commit aa408e7799
2 changed files with 3 additions and 3 deletions

View File

@ -1184,7 +1184,7 @@ char *strnappend(const char *s, const char *suffix, size_t b) {
assert(suffix);
a = strlen(s);
if ((size_t) -1 - a > b)
if (b > ((size_t) -1) - a)
return NULL;
r = new(char, a+b+1);

View File

@ -545,14 +545,14 @@ void closedirp(DIR **d);
void umaskp(mode_t *u);
_malloc_ static inline void *malloc_multiply(size_t a, size_t b) {
if (_unlikely_(a > ((size_t) -1) / b))
if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
return NULL;
return malloc(a * b);
}
_malloc_ static inline void *memdup_multiply(const void *p, size_t a, size_t b) {
if (_unlikely_(a > ((size_t) -1) / b))
if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
return NULL;
return memdup(p, a * b);