Browse code

fix some warnings

git-svn: trunk@3278

Tomasz Kojm authored on 2007/10/08 23:43:32
Showing 5 changed files
... ...
@@ -1,3 +1,7 @@
1
+Mon Oct  8 15:44:59 CEST 2007 (tk)
2
+----------------------------------
3
+  * clamdscan, freshclam: fix some warnings
4
+
1 5
 Mon Oct  8 14:09:05 CEST 2007 (tk)
2 6
 ----------------------------------
3 7
   * freshclam/freshclam.c: add support for LogFileMaxSize and LogTime
... ...
@@ -183,11 +183,6 @@ static int dsfd(int sockfd, int fd, const struct optstruct *opt)
183 183
     }
184 184
     return dsresult(sockfd, opt);
185 185
 }
186
-#else
187
-static int dsfd(int sockfd, int fd, const struct optstruct *opt)
188
-{
189
-    return -1;
190
-}
191 186
 #endif
192 187
 
193 188
 static int dsstream(int sockd, const struct optstruct *opt)
... ...
@@ -195,7 +190,7 @@ static int dsstream(int sockd, const struct optstruct *opt)
195 195
 	int wsockd, loopw = 60, bread, port, infected = 0;
196 196
 	struct sockaddr_in server;
197 197
 	struct sockaddr_in peer;
198
-	int peer_size;
198
+	socklen_t peer_size;
199 199
 	char buff[4096], *pt;
200 200
 
201 201
 
... ...
@@ -206,11 +201,12 @@ static int dsstream(int sockd, const struct optstruct *opt)
206 206
 
