commit 76181fd: [Minor] Another uuencode fix

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Oct 25 19:28:08 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-10-25 20:26:32 +0100
URL: https://github.com/rspamd/rspamd/commit/76181fd6823a644c2670b36341915ad51e804eb2 (HEAD -> master)

[Minor] Another uuencode fix

---
 src/libutil/str_util.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c
index d1f2cbfe6..866ef52d8 100644
--- a/src/libutil/str_util.c
+++ b/src/libutil/str_util.c
@@ -2206,8 +2206,8 @@ rspamd_decode_uue_buf (const gchar *in, gsize inlen,
 	const gchar *p;
 	gssize remain;
 	gboolean base64 = FALSE;
-	goffset newlines_fsm[3], pos;
-	static const gchar *nline = "\r\n";
+	goffset pos;
+	const gchar *nline = "\r\n";
 
 	p = in;
 	o = out;
@@ -2224,29 +2224,24 @@ rspamd_decode_uue_buf (const gchar *in, gsize inlen,
 		return -1;
 	}
 
-	rspamd_substring_preprocess_kmp (nline, 2, newlines_fsm,
-			rspamd_substring_cmp_func);
-
 	if (memcmp (p, "begin ", sizeof ("begin ") - 1) == 0) {
 		p += sizeof ("begin ") - 1;
 		remain -= sizeof ("begin ") - 1;
 
-		pos = rspamd_substring_search_preprocessed (p, remain, nline, 2,
-		 		newlines_fsm, rspamd_substring_cmp_func);
+		pos = rspamd_memcspn (p, nline, remain);
 	}
 	else if (memcmp (p, "begin-base64 ", sizeof ("begin-base64 ") - 1) == 0) {
 		base64 = TRUE;
 		p += sizeof ("begin-base64 ") - 1;
 		remain -= sizeof ("begin-base64 ") - 1;
-		pos = rspamd_substring_search_preprocessed (p, remain, nline, 2,
-				newlines_fsm, rspamd_substring_cmp_func);
+		pos = rspamd_memcspn (p, nline, remain);
 	}
 	else {
 		/* Crap */
 		return (-1);
 	}
 
-	if (pos == -1) {
+	if (pos == -1 || remain == 0) {
 		/* Crap */
 		return (-1);
 	}
@@ -2274,12 +2269,15 @@ rspamd_decode_uue_buf (const gchar *in, gsize inlen,
 		const gchar *eol;
 		gint i, ch;
 
-		pos = rspamd_substring_search_preprocessed (p, remain, nline, 2,
-				newlines_fsm, rspamd_substring_cmp_func);
+		pos = rspamd_memcspn (p, nline, remain);
+
+		if (pos == 0) {
+			/* Skip empty lines */
+			SKIP_NEWLINE;
 
-		if (pos == -1) {
-			/* Assume end of buffer */
-			pos = remain;
+			if (remain == 0) {
+				break;
+			}
 		}
 
 		eol = p + pos;


More information about the Commits mailing list