Commit graph

122 commits

Author SHA1 Message Date
Micah Snyder
e2f59af30a Clang-format touchup 2020-07-24 16:37:25 -07:00
Andrew
319bfb51a5 Fix several coverity warnings
290424 Missing break in switch - In hash_match: Missing break
statement between cases in switch statement

290414 Resource leak - In cli_scanishield_msi: Leak of memory or
pointers to system resources. Memory leak in a fail case

288197 Resource leak - In decrypt_any: Leak of memory or pointers
to system resources. Memory leak in a fail case

290426 Resource leak - In cli_magic_scan: Leak of memory or pointers
to system resources. Leaked a file prefix when running with
--save-temps

192923 Resource leak - In cli_scanrar: Leak of memory or pointers to
system resources. Leaked a file descriptor if a virus was found in
a RAR file comment

225146 Resource leak - In cli_scanegg: Leak of memory or pointers
to system resources. Leaked a file descriptor if unable to write
a comment file to disk

290425 Resource leak - In scan_common: Leak of memory or pointers
to system resources. Memory leaks in various fail cases.

Also changes cli_scanrar to write out the file comment only if
--leave-temps is specified and scan the buffer (like what is done
in cli_scanegg) instead of writing the file out, scanning that,
and then deleting the file if --leave-temps is not specified.

The unit tests stopped working when correcting an issue with a
switch statement that determined what type of signature had matched
on a Google SafeBrowsing GDB rule. Looking into the unit tests, it
looks like the code had always assumed that the test cases would be
detected by a malware test rule in unit_tests/input/daily.gdb, but
now some of the tests get matched on the phishing test rule.
I updated the test logic to be more clear, and added tests for both
cases now.

Fix some memory leaks in libclamav/scanners.c
2020-07-15 08:39:32 -07:00
Andrew
f19f69c7ee Comment out the filter_search call in regex_list_match
Reviewing Coverity bug reports we found that the return value to this
filter_search call was effectively being ignored, causing no filtering
to occur. Fixing this issue resulted in a unit test that uses the
following match list regex to fail when searching for `ebay.com`.:

.+\\.paypal\\.(com|de|fr|it)([/?].*)?:.+\\.ebay\\.(at|be|ca|ch|co\\.uk|de|es|fr|ie|in|it|nl|ph|pl|com(\\.(au|cn|hk|my|sg))?)/

After investigating further, this is because the regex_list_add_pattern
call, which parses the regex for suffixes and attempts to add these to
the filter, can't handle the `com(\\.(au|cn|hk|my|sg))?` portion of
the regex. As a result, it only adds `ebay.at`, `ebay.be`, `ebay.ca`, up
through `ebay.pl` into the filter). With the code returning if no filter match
is found, the `ebay.com` suffix not existing in the filter causes incoming URLs
to be treated as if there are no corresponding regexes for ebay.com, which results
in no regex rules being evaluated against it.

We should get the regex parsing code working (and ensure it handles any
other complex cases in daily.cdb) before re-enabling this code. The code
has had no effect for 12+ years at this point, though, so it's probably
safe to wait a bit longer without it.
2020-06-17 16:02:39 -04:00
Andrew
2429b8dfa7 More Coverity bug fixes
Fixed the following Coverity issues:
- 225236 - In cli_egg_extract_file: Dereference of an explicit
null value (CWE-476). The first fail case checked handle for
NULL and then dereferenced it in the done block

- 225209 - In executeIfNewVersion: Leak of memory or pointers
to system resources (CWE-404). modifiedCommand was defined
twice, with the inner instance being assigned to and the
outer instance being freed

- 225201 - In regex_list_match: Code can never be reached
because of a logical contradiction (CWE-561). The code had
logic off to the side that may have been missed:

