File claws-mail-dont-overshoot-output-buffer.patch of Package claws-mail.openSUSE_Leap_42.1_Update
X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=blobdiff_plain;f=src%2Fcodeconv.c;h=d0fbf70da2cd4d8622ef07ada35252fd62a2e1e4;hp=f0ed61677072db919f235117263ac208132b26f6;hb=8b2aff884d97dcfe5cc70478fecc7c87ce023c95;hpb=fc42499ce0b3d1dc84914d5b15c9b5d19c904cd9
Index: claws-mail-3.12.0/src/codeconv.c
===================================================================
--- claws-mail-3.12.0.orig/src/codeconv.c
+++ claws-mail-3.12.0/src/codeconv.c
@@ -155,10 +155,14 @@ void codeconv_set_strict(gboolean mode)
static gint conv_jistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf)
{
const guchar *in = inbuf;
- guchar *out = outbuf;
+ gchar *out = outbuf;
JISState state = JIS_ASCII;
- while (*in != '\0') {
+ /*
+ * Loop outputs up to 3 bytes in each pass (aux kanji) and we
+ * need 1 byte to terminate the output
+ */
+ while (*in != '\0' && (out - outbuf) < outlen - 4) {
if (*in == ESC) {
in++;
if (*in == '$') {
@@ -291,10 +295,15 @@ static gint conv_jis_hantozen(guchar *ou
static gint conv_euctojis(gchar *outbuf, gint outlen, const gchar *inbuf)
{
const guchar *in = inbuf;
- guchar *out = outbuf;
+ gchar *out = outbuf;
JISState state = JIS_ASCII;
- while (*in != '\0') {
+ /*
+ * Loop outputs up to 6 bytes in each pass (aux shift + aux
+ * kanji) and we need up to 4 bytes to terminate the output
+ * (ASCII shift + null)
+ */
+ while (*in != '\0' && (out - outbuf) < outlen - 10) {
if (IS_ASCII(*in)) {
K_OUT();
*out++ = *in++;
@@ -380,9 +389,13 @@ static gint conv_euctojis(gchar *outbuf,
static gint conv_sjistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf)
{
const guchar *in = inbuf;
- guchar *out = outbuf;
+ gchar *out = outbuf;
- while (*in != '\0') {
+ /*
+ * Loop outputs up to 2 bytes in each pass and we need 1 byte
+ * to terminate the output
+ */
+ while (*in != '\0' && (out - outbuf) < outlen - 3) {
if (IS_ASCII(*in)) {
*out++ = *in++;
} else if (issjiskanji1(*in)) {