Skip to content

Commit

Permalink
blah
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusaa committed Aug 17, 2023
1 parent ba49cbf commit 676cf81
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 5 deletions.
11 changes: 10 additions & 1 deletion clamd/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,23 @@ cl_error_t scan_callback(STATBUF *sb, char *filename, const char *msg, enum cli_
context.virsize = 0;
context.scandata = scandata;
ret = cl_scanfile_callback(filename, &virname, &scandata->scanned, scandata->engine, scandata->options, &context);
fprintf(stderr, "%s::%d::ret == CL_EMEM = %d\n", __FUNCTION__, __LINE__, ret == CL_EMEM);
thrmgr_setactivetask(NULL, NULL);

if (thrmgr_group_need_terminate(scandata->conn->group)) {
free(filename);
logg(LOGG_DEBUG, "Client disconnected while scanjob was active\n");
return ret == CL_ETIMEOUT ? ret : CL_BREAK;
}
fprintf(stderr, "%s::%d::ret == CL_EMEM = %d\n", __FUNCTION__, __LINE__, ret == CL_EMEM);

if ((ret == CL_VIRUS) && (virname == NULL)) {
logg(LOGG_DEBUG, "%s: reported CL_VIRUS but no virname returned!\n", filename);
fprintf(stderr, "%s::%d::ret == CL_EMEM = %d\n", __FUNCTION__, __LINE__, ret == CL_EMEM);
ret = CL_EMEM;
fprintf(stderr, "%s::%d::ret == CL_EMEM = %d\n", __FUNCTION__, __LINE__, ret == CL_EMEM);
}
fprintf(stderr, "%s::%d::ret == CL_EMEM = %d\n", __FUNCTION__, __LINE__, ret == CL_EMEM);

if (ret == CL_EACCES) {
if (conn_reply(scandata->conn, filename, "Access denied.", "ERROR") == -1) {
Expand All @@ -291,8 +296,10 @@ cl_error_t scan_callback(STATBUF *sb, char *filename, const char *msg, enum cli_
free(filename);
return CL_SUCCESS;
}
fprintf(stderr, "%s::%d::ret == CL_EMEM = %d\n", __FUNCTION__, __LINE__, ret == CL_EMEM);

if (ret == CL_VIRUS) {
fprintf(stderr, "%s::%d::ret == CL_EMEM = %d\n", __FUNCTION__, __LINE__, ret == CL_EMEM);

if (scandata->options->general & CL_SCAN_GENERAL_ALLMATCHES || (scandata->infected && scandata->options->general & CL_SCAN_GENERAL_HEURISTIC_PRECEDENCE)) {
if (optget(scandata->opts, "PreludeEnable")->enabled) {
Expand All @@ -316,12 +323,14 @@ cl_error_t scan_callback(STATBUF *sb, char *filename, const char *msg, enum cli_
logg(LOGG_INFO, "%s: %s FOUND\n", filename, virname);
}
} else if (ret != CL_CLEAN) {
fprintf(stderr, "%s::%d::ret == CL_EMEM = %d\n", __FUNCTION__, __LINE__, ret == CL_EMEM);
scandata->errors++;
if (conn_reply(scandata->conn, filename, cl_strerror(ret), "ERROR") == -1) {
free(filename);
return CL_ETIMEOUT;
}
logg(LOGG_INFO, "%s: %s ERROR\n", filename, cl_strerror(ret));
fprintf(stderr, "%s::%d::ret == CL_EMEM = %d\n", __FUNCTION__, __LINE__, ret == CL_EMEM);
logg(LOGG_INFO, "%s::%d::%s: %s ERROR\n", __FUNCTION__, __LINE__, filename, cl_strerror(ret));
} else if (logok) {
logg(LOGG_INFO, "%s: OK\n", filename);
}
Expand Down
26 changes: 26 additions & 0 deletions clamd/server-th.c
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,8 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
logg(LOGG_INFO, "Self checking every %u seconds.\n", selfchk);
}

logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);

logg(LOGG_DEBUG, "Listening daemon: PID: %u\n", (unsigned int)getpid());
max_threads = optget(opts, "MaxThreads")->numarg;
max_queue = optget(opts, "MaxQueue")->numarg;
Expand All @@ -1383,6 +1385,7 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne

#if !defined(_WIN32) && defined(RLIMIT_NOFILE)
if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
/* don't warn if default value is too high, silently fix it */
unsigned maxrec;
int max_max_queue;
Expand All @@ -1402,6 +1405,7 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
** flag
*/

logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
#if defined(_LP64)
solaris_has_extended_stdio++;
#endif
Expand All @@ -1427,6 +1431,7 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
** as the default is usually 256
*/

logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
if (solaris_has_extended_stdio) {
rlim_t saved_soft_limit = rlim.rlim_cur;

Expand All @@ -1439,6 +1444,7 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
} /* If 64bit or has extended stdio */

#endif
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
opt = optget(opts, "MaxRecursion");
maxrec = opt->numarg;
max_max_queue = rlim.rlim_cur - maxrec * max_threads - clamdfiles + max_threads;
Expand Down Expand Up @@ -1466,7 +1472,9 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
}
#endif
logg(LOGG_DEBUG, "MaxQueue set to: %d\n", max_queue);
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
acceptdata.max_queue = max_queue;
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);

#ifndef _WIN32
/* set up signal handling */
Expand Down Expand Up @@ -1504,6 +1512,7 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
sigaction(SIGUSR2, &sigact, NULL);
#endif

logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
idletimeout = optget(opts, "IdleTimeout")->numarg;

for (i = 0; i < nsockets; i++)
Expand All @@ -1530,17 +1539,20 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
exit(-1);
}
#endif
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);

