Commit Graph

10591 Commits

Author SHA1 Message Date
Micah Snyder
016af483e6 CMake: support macOS code signing during build
To build with code signing, the macOS build must have:
  -G Xcode \
  -D CLAMAV_SIGN_FILE=ON \
  -D CODE_SIGN_IDENTITY="...your codesign ID..." \
  -D DEVELOPMENT_TEAM_ID="...your team ID..." \

You can find the codesign ID using:
  /usr/bin/env xcrun security find-identity -v -p codesigning

The team ID should also be listed in the identity description.

Also I changed the package name for APPLE to be "clamav" so it doesn't
put "ClamAV <version>" in the PKG PackageInfo like this:
  com.cisco.ClamAV 0.104.0.libraries
Instead, it should just be something like:
  com.cisco.clamav.libraries

Version is a separate field in that file and shouldn't be in the name.
2021-10-11 11:28:37 -07:00
Micah Snyder
ea625441e1 cmake: Fix Windows .msi installer
At present the .msi installer is only installing documentation component
files and the vcredist files but fails to install clamav libraries,
programs, and dependencies.

It appears that explicitly installing the NEWS & README files under the
documentation component before calling "include(CPack)" was causing the
MSI installer to think it needed to install the documentation component
but nothing else.

This commit removes the component name, since we don't want to use
components in the Windows MSI installer anyways. This appears to resolve
the issue so that the MSI installer installs all the desired files.
2021-10-07 19:30:12 -07:00
Andrea DePasquale
fb7d05c4d0 Add check for signature pattern bytes < 0x80
When locale is UTF-8, check that signature pattern bytes are < 0x80
before using the isalpha() and toupper() functions since that can lead
to segfaults and/or unintended matches.

For example take a LDB signature with a case-insensitive subsignature
containing byte 0xb5. The uint16_t value of pattern->pattern[i] is
0x10b5 since 0xb5 is OR'd with the CLI_MATCH_NOCASE (0x1000) flag.

Locale: C
isalpha((unsigned char) (0x10b5 & 0xff)): 0
toupper((unsigned char) (0x10b5 & 0xff)): b5

Locale: en_US.UTF-8
isalpha((unsigned char) (0x10b5 & 0xff)): 1
toupper((unsigned char) (0x10b5 & 0xff)): 39c

U+00B5 is the Micro Sign (also known as Mu)
U+03BC is the Greek Small Letter Mu
U+039C is the Greek Capital Letter Mu
2021-10-07 17:46:01 -07:00
Micah Snyder
7fc700a43b libfreshclam: fix zero-byte CDIFF support
Zero-byte CDIFFs are sometimes issued in place of real CDIFFs to force
freshclam to download a whole CVD because using a CDIFF would be less
efficient or otherwise problematic.

There is a bug where freshclam fails to detect if a downloaded CDIFF is
empty. This issue prints an ugly warning message and may require the
user to run freshclam up to 3x before they get over the empty-CVD hump
and are back to normal updates.

This commit resolves this bug by checking the size of the downloaded
CDIFF patch and returning an appropriate status code.
2021-10-07 17:40:42 -07:00
Micah Snyder
7b77717b40 test: freshclam cdiff test tuning
There is a bug where freshclam fails to detect if a downloaded CDIFF is
empty. In 0.103 this, combined with a CDN caching issue could result in
freshclam downloading a daily.cvd but failing to update, putting it in a
sort of infinite loop. In 0.104 this issue manifests slightly
differently, requiring freshclam to run up to 3x before you get over the
empty-CVD hump and are back to normal updates.

This commit updates an existing cdiff test with the zero-byte cdiff + an
out-of-date CVD to confirm the bug. The following commit will fix it.
2021-10-07 17:40:42 -07:00
Micah Snyder
10260c77b3 docker: omit freshclam.dat file from image
The freshclam.dat file shouldn't be in the Docker images or else
everyone using the image will have the same UUID.

This commit deletes it after each update.
2021-09-28 18:21:50 -07:00
Alexander Sulfrian
c5c3b7558e CMake: Fix race condition with parallel builds
If running multiple parallel processes of "xor_testfile.py" there was a
race condition between checking for the existence of the directory and
creating it. Now this is handled as a dependency in CMake.
2021-09-27 13:03:24 -07:00
Ravi Sundriyal
5031593e61 jenkins: discard old builds + artifacts 2021-09-15 14:38:47 -07:00
Micah Snyder
62fb91cb54 Docker: Fix build after CMake/CPack changes
Remove the README and COPYING entries from the .dockerignore file.
These are now required by CPack for the build to succeed.

