clamav/unit_tests
Val S. d4114e0d2c
Fix static analysis code quality issues; Fix old libjson-c support (#1574)
`clamscan/manager.c`: Fix double-free in an error condition in `scanfile()`.

`common/optparser.c`: Fix uninitialized use of the `numarg` variable when
`arg` is `NULL`.

`libclamav/cache.c`: Don't check if `ctx-fmap` is `NULL` when we've
already dereferenced it.

`libclamav/crypto.c`: The `win_exception` variable and associated logic
is Windows-specific and so needs preprocessor platform checks. Otherwise
it generates unused variable warnings.

`libclamav/crypto.c`: Check for `size_t` overflow of the `byte_read`
variable in the `cl_hash_file_fd_ex()` function.

`libclamav/crypto.c`: Fix a memory leak in the `cl_hash_file_fd_ex()`
function.

`libclamav/fmap.c`: Correctly the `name` and `path` pointer if
`fmap_duplicate()` fails. Also need to clear those variables when
duplicating the parent `map` so that on error it does not free the wrong
`name` or `path`.

`libclamav/fmap.c`: Refine error handling for `hash_string` cleanup in
`cl_fmap_get_hash()`. Coverity's complaint was that `hash_string` could
never be non-NULL if `status` is not `CL_SUCCESS`. I.e., the cleanup is
dead code. I don't think my cleanup actually "fixes" that though it is
definitely a better way to do the error handling.
The `if (NULL != hash_string) {` check is still technically dead code.
It safeguards against future changes that may `goto done` between the
allocation and transfering ownership from `hash_string` to `hash_out`.

`libclamav/others.c`: Fix possible memory leak in `cli_recursion_stack_push()`.

`libclamav/others.c`: Refactor an if/else + switch statement inside
`cli_dispatch_scan_callback()` so that the `CL_SCAN_CALLBACK_ALERT` case
is not dead-code. It's also easier to read now.

`libclamav/pdfdecode.c`: For logging, use the `%zu` to format `size_t`
instead of casting to `long long` and using `%llu`. Simiularly use the
`STDu32` format string macro for `uint32_t`.

`libclamav/pdfdecode.c`: Fix a possible double-free for the `decoded`
pointer in `filter_lzwdecode()`.

`libclamav/pdfdecode.c`: Remove the `if (capacity > UINT_MAX) {`
overflow check inside `filter_lzwdecode()`, which didn't do anything.
The `capacity` variable this point is a fixed value and so I also changed
the `avail_out` to be that fixed `INFLATE_CHUNK_SIZE` value rather than
using `capacity`. It is more straightforward and replicates how similar
logic works later in the file.
I also removed the copy-pasted `(Bytef *)` cast which didn't reaaally do
anything, and was a copypaste from a different algorihm. The lzw
implementation interface doesn't use `Bytef`.

`libclamav/readdb.c`: Fix a possible NULL-deref on the `matcher` variable
in the error handling/cleanup code if the function fails.

`libclamav/scanners.c`: Fix an issue where the return value from some of
the parsers may be lost/overridden by the call to
`cli_dispatch_scan_callback()` just after the `done:` label in
`cli_magic_scan()`.

`libclamav/scanners.c`: Silence an unused-return value warning when
calling `cli_basename()`.

`sigtool/sigtool.c` and `unit_tests/check_regex.c`:
Fix possible NULL-derefs of the `ctx.recursion_stack` pointer in the error
handling for several functions.

Also, and this isn't a Coverity thing:

`libclamav/json_api.c` and `libclamav/others.c`:
Fix support for libjson-c version 0.13 and older.
I don't think we *should* be using the old version, but some environments
such as the current OSS-Fuzz base image are older and still use it.
The issue is that `json_object_new_uint64()` was introduced in a later
libjson-c version, so we have to fallback to use `json_object_new_int64()`
with older libjson-c, provided the int were storing isn't too big.

CLAM-2768
2025-09-26 18:26:00 -04:00
..
clamscan Reduce unnecessary scanning of embedded file FPs (#1571) 2025-09-23 15:57:28 -04:00
examples Added additional ex_scan_callbacks test and fixed a couple related bugs 2025-08-14 22:40:47 -04:00
input Reduce unnecessary scanning of embedded file FPs (#1571) 2025-09-23 15:57:28 -04:00
check_bytecode.c libclamav: scan-layer callback API functions 2025-08-14 22:39:14 -04:00
check_clamav.c Tests: Fix a couple of valgrind complaints (#1554) 2025-09-09 12:35:14 -04:00
check_clamav_skip.c bb12596: Fix build issue when libcheck missing 2020-08-24 15:11:07 -07:00
check_clamd.c Bump copyright dates for 2025 2025-02-14 10:24:30 -05:00
check_disasm.c Bump copyright dates for 2025 2025-02-14 10:24:30 -05:00
check_fpu_endian.c Bump copyright dates for 2025 2025-02-14 10:24:30 -05:00
check_htmlnorm.c Record unique object-id for each layer scanned 2025-08-14 21:23:33 -04:00
check_jsnorm.c Bump copyright dates for 2025 2025-02-14 10:24:30 -05:00
check_matchers.c libclamav: scan-layer callback API functions 2025-08-14 22:39:14 -04:00
check_regex.c Fix static analysis code quality issues; Fix old libjson-c support (#1574) 2025-09-26 18:26:00 -04:00
check_str.c Bump copyright dates for 2025 2025-02-14 10:24:30 -05:00
check_uniq.c Bump copyright dates for 2025 2025-02-14 10:24:30 -05:00
checks.h CMake: Add CTest support to match Autotools checks 2021-02-25 11:41:26 -08:00
clamd_test.py Tests: Remove unecessary TCP options for non-Windows ClamD tests 2025-05-01 10:45:39 -04:00
CMakeLists.txt Windows: improved support for '/' path separators 2025-07-22 16:14:22 -04:00
freshclam_test.py Tests: clamscan --fips-limits for CVD loading 2025-08-14 22:40:45 -04:00
libclamav_test.py Bump copyright dates for 2025 2025-02-14 10:24:30 -05:00
Run-GetLibs.ctest Test: fix check_clamd failure on Windows 2021-03-22 19:50:48 -07:00
sigtool_test.py Windows: improved support for '/' path separators 2025-07-22 16:14:22 -04:00
testcase.py Swap clean cache from MD5 to SHA2-256 2025-08-14 21:23:30 -04:00
valgrind.supp Valgrind: Adjust statx suppressions 2024-04-09 10:35:22 -04:00