Commit graph

69 commits

Author SHA1 Message Date
Val Snyder
7ff29b8c37
Bump copyright dates for 2025 2025-02-14 10:24:30 -05: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
Micah Snyder
6e8b2abd11 Fix additional invalid prototypes 2022-11-22 23:22:57 -08:00
Micah Snyder
e6c33936de Fix bytecode hook out-file descriptor error handling
The cli_bc_ctx->outfd struct member was not properly initialized to -1.
Perhaps previous developers figured 0 was invalid-enough. All of the
checks for that file descriptor assumed 0 was the invalid value, going
so far as to explicitly set outfd to 0 if `open()` returned -1.
I didn't know this, so when I cleaned up the error handling in
`cli_unpackelf()` and `cli_unpackmacho()`, I had it `close(outfd)` when
not -1. That of course ended up closing stdin... and then all subsequent
file scans opened the file as fd `0`,... which interestingly caused
`read()` and `stat()` errors, but only after scanning a macho or elf
file, first.

Anyways... this commit fixes the issue by properly initializing outfd to
-1, and by changing any checks from 0 to -1.

I also found that it appears that the bytecode timeout wasn't being
applied to bytecode functions associated with logical signaures (that
is, those run by `cli_bytecode_runlsig()`).
What I see is that `ctx->bytecode_timeout` is only set to a non-zero
value in `cli_bytecode_context_alloc()`.
But for `cli_bytecode_runlsig()`, the bytecode context sits on the stack
and is memset instead. To resolve this, and ensure the bytecode context
is properly initialized, I created a new function that does this and
had it do the memset instead of using a calloc in the allocation
function.

I also removed the `bytecode_context_clear()` function because it simply
called `bytecode_context_reset()` and then did a memset. The memset is
unnecessary, especially since in most cases it's memsetting a stack
structure immediately before a return.
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
Micah Snyder
b07b1a65cb Fix linker issues with global variable used in tests
The `have_clamjit` global is used in the unit tests but doesn't appear
to be exported when I was testing the external LLVM runtime support PR,
resulting in an undefined symbol issue. Converting this to a function
that returns 0 or 1 instead of a global variable resolved the issue.
2022-03-09 20:35:42 -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 (micasnyd)
9e20cdf6ea Add CMake build tooling
This patch adds experimental-quality CMake build tooling.

The libmspack build required a modification to use "" instead of <> for
header #includes. This will hopefully be included in the libmspack
upstream project when adding CMake build tooling to libmspack.

Removed use of libltdl when using CMake.

Flex & Bison are now required to build.

If -DMAINTAINER_MODE, then GPERF is also required, though it currently
doesn't actually do anything.  TODO!

I found that the autotools build system was generating the lexer output
but not actually compiling it, instead using previously generated (and
manually renamed) lexer c source. As a consequence, changes to the .l
and .y files weren't making it into the build. To resolve this, I
removed generated flex/bison files and fixed the tooling to use the
freshly generated files. Flex and bison are now required build tools.
On Windows, this adds a dependency on the winflexbison package,
which can be obtained using Chocolatey or may be manually installed.

CMake tooling only has partial support for building with external LLVM
library, and no support for the internal LLVM (to be removed in the
future). I.e. The CMake build currently only supports the bytecode
interpreter.

Many files used include paths relative to the top source directory or
relative to the current project, rather than relative to each build
target. Modern CMake support requires including internal dependency
headers the same way you would external dependency headers (albeit
with "" instead of <>). This meant correcting all header includes to
be relative to the build targets and not relative to the workspace.

For example, ...

```c
include "../libclamav/clamav.h"
include "clamd/clamd_others.h"
```

... becomes:

```c
// libclamav
include "clamav.h"

// clamd
include "clamd_others.h"
```

Fixes header name conflicts by renaming a few of the files.

Converted the "shared" code into a static library, which depends on
libclamav. The ironically named "shared" static library provides
features common to the ClamAV apps which are not required in
libclamav itself and are not intended for use by downstream projects.
This change was required for correct modern CMake practices but was
also required to use the automake "subdir-objects" option.
This eliminates warnings when running autoreconf which, in the next
version of autoconf & automake are likely to break the build.

libclamav used to build in multiple stages where an earlier stage is
a static library containing utils required by the "shared" code.
Linking clamdscan and clamdtop with this libclamav utils static lib
allowed these two apps to function without libclamav. While this is
nice in theory, the practical gains are minimal and it complicates
the build system. As such, the autotools and CMake tooling was
simplified for improved maintainability and this feature was thrown
out. clamdtop and clamdscan now require libclamav to function.

Removed the nopthreads version of the autotools
libclamav_internal_utils static library and added pthread linking to
a couple apps that may have issues building on some platforms without
it, with the intention of removing needless complexity from the
source. Kept the regular version of libclamav_internal_utils.la
though it is no longer used anywhere but in libclamav.

Added an experimental doxygen build option which attempts to build
clamav.h and libfreshclam doxygen html docs.

The CMake build tooling also may build the example program(s), which
isn't a feature in the Autotools build system.

Changed C standard to C90+ due to inline linking issues with socket.h
when linking libfreshclam.so on Linux.

Generate common.rc for win32.

Fix tabs/spaces in shared Makefile.am, and remove vestigial ifndef
from misc.c.

Add CMake files to the automake dist, so users can try the new
CMake tooling w/out having to build from a git clone.

clamonacc changes:
- Renamed FANOTIFY macro to HAVE_SYS_FANOTIFY_H to better match other
  similar macros.
- Added a new clamav-clamonacc.service systemd unit file, based on
  the work of ChadDevOps & Aaron Brighton.
