1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
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
|