Commit graph

96 commits

Author SHA1 Message Date
Val Snyder
7ff29b8c37
Bump copyright dates for 2025 2025-02-14 10:24:30 -05:00
Micah Snyder
1e5ddefcee Clang-format touchup 2024-03-15 13:18:47 -04:00
Micah Snyder
609ace2e3c Remove unnecessary max-allocation limit checks from bytecode runtime
Allocations for bytecode signatures to work need not check against the
memory allocation limit, as bytecode signatures are considered trusted
user input.

You may note that I did not remove allocation limits from the bytecode
API functions that may be called by the signatures such as adding json
objects, hashsets, lzma and bz2 decompressors, etc. This is because it
is likely that a bytecode signature may call them more times based on
the structure of the file being scanned - particularly for the json objects.
2024-03-15 13:18:47 -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
RainRat
1b17e20571
Fix typos (no functional changes) 2024-01-19 09:08:36 -08:00
Micah Snyder
38386349c5 Fix many warnings 2023-04-13 00:11:34 -07:00
Micah Snyder
6eebecc303 Bump copyright for 2023 2023-02-12 11:20:22 -08:00
Micah Snyder
4b9adb984a Bytecode: Fix compiler warning for unused iptr variable
Based on changes observed in the commits:
- 08fef61fea
- 1aa8768db2

... I believe that the iptr variable was intended to be used and was
accidentally not used.

In addition, adding the `ULL` suffix in the second location to match the
first, because it appears to have been accidentally omited.
2022-10-19 13:13:57 -07:00
Micah Snyder
57886cee52 Code cleanup: More accurate variable types in bytecode modules
The bytecode source files largely use `int` instead of the appropriate
`cl_errot_t` for clamav status codes, as well for boolean variables.
This hides warnings that would indicate bugs, and makes it harder to
read the code.

I haven't gone as in depth as with some other code cleanups. This
largely just replaces function interfactes and ret variables that use
`int` with `cl_error_t`. I also swapped a couple of `int`s to `bool`s.

While doing so I found that the `cli_bytecode_context_setpdf()` function
was incorrectly placed in the `bytecode_api.c` file instead of the next
to similar functions (`cli_bytecode_context_setpe`, etc.) in bytecode.c.
It's not an API function, so I moved it to the correct location.

I also eliminated a couple of compiler warnings:

- LLVM's CFG.h header emits a warning about a multi-line comment, so
  that crops up with using LLVM for the bytecode runtime.
  I disabled the warning through CMake.

- C doesn't like using the `inline` keyword on cli_dbgmsg in the
  declaration in `bytecode2llvm.c` because we're compiling the bytecode
  runtimes as a separate object file from the rest of libclamav.
  It doesn't appear to be a functional issue, but I swapped that file
  over to use `cli_dbgmsg_no_inline()` instead, just in case.
  I would hope link-time-optimization will inline it anyways.
