if (slurp_attr(line->buf, "boundary=", boundary)) {
strbuf_insert(boundary, 0, "--", 2);
if (++mi->content_top >= &mi->content[MAX_BOUNDARIES]) {
- fprintf(stderr, "Too many boundaries to handle\n");
- exit(1);
+ error("Too many boundaries to handle");
+ mi->input_error = -1;
+ mi->content_top = &mi->content[MAX_BOUNDARIES] - 1;
+ return;
}
*(mi->content_top) = boundary;
boundary = NULL;
return out;
}
-static void convert_to_utf8(struct mailinfo *mi,
- struct strbuf *line, const char *charset)
+static int convert_to_utf8(struct mailinfo *mi,
+ struct strbuf *line, const char *charset)
{
char *out;
if (!mi->metainfo_charset || !charset || !*charset)
- return;
+ return 0;
if (same_encoding(mi->metainfo_charset, charset))
- return;
+ return 0;
out = reencode_string(line->buf, mi->metainfo_charset, charset);
- if (!out)
- die("cannot convert from %s to %s",
- charset, mi->metainfo_charset);
+ if (!out) {
+ mi->input_error = -1;
+ return error("cannot convert from %s to %s",
+ charset, mi->metainfo_charset);
+ }
strbuf_attach(line, out, strlen(out), strlen(out));
+ return 0;
}
static void decode_header(struct mailinfo *mi, struct strbuf *it)
char *in, *ep, *cp;
struct strbuf outbuf = STRBUF_INIT, *dec;
struct strbuf charset_q = STRBUF_INIT, piecebuf = STRBUF_INIT;
+ int found_error = 1; /* pessimism */
in = it->buf;
while (in - it->buf <= it->len && (ep = strstr(in, "=?")) != NULL) {
dec = decode_q_segment(&piecebuf, 1);
break;
}
- convert_to_utf8(mi, dec, charset_q.buf);
+ if (convert_to_utf8(mi, dec, charset_q.buf))
+ goto release_return;
strbuf_addbuf(&outbuf, dec);
strbuf_release(dec);
strbuf_addstr(&outbuf, in);
strbuf_reset(it);
strbuf_addbuf(it, &outbuf);
+ found_error = 0;
release_return:
strbuf_release(&outbuf);
strbuf_release(&charset_q);
strbuf_release(&piecebuf);
+
+ if (found_error)
+ mi->input_error = -1;
}
static int check_header(struct mailinfo *mi,
mi->header_stage = 0;
/* normalize the log message to UTF-8. */
- convert_to_utf8(mi, line, mi->charset.buf);
+ if (convert_to_utf8(mi, line, mi->charset.buf))
+ return 0; /* mi->input_error already set */
if (mi->use_scissors && is_scissors_line(line)) {
int i;
will fail first. But just in case..
*/
if (--mi->content_top < mi->content) {
- fprintf(stderr, "Detected mismatched boundaries, "
- "can't recover\n");
- exit(1);
+ error("Detected mismatched boundaries, can't recover");
+ mi->input_error = -1;
+ mi->content_top = mi->content;
+ return 0;
}
handle_filter(mi, &newline);
strbuf_release(&newline);
+ if (mi->input_error)
+ return 0;
/* skip to the next boundary */
if (!find_boundary(mi, line))
handle_filter(mi, line);
}
+ if (mi->input_error)
+ break;
} while (!strbuf_getwholeline(line, mi->input, '\n'));
handle_body_out:
handle_info(mi);
strbuf_release(&line);
- return 0;
+ return mi->input_error;
}
static int git_mailinfo_config(const char *var, const char *value, void *mi_)
mi->header_stage = 1;
mi->use_inbody_headers = 1;
mi->content_top = mi->content;
- git_config(git_mailinfo_config, &mi);
+ git_config(git_mailinfo_config, mi);
}
void clear_mailinfo(struct mailinfo *mi)