Commit graph

71 commits

Author SHA1 Message Date
Micah Snyder (micasnyd)
b35d1e1bec fuzz-24354: Fix unknown read in VBA parser
Fixes bound checks in recently rewritten VBA parser code (i.e. issue
does not affect prior versions).

Also improves VBA terminator header parsing to better match the spec,
per recommendation by Jonas Zaddach.
2020-07-30 23:05:51 -07:00
Micah Snyder
e2f59af30a Clang-format touchup 2020-07-24 16:37:25 -07:00
Andy Ragusa (aragusa)
2049078622 fuzz-22348 null deref in egg utf8 conversion
Corrected memory leaks and a null dereference in the egg utf8 conversion.
2020-07-13 19:31:27 -07:00
Andrew
035265b96f Bug fixes related to the recent HFS+/VBA/OLE2/XLM code changes
This commit includes bug fixes and minor modifications based on
warnings generated by Coverity. These include:

- 287096 - In cli_xlm_extract_macros: Leak of memory or pointers
to system resources (CWE-404). This was a legitimate leak of a
generated temp filename and could occur frequently.

- 287095 - In scan_for_xlm_macros: Use of an uninitialized
variable.  The uninitialized value (state.length) was likely
never used unitialized, but we now initialize it just in case.

- 287094 - In cli_vba_readdir_new: Out-of-bounds access to a
buffer (CWE-119). This looks like a copy-paste error and was
a legitimate read past the bounds of a buffer in an error case.

- 284479 - In hfsplus_walk_catalog: All paths that lead to this
null pointer comparison already dereference the pointer earlier
(CWE-476). In certain cases a NULL pointer could be returned
in the success case of hfsplus_scanfile, which was not handled
correctly. This case may have been prevented in practice by
an earlier check, but adding a check for NULL just in case.

- 284478 - In hfsplus_walk_catalog: A value assigned to a
variable is never used. ret would be set if zlib's inflateEnd
function fails. The fix is to just not set ret in this case,
since the error doesn't seem fatal (although would result in
a memory leak by the zlib code...).

- 284477 - In hfsplus_check_attribute: Pointer is checked against
null but then dereferenced anyway. I just took out the NULL check
of record and recordSize, since the code requires these values
to not be NULL elsewhere and there's no way an error could
occur as currently used (stack var addresses are passed via these
parameters).

I also fixed up some of the function identifiers in debug print
messages.
2020-06-17 16:02:39 -04:00
Micah Snyder
11ef77007b Improve tmp sub-directory names
At present many parsers create tmp subdirectories to store extracted
files.  For parsers like the vba parser, this is required as the
directory is later scanned.  For other parsers, these subdirectories are
probably not helpful now that we provide recursive sub-dirs when
--leave-temps is enabled.  It's not quite as simple as removing the extra
subdirectories, however.  Certain parsers, like autoit, don't create very
unique filenames and would result in file name collisions when
--leave-temps is not enabled.

The best thing to do would be to make sure each parser uses unique
filenames and doesn't rely on cli_magic_scan_dir() to scan extracted
content before removing the extra subdirectory.  In the meantime, this
commit gives the extra subdirectories meaningful names to improve
readability.

This commit also:

- Provides the 'bmp' prefix for extracted PE icons.

- Removes empty tmp subdirs when extracting rtf files, to eliminate
  clutter.

- The PDF parser sometimes creates tmp files when decompressing streams
  before it knows if there is actually any content to decompress.  This
  resulted in a large number of empty files.  While it would be best to
  avoid creating empty files in the first place, that's not quite as
  as it sounds.  This commit does the next best thing and deletes the
  tmp files if nothing was actually extracted, even if --leave-temps is
  enabled.

- Removes the "scantemp" prefix for unnamed fmaps scanned with
  cli_magic_scan().  The 5-character hashes given to tmp files with
  prefixes resulted in occasional file name collisions when extracting
  certain file types with thousands of embedded files.

- The VBA and TAR parsers mistakenly used NAME_MAX instead of PATH_MAX,
  resulting in truncated file paths and failed extraction  when
  --leave-temps is enabled and a lot of recursion is in play.  This commit
  switches them from NAME_MAX to PATH_MAX.
2020-06-03 11:00:53 -04:00
Micah Snyder
9b9999d778 Rename core scanning functions
Many of the core scanning functions' names no longer represent their
specific purpose or arguments. This commit aims to make the names more
intuitive. Names are now prefixed with "magic" if they involve
file-typing and file-type parsing. In addition, each function now
includes the type of input being scanned whether its "desc", "fmap", or
"buff". Some of the APIs also now specify "type" to indicate that a type
other than "ANY" may be passed in to select the type rather than use
file type magic for type recognition.

