Fix overflow
[claws.git] / src / plugins / clamd / libclamd / clamd-plugin.c
index 80bf1e91c6c3cb570a57487fbc89080d904bf39c..10bec446a6cb1804765ff590a2df530ee0f61f55 100644 (file)
@@ -285,7 +285,7 @@ static int create_socket() {
        struct sockaddr_in addr_i;
        struct hostent *hp;
 
-       int new_sock;
+       int new_sock = -1;
 
        /*debug_set_mode(TRUE);*/
        if (! Socket) {
@@ -368,7 +368,8 @@ Clamd_Stat clamd_init(Clamd_Socket* config) {
                return NO_CONNECTION;
        }
        memset(buf, '\0', sizeof(buf));
-       while ((n_read = read(sock, buf, BUFSIZ)) > 0) {
+       while ((n_read = read(sock, buf, BUFSIZ - 1)) > 0) {
+               buf[n_read] = '\0';
                if (buf[strlen(buf) - 1] == '\n')
                        buf[strlen(buf) - 1] = '\0';
                debug_print("Ping result: %s\n", buf);
@@ -387,8 +388,8 @@ Clamd_Stat clamd_init(Clamd_Socket* config) {
            return NO_CONNECTION;
        }
        memset(buf, '\0', sizeof(buf));
-        while ((n_read = read(sock, buf, sizeof(buf))) > 0) {
-           buf[sizeof(buf) - 1] = '\0';
+        while ((n_read = read(sock, buf, BUFSIZ - 1)) > 0) {
+           buf[n_read] = '\0';
            if (buf[strlen(buf) - 1] == '\n')
                buf[strlen(buf) - 1] = '\0';
            debug_print("Version: %s\n", buf);
@@ -524,8 +525,8 @@ Clamd_Stat clamd_verify_email(const gchar* path, response* result) {
                }
                g_free(command);
                memset(buf, '\0', sizeof(buf));
-               while ((n_read = read(sock, buf, BUFSIZ)) > 0) {
-                       buf[sizeof(buf) - 1] = '\0';
+               while ((n_read = read(sock, buf, BUFSIZ - 1)) > 0) {
+                       buf[n_read] = '\0';
                        if (buf[strlen(buf) - 1] == '\n')
                                buf[strlen(buf) - 1] = '\0';
                }
@@ -573,7 +574,7 @@ GSList* clamd_verify_dir(const gchar* path) {
        }
        g_free(command);
        memset(buf, '\0', sizeof(buf));
-       while ((n_read = read(sock, buf, BUFSIZ)) > 0) {
+       while ((n_read = read(sock, buf, BUFSIZ - 1)) > 0) {
                gchar** tmp = g_strsplit(buf, "\n", 0);
                gchar** head = tmp;
                while (*tmp) {