Also removed the autotools entries, since they no longer exist.
2021-09-02 03:22:48 -07:00
Micah Snyder
d6cf310c08 Readme: Describe the new install packages
Additional clean up to make the Readme easier to read.
2021-08-27 15:24:10 -07:00
Micah Snyder
ac8f7c17ef CMake: restore clamunrar SO version, match clamav
The libclamunrar (and libclamunrar_iface) SO versions tracked
libclamav's SO version in the old Autotools build system.

We accidentally rolled it backwards, setting it to be similar to UnRAR's
project version. Since the official UnRAR project doesn't have a Unix SO
version that we "should" match, and to prevent the theoretical
possibility of having a collision if an old and new clamav were
installed on the same box, we should make libclamunrar's version track
libclamav as it was before (and before 0.104 is released with CMake
being the stable, and only, build system).
2021-08-27 15:16:41 -07:00
Micah Snyder
382ac2764c CMake, Windows: install News, Readme, and html as UserManual
For Windows to match 0.103 installer behavior, include NEWS.md and
README.md and rename the html directory to UserManual during the
install.

Unfortunately I can't match the behavior for the main page for the
user manual. It is now called index.html instead of UserManual.html
and is inside the UserManual directory instead of at the top level.
2021-08-27 14:46:05 -07:00
kang-grace
23dfe8fc4c ClamScan, ClamDScan: process memory scanning (Windows)
Add the process memory scanning feature from ClamWin's ClamScan.
This commit extends that feature to make it available in ClamDScan 
as well.

This adds three new options to ClamScan and ClamDScan on Windows:
* --memory
* --kill
* --unload

--allmatch and --stream are available for ClamDScan.

To reduce code duplication, this refactors clamd related code
used in both scanmem.c and proto.c into clamdcom. 
Moved send_fdpass(), send_stream(), chkpath(), dconnect(), and
dsresult(); as well as some type definitions.

Special thanks to Gianluigi Tiesi for allowing us to integrate the 
Windows process memory scanning feature from ClamWin into the ClamAV.
2021-08-27 09:14:45 -07:00
Simon Arlott
1b276dbe93 Change ReceiveTimeout to use CURLOPT_LOW_SPEED_TIME
Currently ReceiveTimeout sets CURLOPT_TIMEOUT which is an absolute timeout
on the HTTP download and not particularly useful without knowing the size
of the file or the throughput available to download it.

Change it to use CURLOPT_LOW_SPEED_TIME instead, and set the related low
speed limit (CURLOPT_LOW_SPEED_LIMIT) to 1 byte per second. This will allow
the ReceiveTimeout to abort the attempt if the download is not making
any significant progress.

Restore the documentation, default and sample options back to before
2fd28e1d09 and
f5d465a864.

This fixes #266 and avoids problems caused by the Ubuntu default
ReceiveTimeout of 30 seconds.
2021-08-26 16:17:17 -07:00
Micah Snyder
b47745b691 Bump version from 0.104.0 -> 0.105.0-devel-${TODAY}
Also increase FLEVEL from 140 -> 150.
2021-08-24 18:14:40 -07:00
bleve
872a83fbfe Fix systemd detection to detect also older versions of systemd
This fixes issue when building on rhel7/centos7 and other distros with older systemd versions.
2021-08-22 10:14:20 -07:00
Andy Ragusa
11b069db59 Added malloc error handling macros to ole2_extract 2021-08-18 15:21:55 -07:00
Andy Ragusa
c40eaa9c77 Do not set status on read error
The read error could be due to a corrupted or truncated file, so
continue scanning as much as possible.
2021-08-18 15:21:55 -07:00
Andy Ragusa
7c9e2723ae Add error handling to lseek call. 2021-08-18 15:21:55 -07:00
Andy Ragusa
5ea5494f4b Removed unused variable hex 2021-08-18 15:21:55 -07:00
Andy Ragusa
3930ca13d1 Removed Coverity warning about null check after the value is used
Removed Coverity check by declaring subsigid as an array instead
of a pointer that would need to be calloc'd, since the size is
known at compile time.
2021-08-18 15:21:55 -07:00
Andy Ragusa
e74c49bd1b Removed unused variable real_path 2021-08-18 15:21:55 -07:00
Andy Ragusa
df3e859e50 Moved assignedment of 'mdir' before it is used. 2021-08-18 15:21:55 -07:00
Andy Ragusa
9c69c91338 Corrected status to CL_EMEM when cli_calloc fails. 2021-08-18 15:21:55 -07:00
Andy Ragusa
2c17b878bf Initialize the whole biff_parser_state struct to 0, to avoid uninitialized value warnings. 2021-08-18 15:21:55 -07:00
Andy Ragusa
8fd1c66d99 Fix memory leaked when GETD2 returns without freeing original_filename. 2021-08-18 15:21:55 -07:00
Micah Snyder
a868a7a055 CMake: Fix find-curses issue with static libs
If ncurses or pdcurses are static libraries, they are not properly
detected.