| current name              | new name                          |
| ------------------------- | --------------------------------- |
| magic_scandesc()          | cli_magic_scan()                  |
| cli_magic_scandesc_type() | <delete>                          |
| cli_magic_scandesc()      | cli_magic_scan_desc()             |
| cli_base_scandesc()       | cli_magic_scan_desc_type()        |
| cli_partition_scandesc()  | <delete>                          |
| cli_map_scandesc()        | magic_scan_nested_fmap_type()     |
| cli_map_scan()            | cli_magic_scan_nested_fmap_type() |
| cli_mem_scandesc()        | cli_magic_scan_buff()             |
| cli_scanbuff()            | cli_scan_buff()                   |
| cli_scandesc()            | cli_scan_desc()                   |
| cli_fmap_scandesc()       | cli_scan_fmap()                   |
| cli_scanfile()            | cli_magic_scan_file()             |
| cli_scandir()             | cli_magic_scan_dir()              |
| cli_filetype2()           | cli_determine_fmap_type()         |
| cli_filetype()            | cli_compare_ftm_file()            |
| cli_partitiontype()       | cli_compare_ftm_partition()       |
| cli_scanraw()             | scanraw()                         |
2020-06-03 11:00:40 -04:00
Micah Snyder
005cbf5a37 Record names of extracted files
A way is needed to record scanned file names for two purposes:

1. File names (and extensions) must be stored in the json metadata
properties recorded when using the --gen-json clamscan option. Future
work may use this to compare file extensions with detected file types.

2. File names are useful when interpretting tmp directory output when
using the --leave-temps option.

This commit enables file name retention for later use by storing file
names in the fmap header structure, if a file name exists.

To store the names in fmaps, an optional name argument has been added to
any internal scan API's that create fmaps and every call to these APIs
has been modified to pass a file name or NULL if a file name is not
required.  The zip and gpt parsers required some modification to record
file names.  The NSIS and XAR parsers fail to collect file names at all
and will require future work to support file name extraction.

Also:

- Added recursive extraction to the tmp directory when the
  --leave-temps option is enabled.  When not enabled, the tmp directory
  structure remains flat so as to prevent the likelihood of exceeding
  MAX_PATH.  The current tmp directory is stored in the scan context.

- Made the cli_scanfile() internal API non-static and added it to
  scanners.h so it would be accessible outside of scanners.c in order to
  remove code duplication within libmspack.c.

- Added function comments to scanners.h and matcher.h

- Converted a TDB-type macros and LSIG-type macros to enums for improved
  type safey.

- Converted more return status variables from `int` to `cl_error_t` for
  improved type safety, and corrected ooxml file typing functions so
  they use `cli_file_t` exclusively rather than mixing types with
  `cl_error_t`.

- Restructured the magic_scandesc() function to use goto's for error
  handling and removed the early_ret_from_magicscan() macro and
  magic_scandesc_cleanup() function.  This makes the code easier to
  read and made it easier to add the recursive tmp directory cleanup to
  magic_scandesc().

- Corrected zip, egg, rar filename extraction issues.

- Removed use of extra sub-directory layer for zip, egg, and rar file
  extraction.  For Zip, this also involved changing the extracted
  filenames to be randomly generated rather than using the "zip.###"
  file name scheme.
2020-06-03 10:39:18 -04:00
Micah Snyder (micasnyd)
a97ce0c837 fuzz-21960: Add missing size checks to vba parser
Add missing size checks to validate size data parsed from a VBA file.

This fixes a possible buffer overflow read that was caught by oss-fuzz
before it made it into any release.
2020-05-12 17:28:37 -07:00
Jonas Zaddach (jzaddach)
b7f8440965 Modernize VBA code extraction from Microsoft Office files
- Existing VBA extraction code uses undocumented cache structures.
  This code uses the documented way of accessing VBA projects.
- Adds additional detail to the dumped information:
  Project name, Project doc string, ...
  All VBA projects are dumped into a single file.
- Malware authors are currently evading detection by spreading
  malicious code over several projects. It is hard to write
  signatures if only part of the malicious code is visible.
