diff mbox

debugfs: don't try to fclose NULL

Message ID 4A451A23.20307@redhat.com
State Accepted, archived
Headers show

Commit Message

Eric Sandeen June 26, 2009, 6:57 p.m. UTC
do_logdump may jump to errout if fopen(out_file) fails, 
but in that case out_file is NULL, and fclose will segfault.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---


--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Theodore Ts'o June 29, 2009, 5:07 a.m. UTC | #1
On Fri, Jun 26, 2009 at 01:57:39PM -0500, Eric Sandeen wrote:
> do_logdump may jump to errout if fopen(out_file) fails, 
> but in that case out_file is NULL, and fclose will segfault.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Thanks, applied.


					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Thierry Vignaud June 30, 2009, 3:44 p.m. UTC | #2
Eric Sandeen <sandeen@redhat.com> writes:

> 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.
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Theodore Ts'o June 30, 2009, 4:39 p.m. UTC | #3
On Tue, Jun 30, 2009 at 05:44:55PM +0200, Thierry Vignaud wrote:
> Eric Sandeen <sandeen@redhat.com> writes:
> 
> > 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
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alex Buell June 30, 2009, 4:46 p.m. UTC | #4
On Tue, 2009-06-30 at 12:39 -0400, Theodore Tso wrote:
> On Tue, Jun 30, 2009 at 05:44:55PM +0200, Thierry Vignaud wrote:
> > Eric Sandeen <sandeen@redhat.com> writes:
> > 
> > > 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);
diff mbox

Patch

diff --git a/debugfs/logdump.c b/debugfs/logdump.c
index 4818bc6..9a7108a 100644
--- a/debugfs/logdump.c
+++ b/debugfs/logdump.c
@@ -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;