First, the user compiling clamav needs to specify if the include path is
for NCURSES or PDCURSES, which will differentiate the two. I've updated
the INSTALL.md file to show this.

Second, the wrong variable was being used to add the include path to the
Curses::curses target, which means that clamdtop would fail to include
ncurses.h. I fixed this.
2021-08-18 13:53:34 -07:00
Micah Snyder
4a9cff9214 CMake: support Xcode builds
Xcode (and perhaps some other generators?) do not like targets that have
only object files. See:
https://cmake.org/cmake/help/latest/command/add_library.html#object-libraries

And: https://cmake.org/pipermail/cmake/2016-May/063479.html

This issue manifests when using `-G Xcode` on macOS as the library
dylibs being missing when linking with other binaries.

This commit removes the object libraries for libclamav, libfreshclam,
libclamunrar_iface, libclamunrar, libclammspack, and (lib)common
because they were used by static or shared libs that didn't
themselves have any added sources.

Add getter & setter for the debug flag, so it isn't referenced by unit
tests or other code that links with libclamav. This is needed because
global variables are exported symbols on Windows.
2021-08-18 13:53:34 -07:00
Micah Snyder
8a6946d866 Jenkins: fix tarball name
The Jenkinsfile renames the tarball, removing the version string suffix.
This is problematic because A) we want that suffix when we publish
release candidates and B) the tarball should extract with the same
directory name as the tarball name.
2021-08-18 13:53:34 -07:00
Micah Snyder
e0e0c8f955 CMake: Support to build deb, rpm, & macOS pkg packages
CMake/CPack is already used to build:
- TGZ source tarball
- WiX-based installer (Windows)
- ZIP install packages (Windows)

This commit adds support for building:
- macOS PKG installer
- DEB package
- RPM package

This should also enable building FreeBSD packages, but while I was able
to build all of the static dependencies using Mussels, CMake/CPack 3.20
doesn't appear to have the the FreeBSD generator despite being in the
documentation.

The package names are will be in this format:
  clamav-<version><suffix>.<os>.<arch>.<extension>

This includes changing the Windows .zip and .msi installer names.

E.g.:
- clamav-0.104.0-rc.macos.x86_64.pkg
- clamav-0.104.0-rc.win.win32.msi
- clamav-0.104.0-rc.win.win32.zip
- clamav-0.104.0-rc.win.x64.msi
- clamav-0.104.0-rc.linux.x86_64.deb
- clamav-0.104.0-rc.linux.x86_64.rpm

Notes about building the packages:

I've only tested this with building ClamAV using static dependencies that
I build using the clamav_deps "host-static" recipes from the "clamav"
Mussels cookbook. Eg:

  msl build clamav_deps -t host-static

Here's an example configuration to build clam in this way, installing to
/usr/local/clamav:

```sh
cmake .. \
  -D CMAKE_FIND_PACKAGE_PREFER_CONFIG=TRUE \
  -D CMAKE_PREFIX_PATH=$HOME/.mussels/install/host-static \
  -D CMAKE_INSTALL_PREFIX="/usr/local/clamav" \
  -D CMAKE_MODULE_PATH=$HOME/.mussels/install/host-static/lib/cmake \
  -D CMAKE_BUILD_TYPE=RelWithDebInfo \
  -D ENABLE_EXAMPLES=OFF \
  -D JSONC_INCLUDE_DIR="$HOME/.mussels/install/host-static/include/json-c" \
  -D JSONC_LIBRARY="$HOME/.mussels/install/host-static/lib/libjson-c.a" \
  -D ENABLE_JSON_SHARED=OFF \
  -D BZIP2_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
  -D BZIP2_LIBRARY_RELEASE="$HOME/.mussels/install/host-static/lib/libbz2_static.a" \
  -D OPENSSL_ROOT_DIR="$HOME/.mussels/install/host-static" \
  -D OPENSSL_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
  -D OPENSSL_CRYPTO_LIBRARY="$HOME/.mussels/install/host-static/lib/libcrypto.a" \
  -D OPENSSL_SSL_LIBRARY="$HOME/.mussels/install/host-static/lib/libssl.a" \
  -D LIBXML2_INCLUDE_DIR="$HOME/.mussels/install/host-static/include/libxml2" \
  -D LIBXML2_LIBRARY="$HOME/.mussels/install/host-static/lib/libxml2.a" \
  -D PCRE2_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
  -D PCRE2_LIBRARY="$HOME/.mussels/install/host-static/lib/libpcre2-8.a" \
  -D CURSES_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
  -D CURSES_LIBRARY="$HOME/.mussels/install/host-static/lib/libncurses.a" \
  -D ZLIB_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
  -D ZLIB_LIBRARY="$HOME/.mussels/install/host-static/lib/libz.a" \
  -D LIBCHECK_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
  -D LIBCHECK_LIBRARY="$HOME/.mussels/install/host-static/lib/libcheck.a"
```

