Commit graph

37 commits

Author SHA1 Message Date
Val Snyder
7ff29b8c37
Bump copyright dates for 2025 2025-02-14 10:24:30 -05:00
Micah Snyder
a729aafc38 Remove PCRE dead code
As of ClamAV 0.105, PCRE2 is required. PCRE (1) is not an option, and
there is also no option to disable PCRE support.

This commit removes the dead code associated with those old build
options.
2024-04-13 12:34:15 -04:00
Micah Snyder
8e04c25fec Rename clamav memory allocation functions
We have some special functions to wrap malloc, calloc, and realloc to
make sure we don't allocate more than some limit, similar to the
max-filesize and max-scansize limits. Our wrappers are really only
needed when allocating memory for scans based on untrusted user input,
where a scan file could have bytes that claim you need to allocate
some ridiculous amount of memory. Right now they're named:
- cli_malloc
- cli_calloc
- cli_realloc
- cli_realloc2

... and these names do not convey their purpose

This commit renames them to:
- cli_max_malloc
- cli_max_calloc
- cli_max_realloc
- cli_max_realloc2

The realloc ones also have an additional feature in that they will not
free your pointer if you try to realloc to 0 bytes. Freeing the memory
is undefined by the C spec, and only done with some realloc
implementations, so this stabilizes on the behavior of not doing that,
which should prevent accidental double-free's.

So for the case where you may want to realloc and do not need to have a
maximum, this commit adds the following functions:
- cli_safer_realloc
- cli_safer_realloc2

These are used for the MPOOL_REALLOC and MPOOL_REALLOC2 macros when
MPOOL is disabled (e.g. because mmap-support is not found), so as to
match the behavior in the mpool_realloc/2 functions that do not make use
of the allocation-limit.
2024-03-15 13:18:47 -04:00
Micah Snyder
6d6e04ddf8 Optimization: replace limited allocation calls
There are a large number of allocations for fix sized buffers using the
`cli_malloc` and `cli_calloc` calls that check if the requested size is
larger than our allocation threshold for allocations based on untrusted
input. These allocations will *always* be higher than the threshold, so
the extra stack frame and check for these calls is a waste of CPU.

This commit replaces needless calls with A -> B:
- cli_malloc -> malloc
- cli_calloc -> calloc
- CLI_MALLOC -> MALLOC
- CLI_CALLOC -> CALLOC

I also noticed that our MPOOL_MALLOC / MPOOL_CALLOC are not limited by
the max-allocation threshold, when MMAP is found/enabled. But the
alternative was set to cli_malloc / cli_calloc when disabled. I changed
those as well.

I didn't change the cli_realloc/2 calls because our version of realloc
not only implements a threshold but also stabilizes the undefined
behavior in realloc to protect against accidental double-free's.
It may be worth implementing a cli_realloc that doesn't have the
threshold built-in, however, so as to allow reallocaitons for things
like buffers for loading signatures, which aren't subject to the same
concern as allocations for scanning possible malware.

There was one case in mbox.c where I changed MALLOC -> CLI_MALLOC,
because it appears to be allocating based on untrusted input.
2024-03-15 13:18:47 -04:00
Micah Snyder
9cb28e51e6 Bump copyright dates for 2024 2024-01-22 11:27:17 -05:00
Micah Snyder
6eebecc303 Bump copyright for 2023 2023-02-12 11:20:22 -08:00
mko-x
a21cc6dcd7
Add explicit log level parameter to application logging API
* Added loglevel parameter to logg()

* Fix logg and mprintf internals with new loglevels

* Update all logg calls to set loglevel

* Update all mprintf calls to set loglevel

* Fix hidden logg calls

