Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion libclamav/bytecode_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int32_t cli_bcapi_read(struct cli_bc_ctx *ctx, uint8_t *data, int32_t size)
API_MISUSE();
return -1;
}
if (size < 0 || size > CLI_MAX_ALLOCATION) {
if (size < 0) {
cli_warnmsg("bytecode: negative read size: %d\n", size);
API_MISUSE();
return -1;
Expand Down
2 changes: 1 addition & 1 deletion libclamav/others.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ extern uint8_t cli_always_gen_section_hash;
(size_t)(sb) + (size_t)(sb_size) <= (size_t)(bb_size) && \
(size_t)(sb) <= (size_t)(bb_size))

#define CLI_MAX_ALLOCATION (182 * 1024 * 1024)
#define CLI_MAX_ALLOCATION (1024 * 1024 * 1024)

#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h> /* for NAME_MAX */
Expand Down
26 changes: 17 additions & 9 deletions libclamav/others_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,17 @@ void *cli_malloc(size_t size)
void *alloc;

if (!size || size > CLI_MAX_ALLOCATION) {
cli_errmsg("cli_malloc(): Attempt to allocate %lu bytes. Please report to https://github.com/Cisco-Talos/clamav/issues\n", (unsigned long int)size);
cli_warnmsg("cli_malloc(): File or section is too large to scan (%zu bytes). \
For your safety, ClamAV limits how much memory an operation can allocate to %zu bytes\n",
size, CLI_MAX_ALLOCATION);
return NULL;
}

alloc = malloc(size);

if (!alloc) {
perror("malloc_problem");
cli_errmsg("cli_malloc(): Can't allocate memory (%lu bytes).\n", (unsigned long int)size);
cli_errmsg("cli_malloc(): Can't allocate memory (%zu bytes).\n", size);
return NULL;
} else
return alloc;
Expand All @@ -240,15 +242,17 @@ void *cli_calloc(size_t nmemb, size_t size)
void *alloc;

if (!nmemb || !size || size > CLI_MAX_ALLOCATION || nmemb > CLI_MAX_ALLOCATION || (nmemb * size > CLI_MAX_ALLOCATION)) {
cli_errmsg("cli_calloc(): Attempt to allocate %lu bytes. Please report to https://github.com/Cisco-Talos/clamav/issues\n", (unsigned long int)nmemb * size);
cli_warnmsg("cli_calloc2(): File or section is too large to scan (%zu bytes). \
For your safety, ClamAV limits how much memory an operation can allocate to %zu bytes\n",
size, CLI_MAX_ALLOCATION);
return NULL;
}

alloc = calloc(nmemb, size);

if (!alloc) {
perror("calloc_problem");
cli_errmsg("cli_calloc(): Can't allocate memory (%lu bytes).\n", (unsigned long int)(nmemb * size));
cli_errmsg("cli_calloc(): Can't allocate memory (%zu bytes).\n", (nmemb * size));
return NULL;
} else
return alloc;
Expand All @@ -259,15 +263,17 @@ void *cli_realloc(void *ptr, size_t size)
void *alloc;

if (!size || size > CLI_MAX_ALLOCATION) {
cli_errmsg("cli_realloc(): Attempt to allocate %lu bytes. Please report to https://github.com/Cisco-Talos/clamav/issues\n", (unsigned long int)size);
cli_warnmsg("cli_realloc(): File or section is too large to scan (%zu bytes). \
For your safety, ClamAV limits how much memory an operation can allocate to %zu bytes\n",
size, CLI_MAX_ALLOCATION);
return NULL;
}

alloc = realloc(ptr, size);

if (!alloc) {
perror("realloc_problem");
cli_errmsg("cli_realloc(): Can't re-allocate memory to %lu bytes.\n", (unsigned long int)size);
cli_errmsg("cli_realloc(): Can't re-allocate memory to %zu bytes.\n", size);
return NULL;
} else
return alloc;
Expand All @@ -278,15 +284,17 @@ void *cli_realloc2(void *ptr, size_t size)
void *alloc;

if (!size || size > CLI_MAX_ALLOCATION) {
cli_errmsg("cli_realloc2(): Attempt to allocate %lu bytes. Please report to https://github.com/Cisco-Talos/clamav/issues\n", (unsigned long int)size);
cli_warnmsg("cli_realloc2(): File or section is too large to scan (%zu bytes). \
For your safety, ClamAV limits how much memory an operation can allocate to %zu bytes\n",
size, CLI_MAX_ALLOCATION);
return NULL;
}

alloc = realloc(ptr, size);

if (!alloc) {
perror("realloc_problem");
cli_errmsg("cli_realloc2(): Can't re-allocate memory to %lu bytes.\n", (unsigned long int)size);
cli_errmsg("cli_realloc2(): Can't re-allocate memory to %zu bytes.\n", size);
if (ptr)
free(ptr);
return NULL;
Expand All @@ -299,7 +307,7 @@ char *cli_strdup(const char *s)
char *alloc;

if (s == NULL) {
cli_errmsg("cli_strdup(): s == NULL. Please report to https://github.com/Cisco-Talos/clamav/issues\n");
cli_errmsg("cli_strdup(): passed reference is NULL, nothing to duplicate\n");
return NULL;
}

Expand Down