Set CPACK_PACKAGING_INSTALL_PREFIX to customize the resulting package's
install location. This can be different than the install prefix. E.g.:
```sh
  -D CMAKE_INSTALL_PREFIX="/usr/local/clamav" \
  -D CPACK_PACKAGING_INSTALL_PREFIX="/usr/local/clamav" \
```

Then `make` and then one of these, depending on the platform:
```sh
cpack        # macOS: productbuild is default
cpack -G DEB # Debian-based
cpack -G RPM # RPM-based
```

On macOS you'll need to `pip3 install markdown` so that the NEWS.md file can
be converted to html so it will render in the installer.

On RPM-based systems, you'll need rpmbuild (install rpm-build)

This commit also fixes an issue where the html manual (if present) was
not correctly added to the Windows (or now other) install packages.

Fix num to hex function for Windows installer guid

Fix win32 cpack build

Fix macOS cpack build
2021-08-18 13:53:34 -07:00
Micah Snyder
a33fd0b6e6 Update version suffix to rc2
For second release candidate.
2021-08-17 21:34:51 -07:00
Micah Snyder
7c0236fc96 tests: Fix clamd tests when path has symlink
The access-denied test and excludepath tests both relied on the full
path of the test file to be in the expected results. This fails if
you're working within a path that has a symlink because clamd and
clamdscan determine real-paths before scanning and end up sending
back the real-path in the results, not the original path.

This fixes the tests by removing the full paths from the expected
results.

I also cleaned up some type safety warnings.
2021-08-17 12:40:23 -07:00
Micah Snyder
efd8ac5244 Manpages: Add environment variables to the docs
The CURL_CA_BUNDLE environment variable used by freshclam & clamsubmit to
specify a custom path to a CA bundle is undocumented.

Feature was added here: https://bugzilla.clamav.net/show_bug.cgi?id=12504

Resolves: https://github.com/Cisco-Talos/clamav/issues/175

Also document:
- clamd/clamscan: using LD_LIBRARY_PATH to find libclamunrar_iface.so/dylib
- sigtool: using SIGNDUSER, SIGNDPASS for auth creds when building CVD

This info also needs to be added to the online documentation.
2021-08-17 10:33:15 -07:00
Micah Snyder
8cfaf5f5f6 Test: CDIFF update with UNC paths (Windows)
This is a regression test for https://github.com/Cisco-Talos/clamav/pull/226
2021-08-16 12:10:11 -07:00
kang-grace
5a15a7e298 Freshclam: Fix network path renaming bug (Windows)
* Changed rename() on Windows
via w32_rename(). rename() doesn't work on Windows if the dest file
already exists.

* Change access() and buildcld() to support UNC paths
access uses CreateFileA() and buildcld() opens absolute path to tmpdir
2021-08-16 09:28:29 -07:00
Micah Snyder
22c724cf78 HWP: remove unused signature field from JSON
We don't actually use the Signature (magic bytes) field, which is
pre-verified anyways when checking if the document is HWP.
2021-08-16 07:53:48 -07:00
Micah Snyder
e13d752789 INSTALL.md: step-by-step instructions -> docs.clamav.net
Move all step-by-step instructions for installing dependencies to
docs.clamav.net.

INSTALL.md serves to direct folks to our online documentation (or
the offline copy in the release tarball), and as a reference for
all custom config options.

Add some introductory CMake material to help people new to CMake.

Add un-install instructions.

