summaryrefslogtreecommitdiff
path: root/compat/win32
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-02-22 22:44:35 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-02-22 22:51:09 (GMT)
commit50a6c8efa2bbeddf46ca34c7765024108202e04b (patch)
tree0c189695ed6ad8349527cb03d326ef3fb39707cf /compat/win32
parent96ffc06f72f693d80f05059a1f0e5ca9007d5f1b (diff)
downloadgit-50a6c8efa2bbeddf46ca34c7765024108202e04b.zip
git-50a6c8efa2bbeddf46ca34c7765024108202e04b.tar.gz
git-50a6c8efa2bbeddf46ca34c7765024108202e04b.tar.bz2
use st_add and st_mult for allocation size computation
If our size computation overflows size_t, we may allocate a much smaller buffer than we expected and overflow it. It's probably impossible to trigger an overflow in most of these sites in practice, but it is easy enough convert their additions and multiplications into overflow-checking variants. This may be fixing real bugs, and it makes auditing the code easier. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/win32')
-rw-r--r--compat/win32/syslog.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/compat/win32/syslog.c b/compat/win32/syslog.c
index d015e43..b905aea 100644
--- a/compat/win32/syslog.c
+++ b/compat/win32/syslog.c
@@ -32,7 +32,7 @@ void syslog(int priority, const char *fmt, ...)
return;
}
- str = malloc(str_len + 1);
+ str = malloc(st_add(str_len, 1));
if (!str) {
warning("malloc failed: '%s'", strerror(errno));
return;
@@ -43,7 +43,7 @@ void syslog(int priority, const char *fmt, ...)
va_end(ap);
while ((pos = strstr(str, "%1")) != NULL) {
- str = realloc(str, ++str_len + 1);
+ str = realloc(str, st_add(++str_len, 1));
if (!str) {
warning("realloc failed: '%s'", strerror(errno));
return;