* Executed clam-format
2022-02-15 15:13:55 -08:00
micasnyd
140c88aa4e Bump copyright for 2022
Includes minor format corrections.
2022-01-09 14:23:25 -07:00
Micah Snyder (micasnyd)
b9ca6ea103 Update copyright dates for 2021
Also fixes up clang-format.
2021-03-19 15:12:26 -07:00
Micah Snyder
206dbaefe8 Update copyright dates for 2020 2020-01-03 15:44:07 -05:00
Micah Snyder
95f456424a Variable type corrections for pcre/pcre2 code. 2019-10-02 16:08:25 -04:00
Micah Snyder
5f4f69102d Correcting types from int to cl_error_t where appropriate. Eliminating unused variables and referencing unused parameters to remove warnings. 2019-10-02 16:08:25 -04:00
Micah Snyder
52cddcbcfd Updating and cleaning up copyright notices. 2019-10-02 16:08:18 -04:00
Micah Snyder
b3e82e5e61 Replacing libclamav/cltypes.h with clamav-types.h.in, which generates a header clamav-types.h that we install alongside clamav.h. 2019-10-02 16:08:17 -04:00
Micah Snyder
72fd33c8b2 clang-format'd using new .clang-format rules. 2019-10-02 16:08:16 -04:00
Kevin Lin
eaf0a436c1 bb11965: fix issue with pcre2 support on 64-bit machines 2018-01-23 16:09:56 -05:00
Steven Morgan
45bafcdf0e bb11748 Fix compile warning is regex_pcre.c on Mac OS X. 2017-02-14 14:31:23 -05:00
Kevin Lin
5841080a9c PCRE2 support 2016-02-29 11:05:20 -05:00
Mickey Sola
46a35abe56 mass update of copyright headers 2015-09-17 13:41:26 -04:00
Kevin Lin
a6d2b523d0 bb#11377 - stub pcre functions for dynamic library mapping 2015-08-21 12:43:26 -04:00
Kevin Lin
14878cb1e2 changed pcre PCRE_UNGREEDY from 'G' to 'U'
reason: pcre uses 'U', 'G' is an artifact from old dev
2015-03-09 18:17:04 -04:00
Kevin Lin
0e4ef43b3b pcre: corrected trigger for warning message 2014-10-22 18:06:57 -04:00
Kevin Lin
86eddf118f set cli_virname argument to use const qualifier
pcre: added field to track virname
virname is tracked when a lsig is a single bypass pcre subsig
2014-10-09 13:23:29 -04:00
Kevin Lin
e1ab4becdb general code clean-up and adjustments 2014-09-23 13:43:55 -04:00
Kevin Lin
7250b47e75 pcre: cleaned up comments, old code, and debug messages
pcre: disable (?UTF*) control option
2014-09-16 17:54:58 -04:00
Kevin Lin
0d94646ec4 pcre: separated match report from execution 2014-09-16 13:49:01 -04:00
Kevin Lin
effb4f51fc pcre: intialization function 2014-09-12 13:35:19 -04:00
Kevin Lin
6bf32a7327 pcre: removed obsolete function
pcre: corrected error code for failed pcre_compile
pcre: added pcre_exec error code conversion
pcre: cleaned-up development notes
2014-09-11 16:17:39 -04:00
Kevin Lin
7ab4eec702 pcre: support for clamav styled offsets
pcre: added encompass ('e') option to matcher
2014-09-09 17:14:12 -04:00
Kevin Lin
0ab27124b3 pcre: removed outdated comments
pcre: added lsig validation and more accurate subsig counting
2014-09-03 15:41:06 -04:00
Kevin Lin
fd6af5bf4b pcre: moved diagnostics from matcher to regex execution level
pcre: added diagnostics on matching using ovector and fullinfo
2014-09-03 13:00:39 -04:00
Kevin Lin
39597f2557 pcre: added compiler option parsing 2014-09-02 17:22:22 -04:00
Kevin Lin
3f8f8721a1 pcre: fixed an issue where expression was not copied
pcre: added search offset override to cli_pcre_match
2014-08-26 12:31:11 -04:00
Kevin Lin
9bc7c13882 pcre: added and linked options to set match_limit and match_limit_recursion
pcre: separated parsing function into parsing and compiling functions
2014-08-25 19:11:12 -04:00
Kevin Lin
7afaa9bd22 pcre: encased pcre segments in macros to fix build without pcre support 2014-08-25 15:07:30 -04:00
Kevin Lin
f40a96fbda pcre: implemented rough support for matching and count
HIGHLY EXPERIMENTAL
2014-08-22 17:29:40 -04:00
Kevin Lin
5fa733692a pcre: support and linking for parsing and freeing 2014-08-22 14:39:17 -04:00