Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added checks for MaxRecursion #1264

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions clamd/server-th.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "clamav.h"
#include "others.h"
#include "readdb.h"
#include "default.h"

// common
#include "output.h"
Expand Down Expand Up @@ -981,6 +982,12 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne
#endif

if ((opt = optget(opts, "MaxRecursion"))->active) {
if ((0 == opt->numarg) || (opt->numarg > CLI_MAX_MAXRECLEVEL)) {
logg(LOGG_ERROR, "MaxRecursion set to %zu, but cannot be larger than %u, and cannot be 0.\n",
(size_t) opt->numarg, CLI_MAX_MAXRECLEVEL);
cl_engine_free(engine);
return 1;
}
if ((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_RECURSION, opt->numarg))) {
logg(LOGG_ERROR, "cl_engine_set_num(CL_ENGINE_MAX_RECURSION) failed: %s\n", cl_strerror(ret));
cl_engine_free(engine);
Expand Down
8 changes: 8 additions & 0 deletions clamscan/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "matcher-pcre.h"
#include "str.h"
#include "readdb.h"
#include "default.h"

// common
#include "optparser.h"
Expand Down Expand Up @@ -1388,6 +1389,13 @@ int scanmanager(const struct optstruct *opts)
}

if ((opt = optget(opts, "max-recursion"))->active) {
uint32_t opt_value = opt->numarg;
if ((0 == opt_value) || (opt_value > CLI_MAX_MAXRECLEVEL)) {
logg(LOGG_ERROR, "max-recursion set to %u, but cannot be larger than %u, and cannot be 0.\n",
opt_value, CLI_MAX_MAXRECLEVEL);
ret = 2;
goto done;
}
if ((ret = cl_engine_set_num(engine, CL_ENGINE_MAX_RECURSION, opt->numarg))) {
logg(LOGG_ERROR, "cli_engine_set_num(CL_ENGINE_MAX_RECURSION) failed: %s\n", cl_strerror(ret));
ret = 2;
Expand Down
2 changes: 1 addition & 1 deletion docs/man/clamscan.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Extract and scan at most #n bytes from each archive. The size the archive plus t
Extract at most #n files from each scanned file (when this is an archive, a document or another kind of container). This option protects your system against DoS attacks (default: 10000)
.TP
\fB\-\-max\-recursion=#n\fR
Set archive recursion level limit. This option protects your system against DoS attacks (default: 17).
Set archive recursion level limit. This option protects your system against DoS attacks (default: 17) (maximum: 100).
.TP
\fB\-\-max\-dir\-recursion=#n\fR
Maximum depth directories are scanned at (default: 15).
Expand Down
1 change: 1 addition & 0 deletions etc/clamd.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ Example
# deeply the process should be continued.
# Note: setting this limit too high may result in severe damage to the system.
# Default: 17
# Maximum: 100
#MaxRecursion 10

# Number of files to be scanned within an archive, a document, or any other
Expand Down
2 changes: 2 additions & 0 deletions libclamav/default.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#define CLI_DEFAULT_PCRE_RECMATCH_LIMIT 2000
#define CLI_DEFAULT_PCRE_MAX_FILESIZE (1024 * 1024 * 100) // 100 MB

/* Maximums */
#define CLI_MAX_MAXRECLEVEL 100
micahsnyder marked this conversation as resolved.
Show resolved Hide resolved
// clang-format on

#endif
1 change: 1 addition & 0 deletions win32/conf_examples/clamd.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ TCPAddr localhost
# deeply the process should be continued.
# Note: setting this limit too high may result in severe damage to the system.
# Default: 17
# Maximum: 100
#MaxRecursion 10

# Number of files to be scanned within an archive, a document, or any other
Expand Down
Loading