Also fix broken links in README.md.
2021-08-14 15:04:21 -07:00
Micah Snyder
11b66a8350 libclamav: Increase FLEVEL by 10 more to 140
For reference, version 0.103 started at 120 and we're already at 124
with v0.103.3.

Ordinarily we would reserve 10 FLEVELs for each feature release, but
we're implementing a new Long Term Support (LTS) program and will be
starting with 0.103, which means additional critical bug fixes for the
0.103 series for the next 2-3 years.

This commit pushes v0.104's FLEVEL to 140 to ensure that there will be
enough FLEVELs for future 0.103 patch versions.
2021-08-14 15:04:21 -07:00
Tim Gates
251befbdf3 docs: Fix a few typos
docs: Fix a few typos

There are small typos in:
- libclamav/others_common.c
- libclamav/pe.c
- libclamav/unzip.c

Fixes:
- Should read `descriptor` rather than `desriptor`.
- Should read `record` rather than `reocrd`.
- Should read `overarching` rather than `overaching`.
2021-08-09 15:41:17 -07:00
kang-grace
e68b14efc9 clamdscan: Fix directory scan on Windows
Cause: _wopen() on Windows doesn't work on directories and gives a
Permission Denied error.

The old approach used _wopen() to get a file descriptor and gets the
realpath from that. 
The new approach opens a HANDLE with CreateFileA() with
FILE_FLAG_BACKUP_SEMANTICS to support directories.

Refactor the cli_get_filepath_from_filedesc() function by adding
cli_get_filepath_from_handle().
2021-08-09 14:24:16 -07:00
Mickey Sola
d0d0a8307c clamonacc: Fix segfault and socket fd leak
This fixes a fatal issue that would occur when unable to queue events due to
clamonacc improperly using all available fds.

It also fixes the core fd socket leak issue at the heart of the segfault by
properly cleaning up after a failed curl connection.

Lastly, worst case recovery code now allows more time for consumer queue
to catchup. It accomplishes this by increasing wait time and adding
retry logic.

More info: https://github.com/Cisco-Talos/clamav/issues/184
2021-08-05 17:33:21 -07:00
Micah Snyder
f75c3b3b4c Github actions: Update package list before install
To fix issues with installing older packages that may have been replaced
2021-08-05 16:54:02 -07:00
Micah Snyder
1cda765843 CMake: Fix build on systems lacking inttypes format string macros
Define _SF64_PREFIX and _SF32_PREFIX on systems that do not have these
macros: PRIu64, PRIx64, PRIi64, PRIu32, PRIi32, PRIx32

This logic is the same as in the previous build system, here:
https://github.com/Cisco-Talos/clamav/blob/rel/0.102/m4/reorganization/types.m4#L83

Patch courtesy of Mark Fortescue.
2021-08-05 16:54:02 -07:00
Grace Kang
657a8e0ff8 CLAM-1535: Long file path support on Windows
via clam.manifest in win32/res. Opts into new Windows behavior that
does not have file path limitations.
Only works on Windows 10. In addition, you must set the registry key
"LongPathsEnabled" to  1.
(as described here: https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell)
2021-08-05 14:49:55 -07:00
Andy Ragusa
c4af06c317 Fix ENABLE_UNRAR=off build
Cmake errors out when the ENABLE_UNRAR=off option is used.  This commit
addresses that.
2021-07-31 11:17:27 -07:00
Micah Snyder
5dd64380ad News: Update acknowledgements 2021-07-30 14:48:01 -07:00
Andy Ragusa
4db6e1de0a Tests: tune valgrind suppression rule
Handle the case where thrmgr_dispatch_internal was called from somewhere
other than thrmgr_group_dispatch, triggering the valgrind supression
rule.
2021-07-30 14:45:43 -07:00
Arjen de Korte
9f8b01ec79 cmake/FindIconv.cmake: fix return type in test code
In openSUSE Tumbleweed, this test always fails because it compiles with `-Werror=return-type` by default. Fixing this by adding a return value in the test script to keep the compiler happy.
2021-07-30 14:23:13 -07:00
Andy Ragusa
ee15dd7e0d Fix clamd_valgrind tests when built with clang-8
Since strcpy only writes a null-byte to the first terminating byte,
valgrind is throwing errors about uninitialized reads for strncpy's
that could potentially read beyond the null-byte.  Initializing
the whole array to 0 resolves this.
2021-07-30 12:46:25 -07:00
Andy Ragusa
4c8444957a Fix mspack library name
Modified to change libmspack to libclammspack to avoid name collisions
on installation.
2021-07-29 18:07:52 -07:00