207 207
     while(loopw) {
208 208
 	memset(buff, 0, sizeof(buff));
209
-	read(sockd, buff, sizeof(buff));
210
-	if((pt = strstr(buff, "PORT"))) {
211
-	    pt += 5;
212
-	    sscanf(pt, "%d", &port);
213
-	    break;
209
+	if(read(sockd, buff, sizeof(buff)) > 0) {
210
+	    if((pt = strstr(buff, "PORT"))) {
211
+		pt += 5;
212
+		sscanf(pt, "%d", &port);
213
+		break;
214
+	    }
214 215
 	}
215 216
 	loopw--;
216 217
     }
... ...
@@ -312,7 +308,8 @@ static int dconnect(const struct optstruct *opt)
312 312
 	struct sockaddr_un server;
313 313
 	struct sockaddr_in server2;
314 314
 	struct hostent *he;
315
-	struct cfgstruct *copt, *cpt;
315
+	struct cfgstruct *copt;
316
+	const struct cfgstruct *cpt;
316 317
 	const char *clamav_conf = opt_arg(opt, "config-file");
317 318
 	int sockd;
318 319
 
... ...
@@ -498,8 +495,9 @@ int client(const struct optstruct *opt, int *infected)
498 498
 
499 499
 void move_infected(const char *filename, const struct optstruct *opt)
500 500
 {
501
-	char *movedir, *movefilename, *tmp, numext[4 + 1];
502
-	struct stat fstat, mfstat;
501
+	char *movedir, *movefilename, numext[4 + 1];
502
+	const char *tmp;
503
+	struct stat ofstat, mfstat;
503 504
 	int n, len, movefilename_size;
504 505
 	int moveflag = opt_check(opt, "move");
505 506
 	struct utimbuf ubuf;
... ...
@@ -519,7 +517,7 @@ void move_infected(const char *filename, const struct optstruct *opt)
519 519
         return;
520 520
     }
521 521
 
522
-    if(stat(filename, &fstat) == -1) {
522
+    if(stat(filename, &ofstat) == -1) {
523 523
         logg("^Can't stat file %s\n", filename);
524 524
 	logg("Try to run clamdscan with clamd privileges\n");
525 525
         notmoved++;
... ...
@@ -527,7 +525,7 @@ void move_infected(const char *filename, const struct optstruct *opt)
527 527
     }
528 528
 
529 529
     if(!(tmp = strrchr(filename, '/')))
530
-	tmp = (char *) filename;
530
+	tmp = filename;
531 531
 
532 532
     movefilename_size = sizeof(char) * (strlen(movedir) + strlen(tmp) + sizeof(numext) + 2);
533 533
 
... ...
@@ -553,7 +551,7 @@ void move_infected(const char *filename, const struct optstruct *opt)
553 553
     }
554 554
 
555 555
     if(!stat(movefilename, &mfstat)) {
556
-        if(fstat.st_ino == mfstat.st_ino) { /* It's the same file*/
556
+        if(ofstat.st_ino == mfstat.st_ino) { /* It's the same file*/
557 557
             logg("File excluded '%s'\n", filename);
558 558
             notmoved++;
559 559
             free(movefilename);
... ...
@@ -585,11 +583,12 @@ void move_infected(const char *filename, const struct optstruct *opt)
585 585
 	    return;
586 586
 	}
587 587
 
588
-	chmod(movefilename, fstat.st_mode);
589
-	chown(movefilename, fstat.st_uid, fstat.st_gid);
588
+	chmod(movefilename, ofstat.st_mode);
589
+	if(chown(movefilename, ofstat.st_uid, ofstat.st_gid) == -1)
590
+	    logg("^chown() failed for %s: %s\n", movefilename, strerror(errno));
590 591
 
591
-	ubuf.actime = fstat.st_atime;
592
-	ubuf.modtime = fstat.st_mtime;
592
+	ubuf.actime = ofstat.st_atime;
593
+	ubuf.modtime = ofstat.st_mtime;
593 594
 	utime(movefilename, &ubuf);
594 595
 
595 596
 	if(moveflag && unlink(filename)) {
... ...
@@ -565,11 +565,14 @@ int main(int argc, char **argv)
565 565
 
566 566
     if(opt_check(opt, "on-error-execute")) {
567 567
 	if(ret > 1)
568
-	    system(opt_arg(opt, "on-error-execute"));
568
+	    if(system(opt_arg(opt, "on-error-execute")) == -1)
569
+		logg("!system(%s) failed\n", opt_arg(opt, "on-error-execute"));
569 570
 
570 571
     } else if((cpt = cfgopt(copt, "OnErrorExecute"))->enabled) {
571 572
 	if(ret > 1)
572
-	    system(cpt->strarg);
573
+	    if(system(cpt->strarg) == -1)
574
+		logg("!system(%s) failed\n", cpt->strarg);
575
+
573 576
     }
574 577
     if (pidfile) {
575 578
         unlink(pidfile);
... ...
@@ -1254,8 +1254,8 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c
1254 1254
 	if(arg) {
1255 1255
 	    if(opt_check(opt, "daemon"))
1256 1256
 		execute("OnUpdateExecute", arg);
1257
-            else
1258
-		system(arg);
1257
+            else if(system(arg) == -1)
1258
+		logg("!system(%s) failed\n", arg);
1259 1259
 	}
1260 1260
     }
1261 1261
 
... ...
@@ -1303,8 +1303,8 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c
1303 1303
 	    if(newver) {
1304 1304
 		if(opt_check(opt, "daemon"))
1305 1305
 		    execute("OnOutdatedExecute", cmd);
1306
-		else
1307
-		    system(cmd);
1306
+		else if(system(cmd) == -1)
1307
+		logg("!system(%s) failed\n", cmd);
1308 1308
 	    }
1309 1309
 	    free(cmd);
1310 1310
 	}
... ...
@@ -174,7 +174,7 @@ int logg(const char *str, ...)
174 174
 
175 175
 	if(logg_size) {
176 176
 	    if(stat(logg_file, &sb) != -1) {
177
-		if(sb.st_size > logg_size) {
177
+		if((unsigned int) sb.st_size > logg_size) {
178 178
 		    logg_file = NULL;
179 179
 		    fprintf(logg_fd, "Log size = %u, max = %u\n", (unsigned int) sb.st_size, logg_size);
180 180
 		    fprintf(logg_fd, "LOGGING DISABLED (Maximal log file size exceeded).\n");