Skip to content

Commit

Permalink
Merge branch 'bc/do-not-recurse-in-die'
Browse files Browse the repository at this point in the history
* bc/do-not-recurse-in-die:
  usage.c: detect recursion in die routines and bail out immediately
  • Loading branch information
Junio C Hamano committed Nov 26, 2012
2 parents f225f9b + cd163d4 commit e0a7f2b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand All @@ -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++]) != '%')
Expand Down

0 comments on commit e0a7f2b

Please sign in to comment.