Skip to content

Commit 11d2169

Browse files
committed
Avoid infinite error handling recursion in runguard.
Previously, there were two scenarios that are problematic: - while handling an error, we start writing the meta file, and if that also fails, we treat this as handling a new error and never stop; - while writing the meta file, we encounter an error which in turn tries writing to the meta file causing another error and we never stop.
1 parent 42e4165 commit 11d2169

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

judge/runguard.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ int be_verbose;
136136
int be_quiet;
137137
int show_help;
138138
int show_version;
139+
int in_error_handling = 0;
139140
pid_t runpipe_pid = -1;
140141

142+
141143
double walltimelimit[2], cputimelimit[2]; /* in seconds, soft and hard limits */
142144
int walllimit_reached, cpulimit_reached; /* 1=soft, 2=hard, 3=both limits reached */
143145
int64_t memsize;
@@ -222,6 +224,10 @@ void verbose(const char *format, ...)
222224

223225
void error(int errnum, const char *format, ...)
224226
{
227+
// Silently ignore errors that happen while handling other errors.
228+
if (in_error_handling) return;
229+
in_error_handling = 1;
230+
225231
va_list ap;
226232
va_start(ap,format);
227233

@@ -305,12 +311,15 @@ void write_meta(const char *key, const char *format, ...)
305311
va_start(ap,format);
306312

307313
if ( fprintf(metafile,"%s: ",key)<=0 ) {
314+
outputmeta = 0;
308315
error(0,"cannot write to file `%s'",metafilename);
309316
}
310317
if ( vfprintf(metafile,format,ap)<0 ) {
318+
outputmeta = 0;
311319
error(0,"cannot write to file `%s'(vfprintf)",metafilename);
312320
}
313321
if ( fprintf(metafile,"\n")<=0 ) {
322+
outputmeta = 0;
314323
error(0,"cannot write to file `%s'",metafilename);
315324
}
316325

0 commit comments

Comments
 (0)