summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-10-15 00:45:16 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-10-21 22:59:34 (GMT)
commit669b963af2778c489b0742d2f4d56aeda7dcfad8 (patch)
tree2f3f5750a702077c5008f6f50ef9a0db8e86414a
parentc6905e45f078530cda57690b0db6a7378dc1f794 (diff)
downloadgit-669b963af2778c489b0742d2f4d56aeda7dcfad8.zip
git-669b963af2778c489b0742d2f4d56aeda7dcfad8.tar.gz
git-669b963af2778c489b0742d2f4d56aeda7dcfad8.tar.bz2
mailinfo: handle charset conversion errors in the caller
Instead of dying in convert_to_utf8(), just report an error and let the callers handle it. Between the two callers: - decode_header() silently punts when it cannot parse a broken RFC2047 encoded text (e.g. when it sees anything other than B or Q after it sees "=?<charset>") by jumping to release_return, returning the string it successfully parsed out so far, to the caller. A piece of string that convert_to_utf8() cannot handle can be treated the same way. - handle_commit_msg() doesn't cope with a malformed line well, so die there for now. We'll lift this even higher in later changes in this series. Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--mailinfo.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/mailinfo.c b/mailinfo.c
index 90adc75..97e5cb8 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -344,21 +344,22 @@ static struct strbuf *decode_b_segment(const struct strbuf *b_seg)
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);
+ 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)
@@ -424,7 +425,8 @@ static void decode_header(struct mailinfo *mi, struct strbuf *it)
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);
@@ -637,7 +639,8 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
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))
+ exit(128);
if (mi->use_scissors && is_scissors_line(line)) {
int i;