Skip to content

Commit

Permalink
better error checking/reporting (bb#657)
Browse files Browse the repository at this point in the history
git-svn: trunk@3273
  • Loading branch information
Tomasz Kojm committed Oct 5, 2007
1 parent e6fe106 commit 38fe8af
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion clamd/clamd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion clamdscan/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions clamscan/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion shared/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
/* [email protected]: check result of close for NFS file */
Expand Down

0 comments on commit 38fe8af

Please sign in to comment.