git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] detect dup failure
@ 2007-06-27 11:59 Jim Meyering
  2007-06-27 12:48 ` Alex Riesen
  0 siblings, 1 reply; 15+ messages in thread
From: Jim Meyering @ 2007-06-27 11:59 UTC (permalink / raw)
  To: git

Without this, if you ever run out of file descriptors, dup will
fail (silently), fdopen will return NULL, and fprintf will
try to dereference NULL (i.e., usually segfault).

Signed-off-by: Jim Meyering <jim@meyering.net>
---
 builtin-log.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/builtin-log.c b/builtin-log.c
index 073a2a1..ca54387 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -588,8 +588,12 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	if (ignore_if_in_upstream)
 		get_patch_ids(&rev, &ids, prefix);

-	if (!use_stdout)
-		realstdout = fdopen(dup(1), "w");
+	if (!use_stdout) {
+		int fd = dup(1);
+		if (fd < 0)
+			die("failed to duplicate standard output");
+		realstdout = fdopen(fd, "w");
+	}

 	prepare_revision_walk(&rev);
 	while ((commit = get_revision(&rev)) != NULL) {

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2007-06-28  5:02 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-27 11:59 [PATCH] detect dup failure Jim Meyering
2007-06-27 12:48 ` Alex Riesen
2007-06-27 13:02   ` [PATCH] git-log: detect dup and fdopen failure Jim Meyering
2007-06-27 13:18     ` Alex Riesen
2007-06-27 13:32       ` Jim Meyering
2007-06-27 14:04         ` Alex Riesen
2007-06-27 14:14           ` Jim Meyering
2007-06-27 15:57             ` Alex Riesen
2007-06-27 16:34               ` Jim Meyering
2007-06-27 13:54     ` Geert Bosch
2007-06-27 14:06       ` Jim Meyering
2007-06-27 14:28       ` Jim Meyering
2007-06-27 16:49         ` Linus Torvalds
2007-06-28  2:46           ` Josh Triplett
2007-06-28  5:02             ` Shawn O. Pearce

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).