Commit graph

481 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
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
6eebecc303 Bump copyright for 2023 2023-02-12 11:20:22 -08:00
ragusaa
6ea6ee5690
Fix crash loading bugged bytecode signature
The bytecode compiler has a bug that was observed to cause a crash 
with a specific signature when testing on FreeBSD.

This PR adds an index size check when looking up a constant to
prevent this crash in case a bugged signature gets through QA.

An additional NULL check is added just to be safe.
2022-11-22 10:35:49 -08:00
Micah Snyder
0bd2ae26bc Scanners: Remove allmatch checks + significant code cleanup
Also fixed a number of conditions where magic_scan() critical errors may
be ignored.

To ensure that the scan truly aborts for signature matches (not in
allmatch mode) and for timeouts, the `ctx->abort` option is now set in
these two conditions, and checked in several spots in magic_scan().

Additionally, I've consolidated some of the "scan must halt" type of
checks (mostly large switch statements) into a function so that we can
use the exact same logic in a few places in magic_scan().

I've also fixed a few minor warnings and code format issues.
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
15eef50656 Code cleanup: Refactor to clean up formatting issues
Refactored the clamscan code that determines 'what to scan' in order
to clean up some very messy logic and also to get around a difference in
how vscode and clang-format handle formatting #ifdef blocks in the
middle of an else/if.

In addition to refactoring, there is a slight behavior improvement. With
this change, doing `clamscan blah -` will now scan `blah` and then also
scan `stdin`.  You can even do `clamscan - blah` to now scan `stdin` and
then scan `blah`. Before, The `-` had to be the only "filename" argument
in order to scan from stdin.

In addition, added a bunch of extra empty lines or changing multi-line
function calls to single-line function calls in order to get around a
bug in clang-format with these two options do not playing nice together:
- AlignConsecutiveAssignments: true
- AlignAfterOpenBracket: true

AlignAfterOpenBracket is not taking account the spaces inserted by
AlignConsecutiveAssignments, so you end up with stuff like this:
```c
    bleeblah = 1;
    blah     = function(arg1,
                    arg2,
                    arg3);

                //  ^--- these args 4-left from where they should be.
```

VSCode, meanwhile, somehow fixes this whitespace issue so code that is
correctly formatted by VSCode doesn't have this bug, meaning that:

1. The clang-format check in GH Actions fails.
2. We'd all have to stop using format-on-save in VSCode and accept the
  bug if we wanted those GH Actions tests to pass.

Adding an empty line before variable assignments from multi-line
function calls evades the buggy behavior.

This commit should resolve the clang-format github action test failures,
for now.
2022-03-22 10:42:46 -07:00
Micah Snyder
ddf7224837 Remove compatibility layer for llvm versions before 3 2022-03-09 20:35:42 -08:00
Andy Ragusa
c92227e051 Removed dead code support for llvm versions before 8. 2022-03-09 20:35:42 -08: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
Andy Ragusa
90904d5a7a CMake: Make BYTECODE_RUNTIME parameter case-insensitive
Also:
- Removed an unused DEBUG_TYPE define that was throwing warnings.
- Added default behavior for unexpected platform OS to reduce warnings.
2022-03-09 20:35:42 -08:00
Andy Ragusa
4b83bcf0c5 Updated llvm runtime to support llvm versions 8, 9, 10, 11, 12
Modified bytecode JIT code to support llvm versions 8, 9, 10, 11, 12.
Additionally updated FindLLVM.cmake to the current version, found at
https://github.com/ldc-developers/ldc/blob/master/cmake/Modules/FindLLVM.cmake,
as well as making modifications suggested by Micah Snyder to check VERSION_LESS
in CMakeLists.txt to avoid having modifications to FindLLVM.cmake.
2022-03-09 20:35:42 -08:00
mko-x
a21cc6dcd7
Add explicit log level parameter to application logging API
* Added loglevel parameter to logg()

* Fix logg and mprintf internals with new loglevels

* Update all logg calls to set loglevel

* Update all mprintf calls to set loglevel

* Fix hidden logg calls

* Executed clam-format
2022-02-15 15:13:55 -08:00
micasnyd
140c88aa4e Bump copyright for 2022
Includes minor format corrections.
2022-01-09 14:23:25 -07:00
Mickey Sola
e8d78c9627 Add logging interface via the log crate for libclamav_rust modules 2021-11-15 12:33:05 -08:00
Micah Snyder
d46832d5cf clamav.net URL update for new docs, github issues
Replace new bugzilla ticket links with links to github issues.
Replace clamav.net/documentation links with docs.clamav.net equivalents.
2021-07-17 15:28:02 -07:00
Micah Snyder
b0fc4c1346 clang-format: c++ bytecode source
Previously we'd not clang-formatted the c++ bytecode files because:
A) It's a massive difference in format
B) I wasn't sure, at the time, which code was "ours"

Reformatting now that the LLVM source is all removed and before it gets
updated to support modern LLVM versions.
2021-07-05 15:19:02 -07:00
Micah Snyder
da23b1ceab CMake: Fix support for external LLVM (3.6)
Have to manually link libtinfo (`-ltinfo`) because our FindLLVM
didn't add it to the LLVM_LIBRARIES variable for us. See:
- https://stackoverflow.com/questions/21477407/llvm-3-5-fails-to-link

