From 38fe8af4ff99af29a4bf431cf3bbb6589526612e Mon Sep 17 00:00:00 2001 From: Tomasz Kojm Date: Fri, 5 Oct 2007 23:48:44 +0000 Subject: [PATCH] better error checking/reporting (bb#657) git-svn: trunk@3273 --- ChangeLog | 4 ++++ clamd/clamd.c | 4 +++- clamdscan/client.c | 2 +- clamscan/manager.c | 12 ++++++++++-- shared/misc.c | 6 +++++- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2ffd5ee7a1..d488968bcc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat Oct 6 00:50:05 CEST 2007 (tk) +---------------------------------- + * clamscan, clamd: better error checking/reporting (bb#657) + Sat Oct 6 00:25:17 CEST 2007 (tk) ---------------------------------- * clamd: enable FixStaleSocket by default diff --git a/clamd/clamd.c b/clamd/clamd.c index cbbaf5d651..24d5417dc9 100644 --- a/clamd/clamd.c +++ b/clamd/clamd.c @@ -279,7 +279,9 @@ int main(int argc, char **argv) if(!cfgopt(copt, "Foreground")->enabled) { daemonize(); if(!debug_mode) - chdir("/"); + if(chdir("/") == -1) + logg("^Can't change current working directory to root\n"); + } else foreground = 1; diff --git a/clamdscan/client.c b/clamdscan/client.c index aec61904b2..e59017b1b3 100644 --- a/clamdscan/client.c +++ b/clamdscan/client.c @@ -204,8 +204,8 @@ static int dsstream(int sockd, const struct optstruct *opt) return 2; } - memset(buff, 0, sizeof(buff)); while(loopw) { + memset(buff, 0, sizeof(buff)); read(sockd, buff, sizeof(buff)); if((pt = strstr(buff, "PORT"))) { pt += 5; diff --git a/clamscan/manager.c b/clamscan/manager.c index f0bde3f485..638054ea3f 100644 --- a/clamscan/manager.c +++ b/clamscan/manager.c @@ -107,11 +107,16 @@ static int scanstdin(const struct cl_engine *engine, const struct cl_limits *lim if(!(fs = fopen(file, "wb"))) { logg("!Can't open %s for writing\n", file); + free(file); return 63; } while((ret = fread(buff, 1, FILEBUFF, stdin))) - fwrite(buff, 1, ret, fs); + if(fwrite(buff, 1, ret, fs) < ret) { + logg("!Can't write to %s\n", file); + free(file); + return 58; + } fclose(fs); @@ -460,7 +465,10 @@ static int clamav_unpack(const char *prog, const char **args, const char *tmpdir } } #endif - chdir(tmpdir); + if(chdir(tmpdir) == -1) { + fprintf(stderr, "ERROR: chdir(%s) failed\n", tmpdir); + exit(1); + } if(printinfected) { fdevnull = open("/dev/null", O_WRONLY); diff --git a/shared/misc.c b/shared/misc.c index fd8c038e64..e88c030d23 100644 --- a/shared/misc.c +++ b/shared/misc.c @@ -171,7 +171,11 @@ int filecopy(const char *src, const char *dest) } while((bytes = read(s, buffer, FILEBUFF)) > 0) - write(d, buffer, bytes); + if(write(d, buffer, bytes) < bytes) { + close(s); + close(d); + return -1; + } close(s); /* njh@bandsman.co.uk: check result of close for NFS file */