summaryrefslogtreecommitdiff
path: root/wrapper.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-01-27 14:56:38 -0800
committerJunio C Hamano <gitster@pobox.com>2010-01-27 14:56:38 -0800
commita0075d9e6ae211e8bde3eb40c8cdebb1772ee680 (patch)
treeb29228a2bb894edd907b319b23c77025b5f9e407 /wrapper.c
parentf1694b62bb3a3e1766b92d64a38f61524cc730a0 (diff)
parent4ab07e4d1076a1b94b91d58913daeb20eb1c0e2d (diff)
downloadgit-a0075d9e6ae211e8bde3eb40c8cdebb1772ee680.tar.gz
Merge branch 'il/maint-xmallocz'
* il/maint-xmallocz: Fix integer overflow in unpack_compressed_entry() Fix integer overflow in unpack_sha1_rest() Fix integer overflow in patch_delta() Add xmallocz()
Diffstat (limited to 'wrapper.c')
-rw-r--r--wrapper.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/wrapper.c b/wrapper.c
index c9be1400c0..0e3e20a3fd 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -34,6 +34,16 @@ void *xmalloc(size_t size)
return ret;
}
+void *xmallocz(size_t size)
+{
+ void *ret;
+ if (size + 1 < size)
+ die("Data too large to fit into virtual memory space.");
+ ret = xmalloc(size + 1);
+ ((char*)ret)[size] = 0;
+ return ret;
+}
+
/*
* xmemdupz() allocates (len + 1) bytes of memory, duplicates "len" bytes of
* "data" to the allocated memory, zero terminates the allocated memory,
@@ -42,10 +52,7 @@ void *xmalloc(size_t size)
*/
void *xmemdupz(const void *data, size_t len)
{
- char *p = xmalloc(len + 1);
- memcpy(p, data, len);
- p[len] = '\0';
- return p;
+ return memcpy(xmallocz(len), data, len);
}
char *xstrndup(const char *str, size_t len)