- Added missing clamonacc man page.

Updates to clamdscan man page, add missing options.

Remove vestigial CL_NOLIBCLAMAV definitions (all apps now use
libclamav).

Rename Windows mspack.dll to libmspack.dll so all ClamAV-built
libraries have the lib-prefix with Visual Studio as with CMake.
2020-08-13 00:25:34 -07:00
Micah Snyder
206dbaefe8 Update copyright dates for 2020 2020-01-03 15:44:07 -05: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
Micah Snyder (micasnyd)
89d5207b31 Added new pdf object stream parsing capability. 2018-12-02 23:06:58 -05:00
Mickey Sola
46a35abe56 mass update of copyright headers 2015-09-17 13:41:26 -04:00
Kevin Lin
0ff13b3138 clambc: added diagnostic tools for bytecode IR
clambc: added option to print bytecode IR
TODO: add diagnostic functions to win32 project

Conflicts:

	shared/optparser.c
2014-07-25 12:06:13 -04:00
Steve Morgan
16c4fcdd10 performance statistics for bytecode hooks 2012-12-07 08:09:10 -08:00
Steve Morgan
54402320c0 Add bytecode performance statistics 2012-12-05 15:48:52 -08: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
Török Edvin
540fc128a0 freshclam is using private symbol that changed proto (bb #2187).
Change name to prevent crash with 0.96.1 freshclam and 0.96.2 libclamav.
You'll get a missing symbol error.
2010-08-11 14:26:10 +03:00
Török Edvin
762d46e8ea Fix matchicon bytecode API (bb #2139).
Now you can call it both from a normal lsig triggered BC, and from a PE hook BC.
The normal lsig triggered BC has exe_info (but not PE info) which allows it to
invoke the icon matcher API.
Also putting ICONGROUP1 into the ldb trigger of the bytecode works.
2010-08-02 21:52:15 +03:00
Török Edvin
dc200c6b19 Add bytecode API for pdf. 2010-08-02 18:21:24 +03:00
Török Edvin
927d054838 Add engine param to bytecode, and remove dconf from _init. 2010-07-29 13:48:18 +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
2a7f1cdaf5 Print C++ compiler version.
This requires exporting a function from libclamav, since clamconf is not C++...
2010-04-19 18:35:30 +03:00
Török Edvin
20327f931f compute global offsets. 2010-03-06 16:28:08 +02:00
Török Edvin
6eeadbfeda dconf for bytecode. 2010-02-15 17:32:41 +02:00
Török Edvin
236fb13647 New pointer handling rules. 2010-02-15 17:32:40 +02:00
Török Edvin
57f14280a7 Fix use-after-free on bytecode load/execution.
lsig->bc was referring to the bytecode directly (via a pointer),
but the bytecode struct changes place in memory (it is realloced on each .cbc
load). So use an index instead of the direct pointer.
2010-02-02 15:30:20 +02:00
Török Edvin
847d7fc1b8 2009->2010 2010-02-02 14:03:32 +02:00
Tomasz Kojm
baf2e702e2 libclamav: provide information about lsig matches to bytecode (bb#1799) 2010-01-28 12:54:28 +01:00
Török Edvin
a35cfe5137 print bytecode metadata. 2010-01-22 16:50:35 +02:00
Török Edvin
be43f951c6 BytecodeSecurity setting. 2010-01-22 16:50:35 +02:00
Török Edvin
f4e3421592 Support PE hook bytecodes triggered by logical signature. 2010-01-19 16:41:26 +02:00
Tomasz Kojm
12c6a97e9b fix some compiler warnings 2010-01-12 16:16:08 +01:00
Török Edvin
688799d126 yc_bytecode is able to unpack a file now! 2009-12-17 17:40:35 +02:00
Török Edvin
92ba8d661c Attempt to fix SunC build: enum/unsigned mismatch is not allowed. 2009-12-12 15:14:40 +02:00
Török Edvin
853b6e5da1 Add LLVM win32 proj files generated by cmake.
Fix win32 build issues.
Enable CPU detection on win32 too.
Enable LLVM JIT on win32 too.
Define NDEBUG for libclamavc++ for release win32 builds.
2009-12-12 15:14:39 +02:00
Török Edvin
29cbf0787b stdint.h -> cltypes.h 2009-12-11 21:07:36 +02:00
Török Edvin
d0934caf99 Distcheck fixes. 2009-12-11 21:02:19 +02:00
Török Edvin
0a11015bf5 Refactor trace API, so that trace printing happens in clambc.
This will allow clambc to implement breakpoints, and watchpoints.
2009-12-09 17:05:05 +02:00
Török Edvin
65c740d7d8 Add support for tracing (if bytecode compiled with support).
TODO: global id 0 is now a null pointer, need to adjust rest of conversion code
accordingly.
2009-12-08 23:02:49 +02:00
Török Edvin
74b0023374 Fix after merge: update to fmap API. 2009-12-03 11:37:38 +02:00
Török Edvin
3ae0a76d03 Support for scanning files created by bytecode. 2009-12-02 17:30:17 +02:00
Török Edvin
53bd5bb14d read optional debug metadata. 2009-11-30 15:22:20 +02:00
Török Edvin
250d92c533 Sync with compiler. 2009-11-06 16:34:46 +02:00
Török Edvin
ec41017bba WiP 2009-10-06 17:32:38 +03:00
Török Edvin
ab63657088 Add generic and PE hooks. 2009-10-02 17:33:11 +03:00
Török Edvin
9fac78c72e Update to latest bytecode format. 2009-10-02 10:26:47 +03:00