diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index f0c420976f0f41ea0402a2c20f3f443dd0781b83..97c1ff97440ec107e336df774f86aadc28f26b89 100644 (file)
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
static int decode_q_segment(char *in, char *ot, unsigned otsize, char *ep, int rfc2047)
{
static int decode_q_segment(char *in, char *ot, unsigned otsize, char *ep, int rfc2047)
{
+ char *otbegin = ot;
char *otend = ot + otsize;
int c;
while ((c = *in++) != 0 && (in <= ep)) {
char *otend = ot + otsize;
int c;
while ((c = *in++) != 0 && (in <= ep)) {
@@ -453,13 +454,14 @@ static int decode_q_segment(char *in, char *ot, unsigned otsize, char *ep, int r
*ot++ = c;
}
*ot = 0;
*ot++ = c;
}
*ot = 0;
- return 0;
+ return (ot - otbegin);
}
static int decode_b_segment(char *in, char *ot, unsigned otsize, char *ep)
{
/* Decode in..ep, possibly in-place to ot */
int c, pos = 0, acc = 0;
}
static int decode_b_segment(char *in, char *ot, unsigned otsize, char *ep)
{
/* Decode in..ep, possibly in-place to ot */
int c, pos = 0, acc = 0;
+ char *otbegin = ot;
char *otend = ot + otsize;
while ((c = *in++) != 0 && (in <= ep)) {
char *otend = ot + otsize;
while ((c = *in++) != 0 && (in <= ep)) {
}
}
*ot = 0;
}
}
*ot = 0;
- return 0;
+ return (ot - otbegin);
}
/*
}
/*
convert_to_utf8(it, itsize, "");
}
convert_to_utf8(it, itsize, "");
}
-static void decode_transfer_encoding(char *line, unsigned linesize)
+static int decode_transfer_encoding(char *line, unsigned linesize, int inputlen)
{
char *ep;
switch (transfer_encoding) {
case TE_QP:
{
char *ep;
switch (transfer_encoding) {
case TE_QP:
- ep = line + strlen(line);
- decode_q_segment(line, line, linesize, ep, 0);
- break;
+ ep = line + inputlen;
+ return decode_q_segment(line, line, linesize, ep, 0);
case TE_BASE64:
case TE_BASE64:
- ep = line + strlen(line);
- decode_b_segment(line, line, linesize, ep);
- break;
+ ep = line + inputlen;
+ return decode_b_segment(line, line, linesize, ep);
case TE_DONTCARE:
case TE_DONTCARE:
- break;
+ default:
+ return inputlen;
}
}
}
}
/* process any boundary lines */
if (content_top->boundary && is_multipart_boundary(line)) {
/* flush any leftover */
/* process any boundary lines */
if (content_top->boundary && is_multipart_boundary(line)) {
/* flush any leftover */
- if ((transfer_encoding == TE_BASE64) &&
- (np != newline)) {
+ if (np != newline)
handle_filter(newline, sizeof(newline),
handle_filter(newline, sizeof(newline),
- strlen(newline));
- }
+ np - newline);
if (!handle_boundary())
return;
}
/* Unwrap transfer encoding */
if (!handle_boundary())
return;
}
/* Unwrap transfer encoding */
- decode_transfer_encoding(line, sizeof(line));
+ len = decode_transfer_encoding(line, sizeof(line), len);
+ if (len < 0) {
+ error("Malformed input line");
+ return;
+ }
switch (transfer_encoding) {
case TE_BASE64:
switch (transfer_encoding) {
case TE_BASE64:
break;
}
break;
}
- /* this is a decoded line that may contain
+ /*
+ * This is a decoded line that may contain
* multiple new lines. Pass only one chunk
* at a time to handle_filter()
*/
* multiple new lines. Pass only one chunk
* at a time to handle_filter()
*/
-
do {
do {
- while (*op != '\n' && *op != 0)
+ while (op < line + len && *op != '\n')
*np++ = *op++;
*np = *op;
if (*np != 0) {
*np++ = *op++;
*np = *op;
if (*np != 0) {
rc = handle_filter(newline, sizeof(newline), np - newline);
np = newline;
}
rc = handle_filter(newline, sizeof(newline), np - newline);
np = newline;
}
- } while (*op != 0);
- /* the partial chunk is saved in newline and
- * will be appended by the next iteration of fgets
+ } while (op < line + len);
+ /*
+ * The partial chunk is saved in newline and will be
+ * appended by the next iteration of read_line_with_nul().
*/
break;
}
*/
break;
}
/* NEEDSWORK: might want to do the optional .git/ directory
* discovery
*/
/* NEEDSWORK: might want to do the optional .git/ directory
* discovery
*/
- git_config(git_default_config);
+ git_config(git_default_config, NULL);
def_charset = (git_commit_encoding ? git_commit_encoding : "utf-8");
metainfo_charset = def_charset;
def_charset = (git_commit_encoding ? git_commit_encoding : "utf-8");
metainfo_charset = def_charset;