if ((thr_pool = thrmgr_new(max_threads, idletimeout, max_queue, scanner_thread)) == NULL) {
logg(LOGG_ERROR, "thrmgr_new failed\n");
exit(-1);
}
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);

if (pthread_create(&accept_th, NULL, acceptloop_th, &acceptdata)) {
logg(LOGG_ERROR, "pthread_create failed\n");
exit(-1);
}

logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
time(&start_time);
for (;;) {
int new_sd;
Expand Down Expand Up @@ -1573,6 +1585,7 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
}

if (fds->nfds) i = (rr_last + 1) % fds->nfds;
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
for (j = 0; j < fds->nfds && new_sd >= 0; j++, i = (i + 1) % fds->nfds) {
size_t pos = 0;
int error = 0;
Expand Down Expand Up @@ -1613,8 +1626,10 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
buf->mode = MODE_COMMAND;
logg(LOGG_DEBUG_NV, "mode -> MODE_COMMAND\n");
}
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
while (!error && buf->fd != -1 && buf->buffer && pos < buf->off &&
buf->mode != MODE_WAITANCILL) {
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
client_conn_t conn;
const char *cmd = NULL;
int rc;
Expand All @@ -1635,8 +1650,10 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
conn.mode = buf->mode;
conn.term = buf->term;

logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
/* Parse & dispatch command */
cmd = parse_dispatch_cmd(&conn, buf, &pos, &error, opts, readtimeout);
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);

if (conn.mode == MODE_COMMAND && !cmd)
break;
Expand All @@ -1658,8 +1675,10 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
if (error && error != CL_ETIMEOUT) {
conn_reply_error(&conn, "Error processing command.");
}
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
}
if (error) {
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
if (buf->dumpfd != -1) {
close(buf->dumpfd);
if (buf->dumpname) {
Expand All @@ -1684,6 +1703,7 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
}
pthread_mutex_unlock(fds->buf_mutex);

logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
/* handle progexit */
pthread_mutex_lock(&exit_mutex);
if (progexit) {
Expand All @@ -1708,6 +1728,7 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
}
pthread_mutex_unlock(&exit_mutex);

logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
/* SIGHUP */
if (sighup) {
logg(LOGG_INFO, "SIGHUP caught: re-opening log file.\n");
Expand All @@ -1716,6 +1737,7 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
if (!logg_file && (opt = optget(opts, "LogFile"))->enabled)
logg_file = opt->strarg;
}
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);

/* SelfCheck */
if (selfchk) {
Expand All @@ -1729,6 +1751,7 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
time(&start_time);
}
}
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);

/* DB reload */
pthread_mutex_lock(&reload_mutex);
Expand Down Expand Up @@ -1778,7 +1801,10 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
} else {
pthread_mutex_unlock(&reload_mutex);
}
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
}
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);
logg(LOGG_INFO, "%s::%d\n", __FUNCTION__, __LINE__);

