summaryrefslogblamecommitdiffstats
path: root/0007-Fix-gconv-assert-overlap-buffers-121.patch
blob: c5821345e19eaacc42e7f49de90e8648e0ec647f (plain) (tree)




































































                                                                                               
From 4ebbd6a1c3bcf5a1240413d1447ecf2f1699fc7b Mon Sep 17 00:00:00 2001
From: Georg Sauthoff <mail@georg.so>
Date: Fri, 8 Feb 2019 10:54:46 +0100
Subject: [PATCH 07/11] Fix gconv assert overlap buffers (#121)

cf. https://sourceforge.net/p/bogofilter/bugs/121/
---
 src/iconvert.c | 7 ++++++-
 src/lexer.c    | 4 +++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/iconvert.c b/src/iconvert.c
index 731ce03..14585b4 100644
--- a/src/iconvert.c
+++ b/src/iconvert.c
@@ -31,7 +31,7 @@ AUTHOR:
 
 #include <stdlib.h>
 #include <errno.h>
-
+#include <assert.h>
 #include "buff.h"
 #include "iconvert.h"
 
@@ -163,6 +163,9 @@ static void convert(iconv_t xd, buff_t *restrict src, buff_t *restrict dst)
 		break;
 
 	    default:
+                // Linux man page states that other error codes may occur
+                // thus, safer to leave that loop on unknown error, right?
+		done = true;
 		break;
 	    }
 	}
@@ -190,6 +193,7 @@ static void copy(buff_t *restrict src, buff_t *restrict dst)
 
 void iconvert(buff_t *restrict src, buff_t *restrict dst)
 {
+    assert(src->t.u.text != dst->t.u.text);
     if (cd == NULL)
 	copy(src, dst);
     else
@@ -198,6 +202,7 @@ void iconvert(buff_t *restrict src, buff_t *restrict dst)
 
 void iconvert_cd(iconv_t xd, buff_t *restrict src, buff_t *restrict dst)
 {
+    assert(src->t.u.text != dst->t.u.text);
     if (xd == (iconv_t)-1)
 	copy(src, dst);
     else
diff --git a/src/lexer.c b/src/lexer.c
index ba58d25..0e3e7c7 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -231,8 +231,10 @@ static int get_decoded_line(buff_t *buff)
 	 * a message truncation which we try to avoid by simply
 	 * returning the original input buffer (which has positive
 	 * length) instead. */
-	if(buff->t.leng == 0)
+	if(buff->t.leng == 0) {
 	    memcpy(buff, linebuff, sizeof(*buff));
+            *linebuff = (const buff_t){0};
+        }
 
 	/*
 	 * iconvert, treating multi-byte sequences, can shrink or enlarge
-- 
2.20.1