2020-04-28 13:32:07 -07:00
Micah Snyder
206dbaefe8 Update copyright dates for 2020 2020-01-03 15:44:07 -05:00
Mickey Sola
622771bd58 oss-fuzz - 13468 - fix shift of negative value when converting from unicode 2019-10-02 16:08:26 -04:00
Micah Snyder
bbfe42e133 Correcting use of unsigned variable to a signed off_t variable in calculation that was intended to result in a negative number but failed on 32bit platforms without a cast. 2019-10-02 16:08:26 -04:00
Micah Snyder
4524c398f3 Argument and return types for fmap_readn(), cli_writen(), cli_readn() converted to use size_t instead of int. 2019-10-02 16:08:25 -04:00
Micah Snyder
50f178dc63 fuzz - 12166 - Fix for 4-byte out of bounds write wherein the an invalid struct pointer member variable is set to zero. The fix adds bounds checking to the Uniq storage 'add' function as well as error code checks. Included a lot of new inline documentation. 2019-10-02 16:08:19 -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
d39cb6581f Updating libclamunrar from legacy C implementation to modern unrar 5.6.5. API changes and supporting changes included to pass the filepath of the scanned file into libclamav through the cli_ctx structure, required by the unrar library to open archives. The filename argument may be optional for the scandesc scanning variant, but libclamav will make a best effort to identify the filename from the file descriptor if it was not provided. In addition, included the ability to prefix temp file and directory names with file basenames. 2018-12-02 23:06:59 -05:00
Mickey Sola
46a35abe56 mass update of copyright headers 2015-09-17 13:41:26 -04:00
Kevin Lin
4de2f5ec2c bb#11164 - fixed invalid wrap-around read with vba inflation 2014-11-05 16:46:11 -05:00
Kevin Lin
9b38ab7248 bb#11165 - added size check to prevent invalid reads 2014-11-03 13:07:55 -05:00
Shawn Webb
60d8d2c352 Move all the crypto API to clamav.h 2014-07-01 19:38:01 -04:00
Steven Morgan
e182c02ce3 support libjson-c 0.10, 1.11, and 1.12 2014-05-23 09:46:06 -04:00
Kevin Lin
4c37996842 doc/ppt: moved information stream parsing from vba source to ole2 source 2014-04-21 18:30:28 -04:00
Kevin Lin
09dddc5be3 doc/ppt: added SummaryInfo and DocumentSummary streams parsing, JSON or debug 2014-04-21 16:44:26 -04:00
Shawn Webb
b2e7c931d0 Use OpenSSL for hashing. 2014-02-08 00:31:12 -05:00
David Raynor
dc31213450 vba: length grab cleanup 2013-08-07 13:41:14 -04:00
David Raynor
8c66e38605 vba: grab length after middle test 2013-03-22 12:05:59 -04:00
David Raynor
d489ba8066 vba: fix vba_read_project_strings() looping and bad returns 2013-03-13 14:22:04 -04:00
David Raynor
80649b2842 cid #11398, #11400, #11401 2013-03-12 13:51:49 -04:00
Shawn Webb
241e7eb147 bb6258 - Add warnings when allocations fail 2013-03-01 13:51:15 -05:00
Shawn Webb
7e40bab956 bb6099 - check return value of lseek() 2013-02-28 21:01:40 -05:00
Shawn webb
a2a004df25 BB#3737 - Value too large for specified data type
Create compile-time preprocessor defines for switching from calling
stat() to stat64(). Add --enable-stat64 switch in configure script.
2012-07-16 15:36:49 -04:00
David Raynor
bebd86a60b bb#5343 2012-06-22 16:55:29 -04:00
Tomasz Kojm
d21fb8d975 libclamav/vba_extract.c: fix error path double free (bb#2486) 2011-02-07 17:26:45 +01:00
Tomasz Kojm
fd45238eb6 libclamav: fix some error messages (bb#2083) 2010-07-05 17:31:25 +02:00
aCaB
58481352d5 win32 paths handling 2009-09-24 19:07:39 +02:00
aCaB
081f64735d win32#2 2009-09-24 16:24:07 +02:00
Török Edvin
f6f2869f8d avoid size 1 reads for performance reasons (bb #1542).
git-svn: trunk@5037
2009-04-10 15:20:18 +00:00
Tomasz Kojm
871177cdd9 return codes cleanup (bb#1159)
git-svn: trunk@4749
2009-02-12 13:53:23 +00:00
Tomasz Kojm
33068e0973 libclamav: drop cl_settempdir(); use cl_engine_set() with CL_ENGINE_TMPDIR and CL_ENGINE_KEEPTMP instead
git-svn: trunk@4416
2008-11-14 22:23:39 +00:00
aCaB
ddc9e6c347 bb#1239
git-svn: trunk@4311
2008-10-30 12:26:30 +00:00
Török Edvin
e357da7b90 more leak fixes (bb #1141)
git-svn: trunk@4127
2008-08-21 15:58:02 +00:00
Tomasz Kojm
a45c7039c1 shut up some gcc warnings
git-svn: trunk@4092
2008-08-08 14:00:17 +00:00
aCaB
937ade082c fix collisions in ole2/vba
git-svn: trunk@4068
2008-08-03 14:30:33 +00:00
Tomasz Kojm
72ce4b70eb improve handling of PDF, CAB, RTF, OLE2 and HTML files (sync with branch/0.93)
git-svn: trunk@3862
2008-05-27 16:30:47 +00:00
Tomasz Kojm
2023340a41 update copyrights and stick more files to GPLv2; move and add more credits to the AUTHORS file; add COPYING.BSD
git-svn: trunk@3749
2008-04-02 15:24:51 +00:00
aCaB
c0a95e0ce6 bb#384 - unlink
git-svn: trunk@3747
2008-04-02 11:13:16 +00:00
Nigel Horne
b81763abc8 Minor code tidy
git-svn: trunk@3680
2008-02-27 10:27:05 +00:00
Tomasz Kojm
f0f7f92f9a merge security fixes
git-svn: trunk@3626
2008-02-13 10:34:58 +00:00
aCaB
bbd6ca3fbb more limits and ole2 collision fixup
git-svn-id: file:///var/lib/svn/clamav-devel/branches/newlimits@3608 77e5149b-7576-45b1-b177-96237e5ba77b
2008-02-11 13:18:41 +00:00