[Commits] [SCM] claws branch, master, updated. 3.16.0-92-g86b4d2c

wwp at claws-mail.org wwp at claws-mail.org
Sat Mar 17 20:02:58 CET 2018


The branch, master has been updated
       via  86b4d2c073e7346b591f9270352d772b288f24a7 (commit)
      from  f4cb29891be3d0a74191064680ddade59344c076 (commit)

Summary of changes:
 src/plugins/clamd/libclamd/clamd-plugin.c |   32 +++++++++++++++++------------
 1 file changed, 19 insertions(+), 13 deletions(-)


- Log -----------------------------------------------------------------
commit 86b4d2c073e7346b591f9270352d772b288f24a7
Author: wwp <wwp at free.fr>
Date:   Sat Mar 17 20:02:48 2018 +0100

    Few optimizations: avoid strlen when string length is known (read()>0 return);
    end string at real end of string instead of at buffer boundary and
    be sure we print 0-terminated string (clamd_stream_scan());
    clamd_verify_email: discover a strange multi-line response, be sure we
    print 0-terminated string (CID 1220483), debug_print all response lines.

diff --git a/src/plugins/clamd/libclamd/clamd-plugin.c b/src/plugins/clamd/libclamd/clamd-plugin.c
index 23358e5..314f626 100644
--- a/src/plugins/clamd/libclamd/clamd-plugin.c
+++ b/src/plugins/clamd/libclamd/clamd-plugin.c
@@ -389,8 +389,8 @@ Clamd_Stat clamd_init(Clamd_Socket* config) {
 	memset(buf, '\0', sizeof(buf));
 	while ((n_read = read(sock, buf, BUFSIZ - 1)) > 0) {
 		buf[n_read] = '\0';
-		if (buf[strlen(buf) - 1] == '\n')
-			buf[strlen(buf) - 1] = '\0';
+		if (buf[n_read - 1] == '\n')
+			buf[n_read - 1] = '\0';
 		debug_print("Ping result: %s\n", buf);
 		if (strcmp("PONG", buf) == 0)
 			connect = TRUE;
@@ -407,10 +407,10 @@ Clamd_Stat clamd_init(Clamd_Socket* config) {
 	    return NO_CONNECTION;
 	}
 	memset(buf, '\0', sizeof(buf));
-        while ((n_read = read(sock, buf, BUFSIZ - 1)) > 0) {
-	    buf[n_read] = '\0';
-	    if (buf[strlen(buf) - 1] == '\n')
-		buf[strlen(buf) - 1] = '\0';
+	while ((n_read = read(sock, buf, BUFSIZ - 1)) > 0) {
+		buf[n_read] = '\0';
+		if (buf[n_read - 1] == '\n')
+			buf[n_read - 1] = '\0';
 	    debug_print("Version: %s\n", buf);
 	}
 	close(sock);
@@ -462,10 +462,9 @@ static Clamd_Stat clamd_stream_scan(int sock,
 	}
 
 	while ((count = read(fd, (void *) buf, sizeof(buf))) > 0) {
-		buf[sizeof(buf) - 1] = '\0';
-		if (buf[strlen(buf) - 1] == '\n')
-			buf[strlen(buf) - 1] = '\0';
-		debug_print("read: %ld bytes\n", count);
+		buf[count] = '\0';
+		if (buf[count - 1] == '\n')
+			buf[count - 1] = '\0';
 		
 		debug_print("chunk size: %ld\n", count);
 		chunk = htonl(count);
@@ -500,6 +499,7 @@ static Clamd_Stat clamd_stream_scan(int sock,
 		*res = g_strconcat("ERROR -> ", _("Socket read error"), NULL);
 		return SCAN_ERROR;
 	}
+	res[n_read] = '\0';
 	debug_print("received: %s\n", *res);
 	return OK;
 }
@@ -534,6 +534,7 @@ Clamd_Stat clamd_verify_email(const gchar* path, response* result) {
 		debug_print("copy to buf: %s\n", tmp);
 		memcpy(&buf, tmp, BUFSIZ);
 		g_free(tmp);
+		debug_print("response: %s\n", buf);
 	}
 	else {
 		command = g_strconcat(scan, " ", path, "\n", NULL);
@@ -545,13 +546,18 @@ Clamd_Stat clamd_verify_email(const gchar* path, response* result) {
 		}
 		g_free(command);
 		memset(buf, '\0', sizeof(buf));
+		/* shouldn't we read only once here? we're checking the last response line anyway */
 		while ((n_read = read(sock, buf, BUFSIZ - 1)) > 0) {
 			buf[n_read] = '\0';
-			if (buf[strlen(buf) - 1] == '\n')
-				buf[strlen(buf) - 1] = '\0';
+			if (buf[n_read - 1] == '\n')
+				buf[n_read - 1] = '\0';
+			debug_print("response: %s\n", buf);
+		}
+		if (n_read == 0) {
+			buf[n_read] = '\0';
+			debug_print("response: %s\n", buf);
 		}
 	}
-	debug_print("response: %s\n", buf);
 	if (strstr(buf, "ERROR")) {
 		stat = SCAN_ERROR;
 		result->msg = g_strdup(buf);

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list