From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH] Limit filename for format-patch
Date: Fri, 23 Feb 2007 22:47:26 +0100 [thread overview]
Message-ID: <20070223214631.24544.96597.stgit@lathund.dewire.com> (raw)
In-Reply-To: <200702232239.19504.robin.rosenberg@dewire.com>
Badly formatted commits may have very long comments. This causes
git-format-patch to fail. To avoid that, truncate the filename
to a value we believe will always work.
Err out if the patch file cannot be created.
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
Same as previous patch minus one strlen.
builtin-log.c | 22 ++++++++++++++++------
1 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index ad1e8c0..5afd772 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -264,15 +264,17 @@ static int git_format_config(const char *var, const char *value)
static FILE *realstdout = NULL;
static const char *output_directory = NULL;
-static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
+static int reopen_stdout(struct commit *commit, int nr, int keep_subject)
{
- char filename[1024];
+ char filename[PATH_MAX];
char *sol;
int len = 0;
- int suffix_len = strlen(fmt_patch_suffix) + 10; /* ., NUL and slop */
+ int suffix_len = strlen(fmt_patch_suffix) + 1;
if (output_directory) {
- strlcpy(filename, output_directory, 1000);
+ if (strlen(output_directory) > sizeof filename - suffix_len)
+ return error("name of output directory is too long");
+ strlcpy(filename, output_directory, sizeof filename - suffix_len);
len = strlen(filename);
if (filename[len - 1] != '/')
filename[len++] = '/';
@@ -297,6 +299,7 @@ static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
}
for (j = 0;
+ j< 64-suffix_len-5 &&
len < sizeof(filename) - suffix_len &&
sol[j] && sol[j] != '\n';
j++) {
@@ -314,10 +317,16 @@ static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
}
while (filename[len - 1] == '.' || filename[len - 1] == '-')
len--;
+ filename[len] = 0;
}
+ if (len + suffix_len >= sizeof filename)
+ return error("Patch pathname too long");
strcpy(filename + len, fmt_patch_suffix);
fprintf(realstdout, "%s\n", filename);
- freopen(filename, "w", stdout);
+ if (freopen(filename, "w", stdout) == NULL)
+ return error("Cannot open patch file %s",filename);
+ return 0;
+
}
static int get_patch_id(struct commit *commit, struct diff_options *options,
@@ -573,7 +582,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
rev.message_id = message_id;
}
if (!use_stdout)
- reopen_stdout(commit, rev.nr, keep_subject);
+ if (reopen_stdout(commit, rev.nr, keep_subject))
+ die("Failed to create output files");
shown = log_tree_commit(&rev, commit);
free(commit->buffer);
commit->buffer = NULL;
next prev parent reply other threads:[~2007-02-23 21:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-23 0:37 [PATCH] Limit filename for format-patch Robin Rosenberg
2007-02-23 0:49 ` Johannes Schindelin
2007-02-23 21:39 ` Robin Rosenberg
2007-02-23 21:47 ` Robin Rosenberg [this message]
2007-02-23 22:27 ` Robin Rosenberg
2007-02-24 1:27 ` Johannes Schindelin
2007-02-24 1:33 ` Junio C Hamano
2007-02-24 8:51 ` Junio C Hamano
2007-02-24 11:24 ` Robin Rosenberg
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=20070223214631.24544.96597.stgit@lathund.dewire.com \
--to=robin.rosenberg@dewire.com \
--cc=Johannes.Schindelin@gmx.de \
--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;
as well as URLs for NNTP newsgroup(s).