Clamuko segfault fixed.

git-svn: trunk@151
remotes/push_mirror/metadata
Tomasz Kojm 22 years ago
parent 9813580137
commit 46c2e927d2
  1. 9
      clamav-devel/ChangeLog
  2. 49
      clamav-devel/clamd/clamuko.c
  3. 41
      clamav-devel/clamd/server-th.c
  4. 8
      clamav-devel/clamd/server.h
  5. 3
      clamav-devel/libclamav/scanners.c

@ -1,3 +1,12 @@
Fri Dec 12 18:47:10 CET 2003 (tk)
---------------------------------
* clamd: clamuko - fixed a segmentation fault after database update. Problem
reported by Anders Herbjørnsen <andersh*gar.no>. Also now clamuko
is always stopped before (and restarted after) db update to
protect against a potential split with Dazuko.
* libclamav: scanners: added missing braces in a logical block (thanks to
Tomasz Klim <tomek*euroneto.pl>)
Fri Dec 12 13:43:50 GMT 2003 (njh)
----------------------------------
* clamav-milter: A couple of calls to clamfi_cleanup were missing before

@ -1,5 +1,5 @@
/*
* Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl>
* Copyright (C) 2002, 2003 Tomasz Kojm <zolw@konarski.edu.pl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -48,7 +48,7 @@ void clamuko_exit(int sig)
dazukoUnregister();
clamuko_running = 0;
logg("Clamuko stopped (exit).\n");
logg("Clamuko stopped.\n");
}
void *clamukoth(void *arg)
@ -66,6 +66,7 @@ void *clamukoth(void *arg)
clamuko_running = 1;
clamuko_scanning = 0;
/* ignore all signals except SIGUSR1 */
sigfillset(&sigset);
@ -163,51 +164,7 @@ void *clamukoth(void *arg)
while(1) {
/* wait while reloading the database */
if(reload) {
logg("*Clamuko: Waiting (database reloading)\n");
clamuko_reload = 1;
maxwait = CL_DEFAULT_MAXWHILEWAIT;
while(reload && maxwait--)
sleep(1);
if(!maxwait && reload) {
logg("!Clamuko: Database reloading failed. Forcing quit...\n");
logg("Clamuko stopped.\n");
dazukoUnregister();
kill(progpid, SIGTERM);
clamuko_running = 0;
clamuko_scanning = 0;
clamuko_reload = 0;
return NULL;
}
clamuko_reload = 0;
}
if(dazukoGetAccess(&acc) == 0) {
/* wait while reloading the database */
if(reload) {
logg("*Clamuko: Waiting (database reloading, after dazukoGetAccess())\n");
clamuko_reload = 1;
maxwait = CL_DEFAULT_MAXWHILEWAIT;
while(reload && maxwait--)
sleep(1);
if(!maxwait && reload) {
logg("!Clamuko: Database reloading failed. Forcing quit...\n");
kill(progpid, SIGTERM);
acc.deny = 0;
dazukoReturnAccess(&acc);
logg("Clamuko stopped.\n");
dazukoUnregister();
clamuko_running = 0;
clamuko_scanning = 0;
clamuko_reload = 0;
return NULL;
}
}
clamuko_scanning = 1;
scan = 1;

@ -119,6 +119,8 @@ void *threadscanner(void *arg)
void *threadwatcher(void *arg)
{
struct thrwarg *thwarg = (struct thrwarg *) arg;
struct thrarg *tharg;
pthread_attr_t thattr;
struct cfgstruct *cpt;
sigset_t sigset;
int i, j, ret, maxwait, virnum;
@ -192,7 +194,7 @@ void *threadwatcher(void *arg)
#ifdef CLAMUKO
/* stop clamuko */
if(clamuko_running) {
logg("Stopping Clamuko... (id %d)\n", clamukoid);
logg("Stopping Clamuko...\n");
pthread_kill(clamukoid, SIGUSR1);
/* we must wait for Dazuko unregistration */
maxwait = CL_DEFAULT_MAXWHILEWAIT * 5;
@ -295,10 +297,19 @@ void *threadwatcher(void *arg)
}
#ifdef CLAMUKO
if(clamuko_scanning && !clamuko_reload)
need_wait = 1;
if(clamuko_running) {
logg("Stopping Clamuko...\n");
pthread_kill(clamukoid, SIGUSR1);
/* we must wait for Dazuko unregistration */
maxwait = CL_DEFAULT_MAXWHILEWAIT * 5;
while(clamuko_running && maxwait--)
usleep(200000);
if(!maxwait && clamuko_running)
logg("!Critical error: Can't stop Clamuko.\n");
/* should we stop here ? */
}
#endif
if(need_wait)
usleep(200000);
@ -356,6 +367,24 @@ void *threadwatcher(void *arg)
logg("Database correctly reloaded (%d viruses)\n", virnum);
}
/* start clamuko */
#ifdef CLAMUKO
if(cfgopt(thwarg->copt, "ClamukoScanOnLine")) {
logg("Starting Clamuko...\n");
tharg = (struct thrarg *) mcalloc(1, sizeof(struct thrarg));
tharg->copt = thwarg->copt;
tharg->root = *thwarg->root;
tharg->limits = thwarg->limits;
tharg->options = thwarg->options;
pthread_attr_init(&thattr);
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_DETACHED);
pthread_create(&clamukoid, &thattr, clamukoth, tharg);
pthread_attr_destroy(&thattr);
}
#endif
reload = 0;
}
@ -492,7 +521,6 @@ int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *cop
progpid = 0;
reload = 0;
#ifdef CLAMUKO
clamuko_scanning = 0;
clamuko_running = 0;
#endif
@ -508,7 +536,6 @@ int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *cop
tharg->root = root;
tharg->limits = &limits;
tharg->options = options;
clamuko_reload = 0;
pthread_create(&clamukoid, &thattr, clamukoth, tharg);
}
@ -520,6 +547,8 @@ int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *cop
thwarg.socketd = socketd;
thwarg.copt = copt;
thwarg.root = &root;
thwarg.limits = &limits;
thwarg.options = options;
pthread_create(&watcherid, &thattr, threadwatcher, &thwarg);
/* set up signal handling */

@ -1,5 +1,5 @@
/*
* Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl>
* Copyright (C) 2002, 2003 Tomasz Kojm <zolw@konarski.edu.pl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,7 +25,7 @@
struct thrarg {
int sid;
int options; /* archive support 0/1 */
int options;
const struct cfgstruct *copt;
const struct cl_node *root;
const struct cl_limits *limits;
@ -44,11 +44,13 @@ struct thrwarg {
int socketd;
struct cl_node **root;
const struct cfgstruct *copt;
const struct cl_limits *limits;
int options;
};
short int progexit; /* exit steering variable */
int progpid; /* clamd pid */
short int reload, clamuko_reload, main_accept, main_reload;
short int reload, main_accept, main_reload;
int acceptloop_proc(int socketd, struct cl_node *root, const struct cfgstruct *copt);
int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *copt);

@ -713,12 +713,13 @@ int cli_magic_scandesc(int desc, char **virname, long int *scanned, const struct
(*reclev)--;
}
if(ret != CL_VIRUS) /* scan the raw file */
if(ret != CL_VIRUS) { /* scan the raw file */
lseek(desc, 0, SEEK_SET); /* If archive scan didn't rewind desc */
if(cli_scandesc(desc, virname, scanned, root) == CL_VIRUS) {
cli_dbgmsg("%s virus found in descriptor %d.\n", *virname, desc);
return CL_VIRUS;
}
}
return ret;
}

Loading…
Cancel
Save