summaryrefslogtreecommitdiff
path: root/usage.c
diff options
context:
space:
mode:
authorBrandon Casey <drafnel@gmail.com>2012-11-14 17:45:52 -0800
committerJunio C Hamano <gitster@pobox.com>2012-11-15 18:04:54 -0800
commitcd163d4b4e190d5e5131962c1b8f84601d4736d4 (patch)
treeb84cd743be4e7db07b924b053313e54ac2eefe8c /usage.c
parent7e2010537e96d0a1144520222f20ba1dc3d61441 (diff)
downloadgit-cd163d4b4e190d5e5131962c1b8f84601d4736d4.tar.gz
usage.c: detect recursion in die routines and bail out immediately
It is theoretically possible for a die handler to get into a state of infinite recursion. For example, if a die handler called another function which itself called die(). Let's at least detect this situation, inform the user, and call exit. Signed-off-by: Brandon Casey <bcasey@nvidia.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'usage.c')
-rw-r--r--usage.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/usage.c b/usage.c
index a2a6678004..8eab28113a 100644
--- a/usage.c
+++ b/usage.c
@@ -6,6 +6,8 @@
#include "git-compat-util.h"
#include "cache.h"
+static int dying;
+
void vreportf(const char *prefix, const char *err, va_list params)
{
char msg[4096];
@@ -82,6 +84,12 @@ void NORETURN die(const char *err, ...)
{
va_list params;
+ if (dying) {
+ fputs("fatal: recursion detected in die handler\n", stderr);
+ exit(128);
+ }
+ dying = 1;
+
va_start(params, err);
die_routine(err, params);
va_end(params);
@@ -94,6 +102,13 @@ void NORETURN die_errno(const char *fmt, ...)
char str_error[256], *err;
int i, j;
+ if (dying) {
+ fputs("fatal: recursion detected in die_errno handler\n",
+ stderr);
+ exit(128);
+ }
+ dying = 1;
+
err = strerror(errno);
for (i = j = 0; err[i] && j < sizeof(str_error) - 1; ) {
if ((str_error[j++] = err[i++]) != '%')