pthread_mutex_lock(&exit_mutex);
progexit = 1;
Expand Down
14 changes: 12 additions & 2 deletions clamdscan/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,10 @@ static int client_scan(const char *file, int scantype, int *infected, int *err,
char *real_path = NULL;
char *fullpath = NULL;

fprintf(stderr, "%s::%d\n", __FUNCTION__, __LINE__);
/* Convert relative path to fullpath */
fullpath = makeabs(file);
fprintf(stderr, "%s::%d\n", __FUNCTION__, __LINE__);

/* Convert fullpath to the real path (evaluating symlinks and . and ..).
Doing this early on will ensure that the scan results will appear consistent
Expand All @@ -325,13 +327,21 @@ static int client_scan(const char *file, int scantype, int *infected, int *err,
free(fullpath);
fullpath = real_path;
}
fprintf(stderr, "%s::%d\n", __FUNCTION__, __LINE__);

if (!fullpath)
return 0;
if (!session)
if (!session) {
fprintf(stderr, "%s::%d\n", __FUNCTION__, __LINE__);
ret = serial_client_scan(fullpath, scantype, infected, err, maxlevel, flags);
else
fprintf(stderr, "%s::%d\n", __FUNCTION__, __LINE__);
}
else {
fprintf(stderr, "%s::%d\n", __FUNCTION__, __LINE__);
ret = parallel_client_scan(fullpath, scantype, infected, err, maxlevel, flags);
fprintf(stderr, "%s::%d\n", __FUNCTION__, __LINE__);
}
fprintf(stderr, "%s::%d\n", __FUNCTION__, __LINE__);
free(fullpath);
return ret;
}
Expand Down
2 changes: 2 additions & 0 deletions clamdscan/proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ int serial_client_scan(char *file, int scantype, int *infected, int *err, int ma
cdata.scantype = scantype;
data.data = &cdata;

fprintf(stderr, "%s::%d\n", __FUNCTION__, __LINE__);
ftw = cli_ftw(file, flags, maxlevel ? maxlevel : INT_MAX, serial_callback, &data, ftw_chkpath);
fprintf(stderr, "%s::%d\n", __FUNCTION__, __LINE__);
*infected += cdata.infected;
*err += cdata.errors;

Expand Down
2 changes: 1 addition & 1 deletion libclamav/others.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ const char *cl_strerror(cl_error_t clerror)
case CL_EMAP:
return "Can't map file into memory";
case CL_EMEM:
return "Can't allocate memory";
return "Can't allocate memory <others.c>";
case CL_ETIMEOUT:
return "Exceeded time limit";
/* internal (needed for debug messages) */
Expand Down
15 changes: 14 additions & 1 deletion libclamav/scanners.c
Original file line number Diff line number Diff line change
Expand Up @@ -5737,8 +5737,14 @@ cl_error_t cl_scandesc_callback(int desc, const char *filename, const char **vir
if ((engine->maxfilesize > 0) && ((uint64_t)sb.st_size > engine->maxfilesize)) {
cli_dbgmsg("cl_scandesc_callback: File too large (" STDu64 " bytes), ignoring\n", (uint64_t)sb.st_size);
if (scanoptions->heuristic & CL_SCAN_HEURISTIC_EXCEEDS_MAX) {
if (engine->cb_virus_found)
if (engine->cb_virus_found) {
fprintf(stderr, "%s::%d::In if statement for Heuristics.Limits.Exceeded.MaxFileSize\n", __FUNCTION__, __LINE__);
engine->cb_virus_found(desc, "Heuristics.Limits.Exceeded.MaxFileSize", context);
if (virname){
*virname = "Heuristics.Limits.Exceeded.MaxFileSize";
}
}
fprintf(stderr, "%s::%d::Setting status to CL_VIRUS\n", __FUNCTION__, __LINE__); //exit(11);
status = CL_VIRUS;
} else {
status = CL_CLEAN;
Expand All @@ -5752,11 +5758,13 @@ cl_error_t cl_scandesc_callback(int desc, const char *filename, const char **vir

if (NULL == (map = fmap(desc, 0, sb.st_size, filename_base))) {
cli_errmsg("CRITICAL: fmap() failed\n");
fprintf(stderr, "%s::%d::returning CL_EMEM\n", __FUNCTION__, __LINE__);
status = CL_EMEM;
goto done;
}

status = scan_common(map, filename, virname, scanned, engine, scanoptions, context);
fprintf(stderr, "%s::%d::returning CL_EMEM = %d\n", __FUNCTION__, __LINE__, status == CL_EMEM);

done:
if (NULL != map) {
Expand Down Expand Up @@ -5838,6 +5846,11 @@ cl_error_t cl_scanfile_callback(const char *filename, const char **virname, unsi
ret = cl_scandesc_callback(fd, filename, virname, scanned, engine, scanoptions, context);
close(fd);

//logg(LOGG_ERROR, "%s::%d\n", __FUNCTION__, __LINE__);
fprintf(stderr, "%s::%d::ret == CL_EMEM = %d\n", __FUNCTION__, __LINE__, CL_EMEM == ret);
fprintf(stderr, "%s::%d::ret == CL_VIRUS = %d\n", __FUNCTION__, __LINE__, CL_VIRUS == ret);
fprintf(stderr, "%s::%d::ret = %d\n", __FUNCTION__, __LINE__, ret);

return ret;
}

Expand Down

0 comments on commit 676cf81

Please sign in to comment.