2022-10-19 13:13:57 -07: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
Mickey Sola
4fee702fc3 clamonacc - conform to clang-format 2019-10-02 16:08:29 -04:00
Jonas Zaddach
3fc316c0c4 Trace instructions in bytecode VM 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
38fe8b69a0 Added .clang-format style rules, clam-format script to automate formatting of ClamAV code, and preparing select files so that clang-format does not alter carefully formatted sections. 2019-10-02 16:08:16 -04:00
Josh Soref
7cd9337a70 Spelling Adjustments (#30)
* spelling: accessed

* spelling: alignment

* spelling: amalgamated

* spelling: answers

* spelling: another

* spelling: acquisition

* spelling: apitid

* spelling: ascii

* spelling: appending

* spelling: appropriate

* spelling: arbitrary

* spelling: architecture

* spelling: asynchronous

* spelling: attachments

* spelling: argument

* spelling: authenticode

* spelling: because

* spelling: boundary

* spelling: brackets

* spelling: bytecode

* spelling: calculation

* spelling: cannot

* spelling: changes

* spelling: check

* spelling: children

* spelling: codegen

* spelling: commands

* spelling: container

* spelling: concatenated

* spelling: conditions

* spelling: continuous

* spelling: conversions

* spelling: corresponding

* spelling: corrupted

* spelling: coverity

* spelling: crafting

* spelling: daemon

* spelling: definition

* spelling: delivered

* spelling: delivery

* spelling: delimit

* spelling: dependencies

* spelling: dependency

* spelling: detection

* spelling: determine

* spelling: disconnects

* spelling: distributed

* spelling: documentation

* spelling: downgraded

* spelling: downloading

* spelling: endianness

* spelling: entities

* spelling: especially

* spelling: empty

* spelling: expected

* spelling: explicitly

* spelling: existent

* spelling: finished

* spelling: flexibility

* spelling: flexible

* spelling: freshclam

* spelling: functions

* spelling: guarantee

* spelling: hardened

* spelling: headaches

* spelling: heighten

* spelling: improper

* spelling: increment

* spelling: indefinitely

* spelling: independent

* spelling: inaccessible

* spelling: infrastructure

Conflicts:
	docs/html/node68.html

* spelling: initializing

* spelling: inited

* spelling: instream

* spelling: installed

* spelling: initialization

* spelling: initialize

* spelling: interface

* spelling: intrinsics

* spelling: interpreter

* spelling: introduced

* spelling: invalid

* spelling: latency

* spelling: lawyers

* spelling: libclamav

* spelling: likelihood

* spelling: loop

* spelling: maximum

* spelling: million

* spelling: milliseconds

* spelling: minimum

* spelling: minzhuan

* spelling: multipart

* spelling: misled

* spelling: modifiers

* spelling: notifying

* spelling: objects

* spelling: occurred

* spelling: occurs

* spelling: occurrences

* spelling: optimization

* spelling: original

* spelling: originated

* spelling: output

* spelling: overridden

* spelling: parenthesis

* spelling: partition

* spelling: performance

* spelling: permission

* spelling: phishing

* spelling: portions

* spelling: positives

* spelling: preceded

* spelling: properties

* spelling: protocol

* spelling: protos

* spelling: quarantine

* spelling: recursive

* spelling: referring

* spelling: reorder

* spelling: reset

* spelling: resources

* spelling: resume

* spelling: retrieval

* spelling: rewrite

* spelling: sanity

* spelling: scheduled

* spelling: search

* spelling: section

* spelling: separator

* spelling: separated

* spelling: specify

* spelling: special

* spelling: statement

* spelling: streams

* spelling: succession

* spelling: suggests

* spelling: superfluous

* spelling: suspicious

* spelling: synonym

* spelling: temporarily

* spelling: testfiles

* spelling: transverse

* spelling: turkish

* spelling: typos

* spelling: unable

* spelling: unexpected

* spelling: unexpectedly

* spelling: unfinished

* spelling: unfortunately

* spelling: uninitialized

* spelling: unlocking

* spelling: unnecessary

* spelling: unpack

* spelling: unrecognized

* spelling: unsupported

* spelling: usable

* spelling: wherever

* spelling: wishlist

* spelling: white

* spelling: infrastructure

* spelling: directories

* spelling: overridden

* spelling: permission

* spelling: yesterday

* spelling: initialization

* spelling: intrinsics

* space adjustment for spelling changes

* minor modifications by klin
2018-02-27 22:00:09 -05:00
Micah Snyder
ce2dcb5392 bb11432 - cleaning up additional warning messages. 2017-08-21 17:03:42 -04:00
Micah Snyder
d18d72219f Eliminating warnings, converting iterator variables to size_t when used to compare against sizeof(). added a couple of missing #includes. 2017-08-11 16:01:50 -04:00
Micah Snyder
14e2247bd2 updating the copyright for a number of tiles. 2017-08-09 14:28:47 -04:00
Micah Snyder
d2106081ad Removing check for negative values, because the variable in question is unsigned. 2017-08-09 09:33:05 -04:00
Steven Morgan
48692affad bytecode_vm.c: fix compiler warning and reduce debug verbosity. 2016-05-09 13:53:40 -04:00
Mickey Sola
46a35abe56 mass update of copyright headers 2015-09-17 13:41:26 -04:00
Shawn Webb
cd94be7a52 Silence a bunch of compiler warnings in libclamav 2014-07-10 18:11:49 -04:00
Shawn Webb
60d8d2c352 Move all the crypto API to clamav.h 2014-07-01 19:38:01 -04:00
Kevin Lin
612629994c removed comments and unused variables in bytecode interpreter 2014-03-04 10:23:57 -05:00
Kevin Lin
5db992809c fixed an issue with memory intrinsic return values 2014-02-28 16:35:47 -05:00
Shawn Webb
b2e7c931d0 Use OpenSSL for hashing. 2014-02-08 00:31:12 -05:00
Kevin Lin
08fef61fea marked integer constants too large for long type with ULL 2014-01-24 15:34:40 -05:00
Kevin Lin
c7b17b3bd3 removed an unused variable 2014-01-22 10:56:13 -05:00
Kevin Lin
90c0acc762 formatted a number of bytecode files, converted tabs to spaces 2014-01-16 17:57:40 -05:00
Kevin Lin
1aa8768db2 fixed an issue where GEP with negative offset would invalidate pointer 2014-01-16 17:56:12 -05:00
Shawn Webb
241e7eb147 bb6258 - Add warnings when allocations fail 2013-03-01 13:51:15 -05:00
Ryan Pentney
e0cab69069 Fixed signed division check as in BB#6482 2013-01-25 11:52:03 -08:00
Török Edvin
c9e456b21c fix opcode 20 error (bb #3100) 2011-07-25 16:10:54 +03:00
Török Edvin
7493b2f383 Fix previous commit.
it wants 32-bit arg for memcpy...
2011-01-20 16:55:10 +02:00
Török Edvin
ecedf8a9f9 bytecode_vm: fix memset on bigendian arch (bb #2478).
Otherwise memset's count is always 0, and we are using uninitialized bytes,
causing bytecode to misbehave.
2011-01-20 16:10:30 +02:00
Török Edvin
9eb82c24c8 bytecode_vm: fix apicall8
memstr() curiously always had haystack == needle for bytecode.
To fix this it helps if I actually read arg3 from ops[2] instead of ops[0]!
2010-10-18 11:02:52 +03:00
Török Edvin
a15fc904ed bytecode_vm: fix cli_bcapi_get_pe_section and cli_bcapi_disasm_x86.
They were not working on the interpreter, interpreter was seeing bounds errors
where there weren't any.
The 2nd parameter is a count, not a pointer size, the pointer's size
is a constant. Override the size for now.
2010-10-18 10:48:19 +03:00
Török Edvin
1c00d0ac74 bytecode_vm: record errors as bytecode events too 2010-10-18 10:48:19 +03:00
Török Edvin
2cad69f723 bytecode_vm: restore stack_id after function return
This allows pointers to local stack variables to work correctly after a call.
Previously stackid was not restored, which caused bytecode_vm to stop bytecodes,
claiming it overrun the stack, when in fact it didn't.
(stackid stores stack size).
2010-10-18 10:48:19 +03:00
Török Edvin
598d7edae0 Fix use of uninitialized value (bb #2140).
This bug may cause crashes in certain cases.
2010-07-23 22:32:46 +03:00
Török Edvin
2545f9767c Rearrange some fields in structs to avoid holes. 2010-06-09 13:44:29 +03:00
Török Edvin
f85ae23af3 Fix bswap64 in bytecode interpreter. 2010-05-14 10:41:28 +03:00
Török Edvin
9d39dc93f3 Fix bytecode interpreter nullptr comparisons. 2010-05-13 23:16:08 +03:00
Török Edvin
7ebca3d717 Fix interpreter on new bytecode API tests. 2010-05-13 22:44:41 +03:00
Török Edvin
e4a0f2c94f fix compiler warnings (bb #1872, bb #1934, bb #1935) 2010-04-13 16:19:47 +03:00