Have to remove the CXX_STANDARD setting at the top of CMakeLists.txt
because of c++90 / c++11 ABI compatibility issues w/ LLVM. See:
- https://maleadt.github.io/LLVM.jl/dev/man/troubleshooting/

Rename "llvm/Config/config.h" "llvm/Config/llvm-config.h" because
LLVM renamed it in 2.8.

Have to link LLVM manually with the test binaries that use the
clamav object library instead of libclamav shared library.
CMake does not propagate library dependencies from object files.

I tested on ubuntu:16.04 with LLVM 3.6 built from source using:
```
/usr/local/bin/cmake .. -D CMAKE_INSTALL_PREFIX=/opt/llvm/3.6 \
  -D LLVM_ENABLE_RTTI=ON
```
Then built clamav w/:
```
/usr/local/bin/cmake .. -D CMAKE_INSTALL_PREFIX=`pwd`/install \
  -D BYTECODE_RUNTIME="llvm" \
  -D LLVM_ROOT_DIR="/opt/llvm/3.6" \
  -D LLVM_FIND_VERSION="3.6.0" && make && make install
```
2021-05-19 14:20:59 -07:00
Micah Snyder
a746d344df Remove Autotools build system & built-in LLVM
CMake is now required to build.

The built-in LLVM is no longer available.

Also removed support for libltdl calls, which is not used in the CMake
builds, was only used when building with Autotools.

TODO: Fix CMake LLVM support & update to work with modern versions.
2021-05-19 14:20:59 -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
1db4787f8a Remove autotools generated files, add autogen.sh
Removed all autotools generates files. Autotools (autoconf, automake,
libtool, pkg-config, m4) will be required from now on for builds from
git clones.

Added autogen.sh to be run before ./configure.

Significant update to main .gitignore file.

Removed extraneous .gitignore files. A Git repository only needs one
.gitignore file.
2020-07-17 15:40:32 -07:00
Micah Snyder
9b03090a0a Autotools compatibility fixes
Fixes breaking issues when using autoconf 2.69 and automake 1.15.
2020-07-17 15:40:32 -07:00
Micah Snyder
54c766d184 Autojunk 2020-05-01 08:04:30 -04:00
Jonas Zaddach (jzaddach)
965d7cc82e Fix bug in LLVM bytecode runtime
Fixes a bug in the PtrVerifier pass when using LLVM >= v3.5 for the
bytecode signature runtime.

LLVM 3.5 changed the meaning of "use" and introduced "user". This fix
swaps out "use" keywords for "user" so the code functions correctly when
using LLVM 3.5+.
2020-04-29 13:55:25 -07:00
Micah Snyder
206dbaefe8 Update copyright dates for 2020 2020-01-03 15:44:07 -05:00
Mickey Sola
a0e8d2ffbb autojunk'd 2019-11-06 09:50:38 -08:00
Micah Snyder
d39035d95d Autojunk'd 2019-10-02 16:08:30 -04:00
Micah Snyder
f270023ac3 Autojunk 2019-10-02 16:08:29 -04:00
Mickey Sola
b75b6e420a clamonacc - make curl version configure error message more verbose; remove Makefile artifact from merge conflict which broke auto configure logic 2019-10-02 16:08:29 -04:00
Mickey Sola
b04016987e autojunk'd 2019-10-02 16:08:29 -04:00
Mickey Sola
f7d82063dd autojunk'd 2019-10-02 16:08:28 -04:00
Mickey Sola
aaad010cf4 clamonacc - remove share/priv-fts.h path from makefile to fix
makedist; autojunk'd
2019-10-02 16:08:28 -04:00
Mickey Sola
a8bf985948 autojunk'd after libreshclam merge conflict resolution 2019-10-02 16:08:28 -04:00
Mickey Sola
3921323b62 autojunk'd 2019-10-02 16:08:28 -04:00
Mickey Sola
4ca79bd7cb autojunk'd 2019-10-02 16:08:28 -04:00
Mickey Sola
18b723e697 autojunk'd 2019-10-02 16:08:27 -04:00
Mickey Sola
3733a8795e clamonacc - move and configure fts fix 2019-10-02 16:08:27 -04:00
Mickey Sola
1b264c0bf2 clamonacc - update autotools scripts to get clamd and onacc building; autojunk'd 2019-10-02 16:08:26 -04:00
Micah Snyder
559df75c9f Autojunk'd 2019-10-02 16:08:24 -04:00
Micah Snyder
5fef7399da Autojunk'ed 2019-10-02 16:08:23 -04:00
Micah Snyder
8214bafbef Freshclam logging fixes. The logging features were linked twice, resulting in duplicate symbols for logg settings. On Windows, this manifested as multiple open log file handles which prevented log rotation. This commit fixes that and also alters the rotated log name slightly so that the log file extension is preserved, for Windows compatibility and convenience when viewing in an editor that color codes .log files. 2019-10-02 16:08:23 -04:00
Micah Snyder
fe4433b01f Autojunk'd 2019-10-02 16:08:20 -04:00
Micah Snyder
52cddcbcfd Updating and cleaning up copyright notices. 2019-10-02 16:08:18 -04:00
Micah Snyder
311c3501e4 Autojunk'd 2018-12-02 23:07:06 -05:00
Micah Snyder
7b563ca798 Enabling configure option --with-system-libmspack that will allow use of libmspack installations in /usr or /usr/local in favor of the version provided by ClamAV. 2018-12-02 23:07:02 -05: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
1f8557443e autojunk'd 2018-12-02 23:06:58 -05:00