Browse code

honour StreamMaxLen

git-svn-id: file:///var/lib/svn/clamav-devel/branches/clamd-proto@4705 77e5149b-7576-45b1-b177-96237e5ba77b

aCaB authored on 2009/02/09 00:06:10
Showing 2 changed files
... ...
@@ -66,6 +66,7 @@
66 66
 int notremoved = 0, notmoved = 0;
67 67
 struct sockaddr *mainsa = NULL;
68 68
 int mainsasz;
69
+unsigned long int maxstream;
69 70
 static struct sockaddr_un nixsock;
70 71
 static struct sockaddr_in tcpsock;
71 72
 
... ...
@@ -256,7 +257,7 @@ int client(const struct optstruct *opts, int *infected)
256 256
 {
257 257
 	const char *clamd_conf = optget(opts, "config-file")->strarg;
258 258
 	struct optstruct *clamdopts;
259
-	int remote, scantype, session = 0, errors = 0, scandash = 0, maxrec, maxstream;
259
+	int remote, scantype, session = 0, errors = 0, scandash = 0, maxrec;
260 260
 
261 261
     if((clamdopts = optparse(clamd_conf, 0, NULL, 1, OPT_CLAMD, 0, NULL)) == NULL) {
262 262
 	logg("!Can't parse clamd configuration file %s\n", clamd_conf);
... ...
@@ -38,6 +38,7 @@
38 38
 
39 39
 extern struct sockaddr *mainsa;
40 40
 extern int mainsasz;
41
+extern unsigned long int maxstream;
41 42
 int printinfected;
42 43
 extern void (*action)(const char *);
43 44
 
... ...
@@ -149,6 +150,7 @@ int recvln(struct RCVLN *s, char **rbol, char **reol) {
149 149
 static int send_stream(int sockd, const char *filename) {
150 150
     uint32_t buf[BUFSIZ/sizeof(uint32_t)];
151 151
     int fd, len;
152
+    unsigned int todo = maxstream;
152 153
 
153 154
     if(filename) {
154 155
 	if((fd = open(filename, O_RDONLY))<0) {
... ...
@@ -160,12 +162,18 @@ static int send_stream(int sockd, const char *filename) {
160 160
     if(sendln(sockd, "zINSTREAM", 10)) return 1;
161 161
 
162 162
     while((len = read(fd, &buf[1], sizeof(buf) - sizeof(uint32_t))) > 0) {
163
+	if((unsigned int)len > todo) len = todo;
163 164
 	buf[0] = htonl(len);
164 165
 	if(sendln(sockd, (const char *)buf, len+sizeof(uint32_t))) { /* FIXME: need to handle limits */
165 166
 	    logg("!Can't write to the socket.\n");
166 167
 	    close(fd);
167 168
 	    return 1;
168 169
 	}
170
+	todo -= len;
171
+	if(!todo) {
172
+	    len = 0;
173
+	    break;
174
+	}
169 175
     }
170 176
     close(fd);
171 177
     if(len) {