Browse code

clamdscan - check that the TCPAddr parameter is enabled before using.

Steven Morgan authored on 2016/12/15 08:12:37
Showing 1 changed files
... ...
@@ -96,38 +96,39 @@ int dconnect() {
96 96
 
97 97
     opt = optget(clamdopts, "TCPAddr");
98 98
     while (opt) {
99
-        ipaddr = NULL;
100
-        if (opt->strarg)
101
-            ipaddr = (!strcmp(opt->strarg, "any") ? NULL : opt->strarg);
102
-
103
-        memset(&hints, 0x00, sizeof(struct addrinfo));
104
-        hints.ai_family = AF_UNSPEC;
105
-        hints.ai_socktype = SOCK_STREAM;
106
-
107
-        if ((res = getaddrinfo(ipaddr, port, &hints, &info))) {
108
-            logg("!Could not lookup %s: %s\n", ipaddr ? ipaddr : "", gai_strerror(res));
109
-            opt = opt->nextarg;
110
-            continue;
111
-        }
112
-
113
-        for (p = info; p != NULL; p = p->ai_next) {
114
-            if((sockd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) < 0) {
115
-                logg("!Can't create the socket: %s\n", strerror(errno));
99
+        if (opt->enabled) {
100
+            ipaddr = NULL;
101
+            if (opt->strarg)
102
+                ipaddr = (!strcmp(opt->strarg, "any") ? NULL : opt->strarg);
103
+
104
+            memset(&hints, 0x00, sizeof(struct addrinfo));
105
+            hints.ai_family = AF_UNSPEC;
106
+            hints.ai_socktype = SOCK_STREAM;
107
+
108
+            if ((res = getaddrinfo(ipaddr, port, &hints, &info))) {
109
+                logg("!Could not lookup %s: %s\n", ipaddr ? ipaddr : "", gai_strerror(res));
110
+                opt = opt->nextarg;
116 111
                 continue;
117 112
             }
118 113
 
119
-            if(connect(sockd, p->ai_addr, p->ai_addrlen) < 0) {
120
-                logg("!Could not connect to clamd on %s: %s\n", opt->strarg, strerror(errno));
121
-                closesocket(sockd);
122
-                continue;
114
+            for (p = info; p != NULL; p = p->ai_next) {
115
+                if((sockd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) < 0) {
116
+                    logg("!Can't create the socket: %s\n", strerror(errno));
117
+                    continue;
118
+                }
119
+
120
+                if(connect(sockd, p->ai_addr, p->ai_addrlen) < 0) {
121
+                    logg("!Could not connect to clamd on %s: %s\n", opt->strarg, strerror(errno));
122
+                    closesocket(sockd);
123
+                    continue;
124
+                }
125
+
126
+                freeaddrinfo(info);
127
+                return sockd;
123 128
             }
124 129
 
125 130
             freeaddrinfo(info);
126
-            return sockd;
127 131
         }
128
-
129
-        freeaddrinfo(info);
130
-
131 132
         opt = opt->nextarg;
132 133
     }
133 134