From: Mike Mueller <mmueller@vigilantsw.com>
To: git@vger.kernel.org
Subject: [PATCH] Fix segfault in fast-export
Date: Wed, 6 Jan 2010 22:58:39 -0500 [thread overview]
Message-ID: <20100107035839.GM8510@samus.subfocal.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 1283 bytes --]
Hi all,
I'm working on a C++ static analyzer (Vigilant Sentry), and git
is one of my test subjects. In git-1.6.6, I found a crash in the
fast-export command:
The problem is in builtin-fast-export.c, function export_marks:
f = fopen(file, "w");
if (!f)
error("Unable to open marks file %s for writing.", file);
for (i = 0; i < idnums.size; i++) {
if (deco->base && deco->base->type == 1) {
mark = ptr_to_mark(deco->decoration);
if (fprintf(f, ":%"PRIu32" %s\n", mark,
sha1_to_hex(deco->base->sha1)) < 0) {
e = 1;
break;
}
}
deco++;
}
e |= ferror(f);
e |= fclose(f);
If fopen() fails, the error message is printed, but the function
doesn't exit. The subsequent calls to fprintf and/or ferror will
fail because f is NULL. A simple way to reproduce is to export
to a path you don't have write access to:
$ git fast-export --export-marks=/foo
error: Unable to open marks file /foo for writing.
Segmentation fault (core dumped)
I've attached a trivial patch that calls die_errno instead of
error, so the program exits if f is NULL.
Regards,
Mike
--
Mike Mueller
mmueller@vigilantsw.com
http://www.vigilantsw.com/
[-- Attachment #2: git-fast-export.patch --]
[-- Type: text/x-diff, Size: 449 bytes --]
diff --git a/builtin-fast-export.c b/builtin-fast-export.c
index b0a4029..963e89b 100644
--- a/builtin-fast-export.c
+++ b/builtin-fast-export.c
@@ -503,7 +503,7 @@ static void export_marks(char *file)
f = fopen(file, "w");
if (!f)
- error("Unable to open marks file %s for writing.", file);
+ die_errno("Unable to open marks file %s for writing", file);
for (i = 0; i < idnums.size; i++) {
if (deco->base && deco->base->type == 1) {
next reply other threads:[~2010-01-07 4:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-07 3:58 Mike Mueller [this message]
2010-01-18 17:44 ` [PATCH] Fix segfault in fast-export Heiko Voigt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100107035839.GM8510@samus.subfocal.net \
--to=mmueller@vigilantsw.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox