From d8dcfe2ec2bb0d1815caae3d6a7e4928dc226363 Mon Sep 17 00:00:00 2001 From: Tomasz Kojm Date: Tue, 27 Oct 2009 23:33:43 +0100 Subject: [PATCH] clamdscan: improve error handling (bb#1729) --- ChangeLog | 4 ++++ clamdscan/client.c | 2 +- clamdscan/proto.c | 15 ++++++++++++--- clamdscan/proto.h | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 951e02a28..eef29d3f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue Oct 27 23:29:09 CET 2009 (tk) +--------------------------------- + * clamdscan: improve error handling (bb#1729) + Tue Oct 27 20:31:36 CET 2009 (tk) --------------------------------- * clamdscan, libclamav, clamdtop, freshclam, sigtool: fix some error path diff --git a/clamdscan/client.c b/clamdscan/client.c index 701aadc41..4af276d00 100644 --- a/clamdscan/client.c +++ b/clamdscan/client.c @@ -265,7 +265,7 @@ int client(const struct optstruct *opts, int *infected) struct stat sb; fstat(0, &sb); if((sb.st_mode & S_IFMT) != S_IFREG) scantype = STREAM; - if((sockd = dconnect()) >= 0 && (ret = dsresult(sockd, scantype, NULL, &ret)) >= 0) + if((sockd = dconnect()) >= 0 && (ret = dsresult(sockd, scantype, NULL, &ret, NULL, NULL)) >= 0) *infected = ret; else errors = 1; diff --git a/clamdscan/proto.c b/clamdscan/proto.c index dd18a3759..3021ff2b1 100644 --- a/clamdscan/proto.c +++ b/clamdscan/proto.c @@ -247,7 +247,7 @@ static int send_fdpass(int sockd, const char *filename) { /* Sends a proper scan request to clamd and parses its replies * This is used only in non IDSESSION mode * Returns the number of infected files or -1 on error */ -int dsresult(int sockd, int scantype, const char *filename, int *printok) { +int dsresult(int sockd, int scantype, const char *filename, int *printok, int *files, int *errors) { int infected = 0, len, beenthere = 0; char *bol, *eol; struct RCVLN rcv; @@ -280,12 +280,16 @@ int dsresult(int sockd, int scantype, const char *filename, int *printok) { if(len <=0) { *printok = 0; + if(errors) + (*errors)++; return len; } while((len = recvln(&rcv, &bol, &eol))) { if(len == -1) return -1; beenthere = 1; + if(files) + (*files)++; if(!filename) logg("~%s\n", bol); if(len > 7) { char *colon = strrchr(bol, ':'); @@ -307,6 +311,8 @@ int dsresult(int sockd, int scantype, const char *filename, int *printok) { } } } else if(!memcmp(eol-7, " ERROR", 6)) { + if(errors) + (*errors)++; *printok = 0; if(filename) { if(scantype >= STREAM) @@ -375,12 +381,11 @@ static int serial_callback(struct stat *sb, char *filename, const char *path, en if(filename) free(filename); return CL_EOPEN; } - ret = dsresult(sockd, c->scantype, f, &c->printok); + ret = dsresult(sockd, c->scantype, f, &c->printok, &c->files, &c->errors); if(filename) free(filename); closesocket(sockd); if(ret < 0) return CL_EOPEN; c->infected += ret; - c->files++; if(reason == visit_directory_toplev) return CL_BREAK; return CL_SUCCESS; @@ -407,6 +412,8 @@ int serial_client_scan(char *file, int scantype, int *infected, int maxlevel, in if(cdata.printok) logg("~%s: OK\n", file); return 0; + } else if(!cdata.files) { + logg("~%s: No files scanned\n", file); } return 1; } @@ -468,6 +475,7 @@ static int dspresult(struct client_parallel_data *c) { logg("~%s%s\n", filename, colon); if(action) action(filename); } else if(!memcmp(eol-7, " ERROR", 6)) { + c->errors++; c->printok = 0; logg("~%s%s\n", filename, colon); } @@ -558,6 +566,7 @@ static int parallel_callback(struct stat *sb, char *filename, const char *path, } if(res <= 0) { c->printok = 0; + c->errors++; c->ids = cid->next; c->lastid--; free(cid); diff --git a/clamdscan/proto.h b/clamdscan/proto.h index aa6ba8cd6..048145f2a 100644 --- a/clamdscan/proto.h +++ b/clamdscan/proto.h @@ -36,5 +36,5 @@ void recvlninit(struct RCVLN *s, int sockd); int recvln(struct RCVLN *s, char **rbol, char **reol); int serial_client_scan(char *file, int scantype, int *infected, int maxlevel, int flags); int parallel_client_scan(char *file, int scantype, int *infected, int maxlevel, int flags); -int dsresult(int sockd, int scantype, const char *filename, int *spam); +int dsresult(int sockd, int scantype, const char *filename, int *printok, int *files, int *errors); #endif