[systemd-commits] src/shared
Lennart Poettering
lennart at kemper.freedesktop.org
Thu Sep 20 08:53:10 PDT 2012
src/shared/util.c | 2 +-
src/shared/util.h | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
New commits:
commit aa408e7799cf01f048efedf434916544b4badc77
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Sep 20 17:53:03 2012 +0200
util: fix overflow checks
diff --git a/src/shared/util.c b/src/shared/util.c
index 02ee637..be94515 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -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);
diff --git a/src/shared/util.h b/src/shared/util.h
index 2e49cfd..e1d4735 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -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);
More information about the systemd-commits
mailing list