From: Junio C Hamano Date: Thu, 10 Feb 2011 22:45:55 +0000 (-0800) Subject: Merge branch 'maint' X-Git-Tag: v1.7.5-rc0~137 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/b308bf18633964102472db5065929a359d4ad265?hp=-c Merge branch 'maint' * maint: compat: helper for detecting unsigned overflow --- b308bf18633964102472db5065929a359d4ad265 diff --combined wrapper.c index 55b074ec46,79635f2e16..4c147d6c48 --- a/wrapper.c +++ b/wrapper.c @@@ -53,7 -53,7 +53,7 @@@ void *xmalloc(size_t size void *xmallocz(size_t size) { void *ret; - if (size + 1 < size) + if (unsigned_add_overflows(size, 1)) die("Data too large to fit into virtual memory space."); ret = xmalloc(size + 1); ((char*)ret)[size] = 0; @@@ -198,22 -198,10 +198,22 @@@ FILE *xfdopen(int fd, const char *mode int xmkstemp(char *template) { int fd; + char origtemplate[PATH_MAX]; + strlcpy(origtemplate, template, sizeof(origtemplate)); fd = mkstemp(template); - if (fd < 0) - die_errno("Unable to create temporary file"); + if (fd < 0) { + int saved_errno = errno; + const char *nonrelative_template; + + if (!template[0]) + template = origtemplate; + + nonrelative_template = make_nonrelative_path(template); + errno = saved_errno; + die_errno("Unable to create temporary file '%s'", + nonrelative_template); + } return fd; } @@@ -333,22 -321,10 +333,22 @@@ int gitmkstemps(char *pattern, int suff int xmkstemp_mode(char *template, int mode) { int fd; + char origtemplate[PATH_MAX]; + strlcpy(origtemplate, template, sizeof(origtemplate)); fd = git_mkstemp_mode(template, mode); - if (fd < 0) - die_errno("Unable to create temporary file"); + if (fd < 0) { + int saved_errno = errno; + const char *nonrelative_template; + + if (!template[0]) + template = origtemplate; + + nonrelative_template = make_nonrelative_path(template); + errno = saved_errno; + die_errno("Unable to create temporary file '%s'", + nonrelative_template); + } return fd; }