Skip to contentSkip to conversation

debugfs: don't try to fclose NULL

PATCH Applied Eric Sandeen 4 participants 5 messages Jun 26, 2009 – Jun 30, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 debugfs: don't try to fclose NULL

do_logdump may jump to errout if fopen(out_file) fails, but in that case out_file is NULL, and fclose will segfault.

---

debugfs/logdump.c +1 -1
index 4818bc6..9a7108a 100644
@@ -259,7 +259,7 @@ void do_logdump(int argc, char **argv)
 		close(journal_fd);
 
 errout:
-	if (out_file != stdout)
+	if (out_file && (out_file != stdout))
 		fclose(out_file);
 
 	return;
Applied
#1 lore raw
Quoted 4 lines · Eric Sandeen

do_logdump may jump to errout if fopen(out_file) fails, but in that case out_file is NULL, and fclose will segfault.

Thanks, applied.

- Ted

#2 lore raw
In reply to Eric Sandeen
Quoted 2 lines · Eric Sandeen

do_logdump may jump to errout if fopen(out_file) fails, but in that case out_file is NULL, and fclose will segfault.

You should report that segfault to glibc authors too.

#3 lore raw
Quoted 6 lines · Thierry Vignaud
Quoted 2 lines · Eric Sandeen

do_logdump may jump to errout if fopen(out_file) fails, but in that case out_file is NULL, and fclose will segfault.

You should report that segfault to glibc authors too.

It would be robust for glibc to code fclose() defensively such that it would survive a null pointer, but I don't think it's technically required by the ANSI or POSIX spec.

- Ted

#4 lore raw
Quoted 11 lines · Theodore Tso
Quoted 6 lines · Thierry Vignaud
Quoted 2 lines · Eric Sandeen

do_logdump may jump to errout if fopen(out_file) fails, but in that case out_file is NULL, and fclose will segfault.

You should report that segfault to glibc authors too.

It would be robust for glibc to code fclose() defensively such that it would survive a null pointer, but I don't think it's technically required by the ANSI or POSIX spec.

It's the programmer's responsibility to write the following:

if (fp)

	fclose(fp);
Signature · 3 lines
http://www.munted.org.uk

One very high maintenance cat living here.