filter_search_rc = filter_search(&matcher->filter, (const unsigned char *)bufrev, buffer_len) != -1;
if (filter_search_rc == -1) {

- 225198 - In phishingCheck: Leak of memory or pointers to
system resources (CWE-404). A fail case caused by malloc
failing would leak previously allocated memory.

- 225197 - In updatecustomdb: A pointer to freed memory
is dereferenced, used as a function argument, or otherwise
used (CWE-416). In a fail case, a pointer was freed and
then used in a debug print statement

- 225190 - In updatedb: A pointer to freed memory is
dereferenced, used as a function argument, or otherwise used
(CWE-416). In a fail case, a pointer was freed and then used
in a debug print statement

- 225195 - In cli_egg_open: The sizeof operator is used on a
wrong argument that incidentally has the same size (CWE-467).
sizeof(char **) was being used instead of sizeof(char *)

- 225193 - In egg_parse_comment_header: Code can never be
reached because of a logical contradiction (CWE-561).
A cleanup case for variable comment was unnecessary, and
to fix comment was removed entirely.

- 225147 - In get_server_node: Code can never be reached
because of a logical contradiction (CWE-561). A cleanup
case for variable url was unnecessary

- 225168 - In download_complete_callback: Missing break
statement between cases in switch statement (CWE-484).
In the case where forking failed, freshclam would check
the database without forking but then continue on to
execute the code intended to be done in the child process
because of a missing break statement

- 225152 - In cli_egg_lzma_decompress: Use of an
uninitialized variable (CWE-457). Certain fail cases
would call cli_LzmaShutdown on an uninitialized stream.
Now it’s only called after initialization occurs.
2020-06-17 16:02:39 -04:00
Micah Snyder
e01ba94e36 bb12506: Fix phishing/heuristic alert verbosity
Some detections, like phishing, are considered heuristic alerts because
they match based on behavior more than on content.  A subset of these
are considered "potentially unwanted" (low-severity).  These
low-severity alerts include:
- phishing
- PDFs with obfuscated object names
- bytecode signature alerts that start with "BC.Heuristics"

The concept is that unless you enable "heuristic precedence" (a method
of lowing the threshold to immediateley alert on low-severity
detections), the scan should continue after a match in case a higher
severity match is found.  Only at the end will it print the low-severity
match if nothing else was found.

The current implementation is buggy though. Scanning of archives does
not correctly bail out for the entire archive if one email contains a
phishing link.  Instead, it sets the "heuristic found"  flag then and
alerts for every subsequent file in the archive because it doesn't know
if the heuristic was found in an embedded file or the target file.
Because it's just a heuristic and the status is "clean", it keeps
scanning.

This patch corrects the behavior by checking if a low-severity alerts
were found at the end of scanning the target file, instead of at the end
of each embedded file.

Additionally, this patch fixes an in issue with phishing alerts wherein
heuristic precedence mode did not cause a scan to stop after the first
alert.

The above changes required restructuring to create an fmap inside of
cl_scandesc_callback() so that scan_common() could be modified to
require an fmap and set up so that the current *ctx->fmap pointer is
never NULL when scan_common() evaluates match results.

Also fixed a couple minor bugs in the phishing unit tests and cleaned up
the test code for improved legitibility and type safety.
2020-06-03 17:20:35 -04:00
Micah Snyder
206dbaefe8 Update copyright dates for 2020 2020-01-03 15:44:07 -05:00
Micah Snyder
ee40795fe2 Converted mpool calls to macros when USE_MPOOL is defined to clearly differentiate between function and macro behavior. 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 (micasnyd)
3390c26c99 Added call to match R-type PDB signatures in phishcheck.c:phishingCheck(). This makes R-type PDB signatures functional, and operate as described in the documentation. 2019-10-02 16:08:23 -04:00
Micah Snyder
52cddcbcfd Updating and cleaning up copyright notices. 2019-10-02 16:08:18 -04:00
Micah Snyder
72fd33c8b2 clang-format'd using new .clang-format rules. 2019-10-02 16:08:16 -04:00
Micah Snyder
8efbf4a0cb eliminating compile warnings in windows 10, vs2015, x86 and x64. 2017-08-31 16:38:41 -04:00
Steven Morgan
22cb38ed24 pull request #53(2/4): Spelling fix by klemens(ka7). 2016-10-19 15:57:45 -04:00
Kevin Lin
1d06f67a13 bb#11396 - use temp var for realloc to prevent pointer loss 2016-03-23 16:14:42 -04:00
Kevin Lin
059ca61484 compiler warning suppression 2016-02-29 11:09:09 -05:00
Mickey Sola
46a35abe56 mass update of copyright headers 2015-09-17 13:41:26 -04:00
Kevin Lin
f210254408 matcher-ac: converted length fields to arrays 2015-07-02 14:41:37 -04:00
Kevin Lin
23d7c6e6f4 removed nocase changes to ac tree operation 2015-02-09 14:22:45 -08:00
Kevin Lin
7fc5eab81a finished support for AC trie nocase variant
added check to prevent adding nocase signatures to case-sensitive AC tries
2015-02-06 11:13:20 -08:00
Shawn Webb
60d8d2c352 Move all the crypto API to clamav.h 2014-07-01 19:38:01 -04:00
Shawn Webb
b2e7c931d0 Use OpenSSL for hashing. 2014-02-08 00:31:12 -05:00
Shawn Webb
241e7eb147 bb6258 - Add warnings when allocations fail 2013-03-01 13:51:15 -05:00
Steve Morgan
6ad45a2931 add initial allscan/allmatch mode to libclamav, clamd, clamdscan, and clamscan with unit tests 2012-10-18 14:12:58 -07:00
David Raynor
bebd86a60b bb#5343 2012-06-22 16:55:29 -04:00
aCaB
f206d31afa bb#3509 2011-09-16 12:48:59 +02:00
aCaB
88d09f480d make the sigload callback be aware of custom sigs 2011-06-14 19:04:02 +02:00
aCaB
9f497be696 Revert "Revert "add whitelisting via cb to phish sigs too""
This reverts commit 9eff97c080.
2010-08-13 00:53:45 +02:00
aCaB
9eff97c080 Revert "add whitelisting via cb to phish sigs too"
This reverts commit febc0c9f77.
2010-08-11 14:18:13 +02:00
aCaB
febc0c9f77 add whitelisting via cb to phish sigs too 2010-08-11 12:33:20 +02:00
Török Edvin
5b74e89a35 enable prefiltering, and add to dconf.
Also downgrade some warnings to debug messages.
2010-02-15 17:32:41 +02:00
Török Edvin
40103a3004 Merge branch 'tmp' into prefiltering2
* tmp:
  Prepare for prefiltering: add new files.

Conflicts:
	libclamav/Makefile.am
	libclamav/Makefile.in
	libclamav/libclamav.map
	libclamav/regex_list.c
2010-02-09 12:28:23 +02:00
Török Edvin
e0ac80ab38 Prepare for prefiltering: add new files.
Move SO_search to filtering.c as filtering_search.
Add unit test.
2010-02-09 12:12:49 +02:00
aCaB
63979bf21e Merge remote branch 'origin/fmap4all' 2009-10-09 22:07:33 +02:00
Tomasz Kojm
6c26e99c59 libclamav: check file sizes for MD5 sigs in all cases 2009-10-02 21:03:26 +02:00
aCaB
10aa2df79b Merge branch 'replace-mmap' into fmap4all
Conflicts:
	libclamav/matcher-bm.c
	libclamav/matcher-bm.h
	libclamav/matcher.c
	libclamav/pe.c
	libclamav/phishcheck.c
	libclamav/regex_list.c
2009-09-02 00:09:28 +02:00
aCaB
49ee0318fc fix scanbuff callers 2009-09-01 19:15:57 +02:00
Tomasz Kojm
006f5fe642 libclamav: in bm_offmode only load sigs with non-floating absolute
and relative offsets into BM matcher (load other ones into AC) and
use per-file computed offset table to pick up best shifts (not
enabled by default, bb#1300)
2009-09-01 11:19:31 +02:00
Tomasz Kojm
aca9ea82df libclamav: handle relative offsets with cli_ac_data; fix offset logic 2009-08-21 15:55:10 +02:00
Tomasz Kojm
33872a43de libclamav: improve handling of signature offsets 2009-08-14 14:38:13 +02:00
Tomasz Kojm
cc447ac82c configure, libclamav: fix compile issues on IRIX (bb#1532) 2009-08-04 23:17:28 +02:00
Török Edvin
627b76269a Safebrowsing.cvd load speed was very slow, taking up to 20s.
Improve load speed to ~3s by using another hash.
Also silence some .pdb load debug messages.
2009-07-17 13:55:15 +03:00
Török Edvin
816d66a876 local.gdb whitelisting of safebrowsing entries (bb #1482).
git-svn: trunk@5015
2009-04-02 20:36:27 +00:00
Török Edvin
a3d029b938 make use of hostkey prefix entries
git-svn: trunk@4929
2009-03-11 20:06:35 +00:00
Török Edvin
e828353b83 allow for hash prefixes.
git-svn: trunk@4916
2009-03-09 11:23:21 +00:00
Török Edvin
12d07440c4 comply with safebrowsing naming guidelines.
git-svn: trunk@4912
2009-03-09 11:23:02 +00:00
Tomasz Kojm
03527bee64 libclamav: count .pdb entries as signatures
freshclam, sigtool: add support for safebrowsing.cvd (bb#1056)


git-svn: trunk@4901
2009-03-05 19:09:54 +00:00
Török Edvin
d4e1cb474f fix match with root regex (bb #1421).
git-svn: trunk@4848
2009-02-23 12:35:45 +00:00
Török Edvin
fe389c841d reorder fields (bb #1144)
git-svn: trunk@4830
2009-02-18 19:53:28 +00:00
Török Edvin
4e46d65d39 use sha256 instead of md5 in phishcheck.
move sha256 to libclamav.
add more tests.

git-svn: trunk@4822
2009-02-18 14:54:16 +00:00
Tomasz Kojm
871177cdd9 return codes cleanup (bb#1159)
git-svn: trunk@4749
2009-02-12 13:53:23 +00:00