Better fix for buffer overrun
authorColin Leroy <colin@colino.net>
Fri, 13 Nov 2015 08:46:16 +0000 (09:46 +0100)
committerColin Leroy <colin@colino.net>
Fri, 13 Nov 2015 08:46:16 +0000 (09:46 +0100)
src/plugins/clamd/libclamd/clamd-plugin.c

index dd61481..d2e725a 100644 (file)
@@ -368,8 +368,7 @@ Clamd_Stat clamd_init(Clamd_Socket* config) {
                return NO_CONNECTION;
        }
        memset(buf, '\0', sizeof(buf));
                return NO_CONNECTION;
        }
        memset(buf, '\0', sizeof(buf));
-       while ((n_read = read(sock, buf, BUFSIZ)) > 0) {
-               n_read = n_read < BUFSIZ ? n_read : BUFSIZ - 1;
+       while ((n_read = read(sock, buf, BUFSIZ - 1)) > 0) {
                buf[n_read] = '\0';
                if (buf[strlen(buf) - 1] == '\n')
                        buf[strlen(buf) - 1] = '\0';
                buf[n_read] = '\0';
                if (buf[strlen(buf) - 1] == '\n')
                        buf[strlen(buf) - 1] = '\0';
@@ -526,8 +525,7 @@ Clamd_Stat clamd_verify_email(const gchar* path, response* result) {
                }
                g_free(command);
                memset(buf, '\0', sizeof(buf));
                }
                g_free(command);
                memset(buf, '\0', sizeof(buf));
-               while ((n_read = read(sock, buf, BUFSIZ)) > 0) {
-                       n_read = n_read < BUFSIZ ? n_read : BUFSIZ - 1;
+               while ((n_read = read(sock, buf, BUFSIZ - 1)) > 0) {
                        buf[n_read] = '\0';
                        if (buf[strlen(buf) - 1] == '\n')
                                buf[strlen(buf) - 1] = '\0';
                        buf[n_read] = '\0';
                        if (buf[strlen(buf) - 1] == '\n')
                                buf[strlen(buf) - 1] = '\0';