]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
3 years agostacktrace-on-signal: Use kill(getpid(), sig_num) 7389/head 7395/head
Arne Welzel [Wed, 4 May 2022 18:06:36 +0000 (20:06 +0200)] 
stacktrace-on-signal: Use kill(getpid(), sig_num)

kill(0, ...) re-raises the signal to every processes in the process
group which may impact unrelated processes.

Concretely, in our CI pipeline, a segfaulting Suricata process killed
the test driver.

3 years agosuricata.yaml: include version that generated this file
Jason Ish [Wed, 4 May 2022 21:19:48 +0000 (15:19 -0600)] 
suricata.yaml: include version that generated this file

Add a line to the configuration that says which version generated the
configuration file.  For example:

    # This configuration generated by:
    #     Suricata 7.0.0-dev

Issue: #4784

3 years agostream/segtree: improve docs, error handling
Victor Julien [Tue, 22 Mar 2022 15:59:17 +0000 (16:59 +0100)] 
stream/segtree: improve docs, error handling

3 years agostreaming/buffer: add debug validation for 'impossible' condition
Victor Julien [Tue, 22 Mar 2022 15:55:52 +0000 (16:55 +0100)] 
streaming/buffer: add debug validation for 'impossible' condition

3 years agoapp-layer: make registration structure more compact
Victor Julien [Tue, 3 May 2022 17:56:19 +0000 (19:56 +0200)] 
app-layer: make registration structure more compact

3 years agohtp: minor format string fixes 7392/head
Victor Julien [Thu, 5 May 2022 08:41:15 +0000 (10:41 +0200)] 
htp: minor format string fixes

3 years agodatasets: constify some function args
Victor Julien [Thu, 28 Apr 2022 15:50:30 +0000 (17:50 +0200)] 
datasets: constify some function args

3 years agotime: reduce scope of static string
Victor Julien [Wed, 27 Apr 2022 19:28:53 +0000 (21:28 +0200)] 
time: reduce scope of static string

3 years agothreshold: constify detect engine arg
Victor Julien [Wed, 27 Apr 2022 19:28:25 +0000 (21:28 +0200)] 
threshold: constify detect engine arg

3 years agothash: reduce scope for var; suggested by cppcheck
Victor Julien [Wed, 27 Apr 2022 19:27:50 +0000 (21:27 +0200)] 
thash: reduce scope for var; suggested by cppcheck

3 years agospm: constify badchars; suggested by cppcheck
Victor Julien [Wed, 27 Apr 2022 19:27:07 +0000 (21:27 +0200)] 
spm: constify badchars; suggested by cppcheck

3 years agoradix: small cppcheck suggested cleanup
Victor Julien [Wed, 27 Apr 2022 19:26:19 +0000 (21:26 +0200)] 
radix: small cppcheck suggested cleanup

3 years agopacketpool: minor cleanup
Victor Julien [Wed, 27 Apr 2022 19:25:51 +0000 (21:25 +0200)] 
packetpool: minor cleanup

3 years agostream: minor code cleanups suggested by cppcheck
Victor Julien [Wed, 27 Apr 2022 19:21:09 +0000 (21:21 +0200)] 
stream: minor code cleanups suggested by cppcheck

3 years agodefrag: minor code cleanups suggested by cppcheck
Victor Julien [Wed, 27 Apr 2022 19:19:43 +0000 (21:19 +0200)] 
defrag: minor code cleanups suggested by cppcheck

3 years agooutput/flow: no double var init
Victor Julien [Wed, 27 Apr 2022 19:18:57 +0000 (21:18 +0200)] 
output/flow: no double var init

3 years agosmtp: minor code cleanup
Victor Julien [Wed, 27 Apr 2022 19:18:17 +0000 (21:18 +0200)] 
smtp: minor code cleanup

3 years agoapp-layer: minor code cleanups suggested by cppcheck
Victor Julien [Wed, 27 Apr 2022 19:16:05 +0000 (21:16 +0200)] 
app-layer: minor code cleanups suggested by cppcheck

3 years agoapp-layer/expectation: reduce scope and init vars
Victor Julien [Wed, 27 Apr 2022 19:15:25 +0000 (21:15 +0200)] 
app-layer/expectation: reduce scope and init vars

3 years agoftp: code clarifications
Victor Julien [Wed, 27 Apr 2022 18:19:09 +0000 (20:19 +0200)] 
ftp: code clarifications

src/app-layer-ftp.c:945:49: style: Parameter 'ftp_state' can be declared with const [constParameter]
static FTPTransaction *FTPGetOldestTx(FtpState *ftp_state, FTPTransaction *starttx)
                                                ^

3 years agoutil/byte: minor cleanup
Victor Julien [Wed, 27 Apr 2022 15:28:14 +0000 (17:28 +0200)] 
util/byte: minor cleanup

3 years agothreads: remove usused code; wrap in guards
Victor Julien [Wed, 27 Apr 2022 15:21:25 +0000 (17:21 +0200)] 
threads: remove usused code; wrap in guards

3 years agothreads: remove unused function
Victor Julien [Wed, 27 Apr 2022 14:52:43 +0000 (16:52 +0200)] 
threads: remove unused function

3 years agounittests: wrap unittest registration in guards
Victor Julien [Wed, 27 Apr 2022 14:54:49 +0000 (16:54 +0200)] 
unittests: wrap unittest registration in guards

3 years agoapp-layer/profiling: hide profiling code behind guards
Victor Julien [Wed, 27 Apr 2022 14:49:24 +0000 (16:49 +0200)] 
app-layer/profiling: hide profiling code behind guards

3 years agoapp-layer/events: remove unused function
Victor Julien [Wed, 27 Apr 2022 14:47:12 +0000 (16:47 +0200)] 
app-layer/events: remove unused function

3 years agooutput/frames: fix eof var overwrite
Victor Julien [Wed, 27 Apr 2022 14:40:14 +0000 (16:40 +0200)] 
output/frames: fix eof var overwrite

3 years agostream/reassembly: reduce scope of variable
Victor Julien [Wed, 27 Apr 2022 14:37:28 +0000 (16:37 +0200)] 
stream/reassembly: reduce scope of variable

3 years agostream/buffer: remove redundant check
Victor Julien [Wed, 27 Apr 2022 13:57:45 +0000 (15:57 +0200)] 
stream/buffer: remove redundant check

3 years agodecode/checksums: constify pointer args
Victor Julien [Wed, 27 Apr 2022 13:48:18 +0000 (15:48 +0200)] 
decode/checksums: constify pointer args

3 years agodetect/state: address cppcheck warnings
Victor Julien [Wed, 27 Apr 2022 13:35:46 +0000 (15:35 +0200)] 
detect/state: address cppcheck warnings

src/detect-engine-state.c:127:91: style: Suspicious calculation. Please use parentheses to clarify the code. The code ''a&b?c:d'' should be written as either ''(a&b)?c:d'' or ''a&(b?c:d)''. [clarifyCalculation]
    DetectEngineStateDirection *dir_state = &state->dir_state[direction & STREAM_TOSERVER ? 0 : 1];
                                                                                          ^
src/detect-engine-state.c:194:53: style: Suspicious calculation. Please use parentheses to clarify the code. The code ''a&b?c:d'' should be written as either ''(a&b)?c:d'' or ''a&(b?c:d)''. [clarifyCalculation]
    de_state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].filestore_cnt += file_no_match;
                                                    ^
src/detect-engine-state.c:201:57: style: Suspicious calculation. Please use parentheses to clarify the code. The code ''a&b?c:d'' should be written as either ''(a&b)?c:d'' or ''a&(b?c:d)''. [clarifyCalculation]
    if (de_state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].filestore_cnt == sgh->filestore_cnt)
                                                        ^

3 years agodetect/file: minor code cleanup
Victor Julien [Wed, 27 Apr 2022 13:33:20 +0000 (15:33 +0200)] 
detect/file: minor code cleanup

Reduce scope where possible. Suggested by cppcheck.

3 years agorunmodes: fix more warnings
Victor Julien [Thu, 28 Apr 2022 15:49:07 +0000 (17:49 +0200)] 
runmodes: fix more warnings

3 years agomemcmp: no-simd no case loop can scan forward
Victor Julien [Fri, 6 May 2022 21:52:00 +0000 (23:52 +0200)] 
memcmp: no-simd no case loop can scan forward

3 years agomemcmp: use SCMEMCMP_BYTES everywhere; general cleanups
Victor Julien [Fri, 6 May 2022 16:20:40 +0000 (18:20 +0200)] 
memcmp: use SCMEMCMP_BYTES everywhere; general cleanups

3 years agomemcmp: work around GCC 12+ 'blend' issues
Victor Julien [Fri, 6 May 2022 15:46:40 +0000 (17:46 +0200)] 
memcmp: work around GCC 12+ 'blend' issues

Since GCC 12 the memcmp code using `_mm_blendv_epi8` failed to work.
Inspection of the disassembled objects suggests that it simply omits
the instruction on systems that are not AVX512 capable. On AVX512
it does replace it with VPCMPB logic that appears to work.

Luckily our use of blend is actually uncessary. A simple AND is sufficient.

Bug: #5312.

3 years agomemcmp: remove unreachable code from memcmp simd
Victor Julien [Thu, 5 May 2022 05:16:53 +0000 (07:16 +0200)] 
memcmp: remove unreachable code from memcmp simd

cppcheck:

src/util-memcmp.h:281:18: warning: Identical condition 'len-offset<16', second condition is always false [identicalConditionAfterEarlyExit]
        if (diff < 16) {
                 ^
src/util-memcmp.h:280:24: note: 'diff' is assigned value 'len-offset' here.
        int diff = len - offset;
                       ^
src/util-memcmp.h:269:33: note: If condition 'len-offset<16' is true, the function will return/exit
        if (likely(len - offset < 16)) {
                                ^
src/util-memcmp.h:281:18: note: Testing identical condition 'len-offset<16'
        if (diff < 16) {
                 ^
src/util-memcmp.h:344:18: warning: Identical condition 'len-offset<16', second condition is always false [identicalConditionAfterEarlyExit]
        if (diff < 16) {
                 ^
src/util-memcmp.h:343:24: note: 'diff' is assigned value 'len-offset' here.
        int diff = len - offset;
                       ^
src/util-memcmp.h:318:33: note: If condition 'len-offset<16' is true, the function will return/exit
        if (likely(len - offset < 16)) {
                                ^
src/util-memcmp.h:344:18: note: Testing identical condition 'len-offset<16'
        if (diff < 16) {
                 ^
src/util-memcmp.h:171:18: warning: Identical condition 'len-offset<16', second condition is always false [identicalConditionAfterEarlyExit]
        if (diff < 16) {
                 ^
src/util-memcmp.h:170:24: note: 'diff' is assigned value 'len-offset' here.
        int diff = len - offset;
                       ^
src/util-memcmp.h:159:33: note: If condition 'len-offset<16' is true, the function will return/exit
        if (likely(len - offset < 16)) {
                                ^
src/util-memcmp.h:171:18: note: Testing identical condition 'len-offset<16'
        if (diff < 16) {
                 ^
src/util-memcmp.h:233:18: warning: Identical condition 'len-offset<16', second condition is always false [identicalConditionAfterEarlyExit]
        if (diff < 16) {
                 ^
src/util-memcmp.h:232:24: note: 'diff' is assigned value 'len-offset' here.
        int diff = len - offset;
                       ^
src/util-memcmp.h:208:33: note: If condition 'len-offset<16' is true, the function will return/exit
        if (likely(len - offset < 16)) {
                                ^
src/util-memcmp.h:233:18: note: Testing identical condition 'len-offset<16'
        if (diff < 16) {
                 ^

3 years agodetect/iponly: fix debug compiler warning
Victor Julien [Fri, 6 May 2022 09:13:09 +0000 (11:13 +0200)] 
detect/iponly: fix debug compiler warning

3 years agodcerpc: convert transaction list to vecdeque 7367/head
Jason Ish [Mon, 2 May 2022 18:19:51 +0000 (12:19 -0600)] 
dcerpc: convert transaction list to vecdeque

Allows for more efficient removal from front of the list.

Ticket: #5271

3 years agomqtt, rdp: fix copyright dates
Jason Ish [Mon, 2 May 2022 18:19:29 +0000 (12:19 -0600)] 
mqtt, rdp: fix copyright dates

3 years agorust: RustParser same fields as AppLayerParser
Philippe Antoine [Mon, 2 May 2022 20:50:04 +0000 (22:50 +0200)] 
rust: RustParser same fields as AppLayerParser

So that there is no problem when crossing FFI

3 years agoconfigure.ac: handle undefined LEVEL1_DCACHE_LINESIZE
Sascha Steinbiss [Sat, 30 Apr 2022 12:20:38 +0000 (14:20 +0200)] 
configure.ac: handle undefined LEVEL1_DCACHE_LINESIZE

On some platforms (riscv64, s390x) this value is "undefined" as returned
from getconf. We also need to handle this to avoid using the string
"undefined" blindly in further #defines.

3 years agodoc: add note about file.data and file_data
jason taylor [Mon, 2 May 2022 12:06:56 +0000 (12:06 +0000)] 
doc: add note about file.data and file_data

Signed-off-by: jason taylor <jtfas90@gmail.com>
3 years agodoc: update file_data to file.data keyword
jason taylor [Tue, 26 Apr 2022 20:49:19 +0000 (20:49 +0000)] 
doc: update file_data to file.data keyword

Signed-off-by: jason taylor <jtfas90@gmail.com>
3 years agodoc: remove extra newline in order to match style
jason taylor [Tue, 26 Apr 2022 20:35:52 +0000 (20:35 +0000)] 
doc: remove extra newline in order to match style

Signed-off-by: jason taylor <jtfas90@gmail.com>
3 years agodoc: remove extraneous + characters
jason taylor [Tue, 26 Apr 2022 20:33:07 +0000 (20:33 +0000)] 
doc: remove extraneous + characters

Signed-off-by: jason taylor <jtfas90@gmail.com>
3 years agoftp-data: fix direction for active mode commands 7356/head
Victor Julien [Sat, 30 Apr 2022 14:54:07 +0000 (16:54 +0200)] 
ftp-data: fix direction for active mode commands

Set correct direction for PORT mode, where the server connects
to the client.

The direction is not also strictly enforced. No data in the wrong
direction will be accepted to setup the file or to be added to the
file after setup.

This also fixes files getting closed twice.

Adds some general cleanups.

Bug: #3542.

3 years agonfs3/records: Fix typo 7349/head
Sam Muhammed [Sat, 12 Feb 2022 17:53:00 +0000 (19:53 +0200)] 
nfs3/records: Fix typo

Fix response_lookup unittest name

3 years agotemplate: convert GetTx to SCLogDebug
Philippe Antoine [Thu, 14 Apr 2022 11:54:53 +0000 (13:54 +0200)] 
template: convert GetTx to SCLogDebug

as it is especially verbose for fuzzing

3 years agoscripts/bundle: use git instead of tar.gz
Jason Ish [Thu, 21 Apr 2022 19:41:15 +0000 (13:41 -0600)] 
scripts/bundle: use git instead of tar.gz

To better fit with our current CI processes, use git to clone the
suricata-update and libhtp dependencies.  The requirements.txt file has
been modified to take a repo URL and a `-b` command line option for tag
or branch.

For the master branch we will use the libhtp 0.5.x branch and the
suricata-update master branch.

Also allows for repo and branch names to be overrided with environment
variables:
- SU_REPO
- SU_BRANCH
- LIBHTP_REPO
- LIBHTP_BRANCH

3 years agodecode: fix integer warnings
Philippe Antoine [Tue, 18 Jan 2022 14:29:17 +0000 (15:29 +0100)] 
decode: fix integer warnings

Ticket: 4516

3 years agoftp: truncate first segment if over max length
Jason Ish [Fri, 22 Apr 2022 18:04:37 +0000 (12:04 -0600)] 
ftp: truncate first segment if over max length

The first segment was not limited to the configured maximum line length
allowing it to be up to 65k. This could result in the next input length
being negative, which while handled properly by the code, did trigger a
debug validation assertion.

The fix is to be consistent and apply the limit to the first segment as
well, which does ensure the input_len could never be less than 0.

Ticket #5281

3 years agodns: add pdu frame
Jason Ish [Tue, 8 Feb 2022 19:42:37 +0000 (13:42 -0600)] 
dns: add pdu frame

Adds a PDU frame to the DNS parser. For UDP this is the DNS payload
portion of the DNS packet, for TCP this is the payload minus the leading
legth field.

Ticket: 4984

3 years agoframes(rust): don't call into C if running Rust unit tests
Jason Ish [Tue, 26 Apr 2022 20:59:18 +0000 (14:59 -0600)] 
frames(rust): don't call into C if running Rust unit tests

Wrap the calls behind frames to C code if a `cfg!(not(test))` so they
don't get compiled when running Rust unit tests.  Linkage to C functions
is not yet available for Rust unit tests, and this will keep the check
out of individual parsers.

Ticket: 4984

3 years agoframes (rust): method to create StreamSlice from slice
Jason Ish [Tue, 8 Feb 2022 21:45:05 +0000 (15:45 -0600)] 
frames (rust): method to create StreamSlice from slice

Useful in unit test for function that require a StreamSlice.

3 years agodoc/userguide: updates for eve dns v1 removal
Jason Ish [Wed, 27 Apr 2022 19:13:07 +0000 (13:13 -0600)] 
doc/userguide: updates for eve dns v1 removal

Ticket: #4157

3 years agoeve/dns: remove dns v1 logging
Jason Ish [Wed, 27 Apr 2022 18:32:18 +0000 (12:32 -0600)] 
eve/dns: remove dns v1 logging

Removal of DNS v1 logging was scheduled to be removed in May 2022.

Ticket: #4157

3 years agogithub-actions: bump github/codeql-action from 2.1.8 to 2.1.9
dependabot[bot] [Wed, 27 Apr 2022 19:29:46 +0000 (19:29 +0000)] 
github-actions: bump github/codeql-action from 2.1.8 to 2.1.9

Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.1.8 to 2.1.9.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/1ed1437484560351c5be56cf73a48a279d116b78...7502d6e991ca767d2db617bfd823a1ed925a0d59)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
3 years agodetect: update copyright years
Juliana Fajardini [Thu, 21 Apr 2022 14:51:21 +0000 (11:51 -0300)] 
detect: update copyright years

3 years agoassorted: fix low hanging typos
Juliana Fajardini [Thu, 21 Apr 2022 15:47:03 +0000 (12:47 -0300)] 
assorted: fix low hanging typos

3 years agouserguide: explain alert queue behavior and stats
Juliana Fajardini [Wed, 6 Apr 2022 20:06:09 +0000 (17:06 -0300)] 
userguide: explain alert queue behavior and stats

Added sections along packet-alert-max config section explaining
packet alert queue overflow (when Suri reaches packet alert max), when
alerts are discarded etc.

Since from the user perspective it shouldn't matter how we process the
alert queue, the term "replace" is used, even though there's not exactly
a replacing action happening, with the queue bein pre-processed before
being appended to the Packet.

Also described the associated stats and added an explanation on when to
change packet-alert-max.

Task #5178

3 years agodetect/stats: log out total of suppressed alerts
Juliana Fajardini [Wed, 20 Apr 2022 16:49:31 +0000 (13:49 -0300)] 
detect/stats: log out total of suppressed alerts

Related to
Task #4943
Task #5179

3 years agodetect/stats: log out total of discarded alerts
Juliana Fajardini [Tue, 5 Apr 2022 19:54:29 +0000 (16:54 -0300)] 
detect/stats: log out total of discarded alerts

Add a counter to our stats log with the total of alerts that have been
discarded due to packet alert queue overflow.

Task #5179

3 years agodetect/alert: move apply-action-flow code to func
Juliana Fajardini [Wed, 27 Apr 2022 22:18:27 +0000 (19:18 -0300)] 
detect/alert: move apply-action-flow code to func

Trying to clean PacketAlertFinalize a bit more.

3 years agodetect/alert: remove unused functions
Juliana Fajardini [Wed, 20 Apr 2022 20:50:43 +0000 (17:50 -0300)] 
detect/alert: remove unused functions

Since we now only copy the PacketAlerts to the Packet's queue after
processing them, we no longer do packet alert appending from
detect-engine-alert, nor do we remove PacketAlerts from the queue (if
they're discarded by overflow or thresholding, they're not copied to the
final alert queue).

Task #4943

3 years agodetect/alert: preprocess then append alert queue
Juliana Fajardini [Tue, 19 Apr 2022 20:43:10 +0000 (17:43 -0300)] 
detect/alert: preprocess then append alert queue

Do all alert queue processing before actually appending
the PacketAlerts to the Packet's alert queue.

Task #4943

3 years agodetect/alert: use tx id in alert if frame has it
Juliana Fajardini [Tue, 26 Apr 2022 14:57:49 +0000 (11:57 -0300)] 
detect/alert: use tx id in alert if frame has it

Task #4943

3 years agodetect/engine: use alert queue from det_ctx
Juliana Fajardini [Tue, 19 Apr 2022 13:58:22 +0000 (10:58 -0300)] 
detect/engine: use alert queue from det_ctx

Task #4943

3 years agodetect/alert: add infra for new alert queue
Juliana Fajardini [Mon, 18 Apr 2022 21:14:52 +0000 (18:14 -0300)] 
detect/alert: add infra for new alert queue

Initial work to bring part of the alert queue processing to
DetectEngineThreadCtx.

Task #4943

3 years agodoc/userguide: explain packet-alert-max config
Juliana Fajardini [Wed, 6 Apr 2022 14:54:52 +0000 (11:54 -0300)] 
doc/userguide: explain packet-alert-max config

Task #4207

3 years agodecode: make packet_alert_max configurable
Juliana Fajardini [Wed, 19 Jan 2022 18:29:39 +0000 (18:29 +0000)] 
decode: make packet_alert_max configurable

The maximum of possible alerts triggered by a unique packet was
hardcoded to 15. With usage of 'noalert' rules, that limit could be
reached somewhat easily. Make that configurable via suricata.yaml.

Conf Bug#4941

Task #4207

3 years agotemplate(rust): convert transaction list to vecdeque
Jason Ish [Wed, 27 Apr 2022 16:16:02 +0000 (10:16 -0600)] 
template(rust): convert transaction list to vecdeque

Allows for more efficient removal from front of the list.

Ticket: #5298

3 years agopgsql: convert transaction list to vecdeque
Jason Ish [Wed, 27 Apr 2022 15:47:19 +0000 (09:47 -0600)] 
pgsql: convert transaction list to vecdeque

Allows for more efficient removal from front of the list.

Ticket: #5297

3 years agohttp2: convert transaction list to vecdeque
Jason Ish [Wed, 27 Apr 2022 15:38:51 +0000 (09:38 -0600)] 
http2: convert transaction list to vecdeque

Allows for more efficient removal from front of the list.

Ticket: #5296

3 years agordp: convert transaction list to vecdeque
Jason Ish [Wed, 27 Apr 2022 15:29:30 +0000 (09:29 -0600)] 
rdp: convert transaction list to vecdeque

Allows for more efficient removal from front of the list.

Ticket: #5295

3 years agomqtt: convert transaction list to vecdeque
Jason Ish [Wed, 27 Apr 2022 15:25:13 +0000 (09:25 -0600)] 
mqtt: convert transaction list to vecdeque

Allows for more efficient removal from front.

Ticket: #5294

3 years agodns: convert transaction list to vecdeque
Jason Ish [Tue, 26 Apr 2022 19:25:40 +0000 (13:25 -0600)] 
dns: convert transaction list to vecdeque

Allows for more efficient removal from front of the list.

Ticket: #5277

3 years agoapp-layer: more generic state trait
Jason Ish [Tue, 26 Apr 2022 19:21:40 +0000 (13:21 -0600)] 
app-layer: more generic state trait

Instead of a method that is required to return a slice of transactions,
use 2 methods, one to return the number of transactions in the
collection, and another to get a transaction by its index in the
collection.

This allows for the transaction collection to not be a contiguous array
and instead can be a VecDeque, or possibly another collection type that
supports retrieval by index.

Ticket #5278

3 years agopgsql: apply clippy fixes
Juliana Fajardini [Fri, 29 Apr 2022 20:21:45 +0000 (17:21 -0300)] 
pgsql: apply clippy fixes

3 years agopgsql: fix uint overflow and optimizations
Juliana Fajardini [Fri, 4 Feb 2022 10:58:27 +0000 (10:58 +0000)] 
pgsql: fix uint overflow and optimizations

Fuzzers found a possible integer overflow bug when parsing response
messages. To fix that, removed the case where we incremented the parsed
field length and created a new message type for situations where Suri
parsers an Unknown message. This is good because there may happen that
an unknown message to Suri is valid, and in this case, we would still be
able to log it.

Philippe Antoine found the bug while fuzzing with rust debug assertions.

Bug #5016

3 years agopgsql: fix clippy is_null usage warning
Juliana Fajardini [Wed, 26 Jan 2022 17:33:23 +0000 (17:33 +0000)] 
pgsql: fix clippy is_null usage warning

3 years agoutil: add unit tests for CIDRFromMask()
Sascha Steinbiss [Wed, 27 Apr 2022 21:12:26 +0000 (23:12 +0200)] 
util: add unit tests for CIDRFromMask()

3 years agodetect: make int CIDRFromMask() work on big endian platforms
Sascha Steinbiss [Wed, 27 Apr 2022 18:09:50 +0000 (20:09 +0200)] 
detect: make int CIDRFromMask() work on big endian platforms

3 years agodcerpc: use wrappingadd for padding parsing
Philippe Antoine [Sat, 2 Apr 2022 19:41:56 +0000 (21:41 +0200)] 
dcerpc: use wrappingadd for padding parsing

As we compute a modulo, we can safely wrap around even if there
is an overflow

Ticket: #5301

3 years agologopenfile: fix minor format string warning 7322/head
Victor Julien [Wed, 27 Apr 2022 09:39:27 +0000 (11:39 +0200)] 
logopenfile: fix minor format string warning

cppcheck:

src/util-logopenfile.c:743:13: warning: %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
            snprintf(threaded_name, len, "%s.%d.%s", tname, unique_id, ext);
            ^
src/util-logopenfile.c:752:9: warning: %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
        snprintf(threaded_name, len, "%s.%d", original_name, unique_id);
        ^

Bug: #5291.

3 years agoja3: fix minor format string warning
Victor Julien [Wed, 27 Apr 2022 09:38:37 +0000 (11:38 +0200)] 
ja3: fix minor format string warning

cppcheck:

src/util-ja3.c:197:28: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
        (*buffer)->used += snprintf((*buffer)->data, (*buffer)->size, "%d",
                           ^
src/util-ja3.c:201:28: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
        (*buffer)->used += snprintf((*buffer)->data + (*buffer)->used,
                           ^

Bug: #5291.

3 years agolog-pcap: remove redundant check
Victor Julien [Wed, 27 Apr 2022 09:36:21 +0000 (11:36 +0200)] 
log-pcap: remove redundant check

Check is always true but confuses cppcheck:

src/log-pcap.c:1224:32: warning: Either the condition 'filename' is redundant or there is possible null pointer dereference: filename. [nullPointerRedundantCheck]
    if ((pl->prefix = SCStrdup(filename)) == NULL) {
                               ^
src/log-pcap.c:1421:9: note: Assuming that condition 'filename' is not redundant
    if (filename) {
        ^
src/log-pcap.c:1224:32: note: Null pointer dereference
    if ((pl->prefix = SCStrdup(filename)) == NULL) {
                               ^

Bug: #5291.

3 years agoaf-packet/v2: use proper type for ring
Victor Julien [Wed, 27 Apr 2022 09:32:22 +0000 (11:32 +0200)] 
af-packet/v2: use proper type for ring

cppcheck:

src/source-af-packet.c:1762:19: warning: Size of pointer 'v2' used instead of size of its data. This is likely to lead to a buffer overflow. You probably intend to write 'sizeof(*v2)'. [pointerSize]
        ptv->ring.v2 = SCMalloc(ptv->req.v2.tp_frame_nr * sizeof (union thdr *));
                  ^
src/source-af-packet.c:1767:26: warning: Size of pointer 'v2' used instead of size of its data. This is likely to lead to a buffer overflow. You probably intend to write 'sizeof(*v2)'. [pointerSize]
        memset(ptv->ring.v2, 0, ptv->req.v2.tp_frame_nr * sizeof (union thdr *));
                         ^

scan-build:

CC       source-af-packet.o
source-af-packet.c:1762:24: warning: Result of 'malloc' is converted to a pointer of type 'char', which is incompatible with sizeof operand type 'union thdr *' [unix.MallocSizeof]
        ptv->ring.v2 = SCMalloc(ptv->req.v2.tp_frame_nr * sizeof (union thdr *));
                       ^~~~~~~~                           ~~~~~~~~~~~~~~~~~~~~~
./util-mem.h:35:18: note: expanded from macro 'SCMalloc'
                 ^~~~~~
1 warning generated.

Bug: #5291.

3 years agodetect/pcre: assist code analyzer around pointer logic
Victor Julien [Tue, 26 Apr 2022 19:47:37 +0000 (21:47 +0200)] 
detect/pcre: assist code analyzer around pointer logic

cppcheck:

src/detect-pcre.c:381:27: warning: Either the condition 'pcap' is redundant or there is overflow in pointer subtraction. [nullPointerArithmeticRedundantCheck]
            cut_capture = MIN((pcap - regexstr), (fcap - regexstr));
                          ^
src/detect-pcre.c:378:18: note: Assuming that condition 'pcap' is not redundant
        else if (pcap && !fcap)
                 ^
src/detect-pcre.c:381:27: note: Null pointer subtraction
            cut_capture = MIN((pcap - regexstr), (fcap - regexstr));
                          ^

Bug: #5291.

3 years agodevice: avoid uninit var warning
Victor Julien [Tue, 26 Apr 2022 19:35:29 +0000 (21:35 +0200)] 
device: avoid uninit var warning

cppcheck:

src/util-device.c:455:17: error: Uninitialized variables: *ndev.dev, *ndev.tenant_id_set, *ndev.id, *ndev.next, *ndev.tenant_id, *ndev.offload_orig [uninitvar]
        *ldev = *ndev;
                ^
src/util-device.c:618:36: note: Calling function 'LiveDeviceForEach', 2nd argument '&ndev' value is <Uninit>
    while(LiveDeviceForEach(&ldev, &ndev)) {
                                   ^
src/util-device.c:455:17: note: Uninitialized variables: *ndev.dev, *ndev.tenant_id_set, *ndev.id, *ndev.next, *ndev.tenant_id, *ndev.offload_orig
        *ldev = *ndev;
                ^

Bug: #5291.

3 years agodetect: fix bad BUG_ON pattern
Victor Julien [Tue, 26 Apr 2022 19:33:52 +0000 (21:33 +0200)] 
detect: fix bad BUG_ON pattern

cppcheck:

src/detect-engine-uint.c:73:13: warning: Conversion of string literal "unknown mode" to bool always evaluates to true. [incorrectStringBooleanError]
            BUG_ON("unknown mode");
            ^
src/detect-engine-uint.c:328:13: warning: Conversion of string literal "unknown mode" to bool always evaluates to true. [incorrectStringBooleanError]
            BUG_ON("unknown mode");
            ^
src/detect-pcre.c:291:25: warning: Conversion of string literal "Impossible captype" to bool always evaluates to true. [incorrectStringBooleanError]
                        BUG_ON("Impossible captype");
                        ^

Bug: #5291.

3 years agotime: fix warning in timestring creation
Victor Julien [Tue, 26 Apr 2022 19:03:42 +0000 (21:03 +0200)] 
time: fix warning in timestring creation

cppcheck:

src/util-time.c:255:18: warning: Either the condition 'str!=NULL' is redundant or there is possible null pointer dereference: str. [nullPointerRedundantCheck]
        snprintf(str, size, "ts-error");
                 ^
src/util-time.c:252:48: note: Assuming that condition 'str!=NULL' is not redundant
    if (likely(t != NULL && fmt != NULL && str != NULL)) {
                                               ^
src/util-time.c:255:18: note: Null pointer dereference
        snprintf(str, size, "ts-error");
                 ^

Only `t` could possibly be NULL if `localtime_r` fails elsewhere.

Bug: #5291.

3 years agodetect/multi-tentancy: minor format string fixes
Victor Julien [Tue, 26 Apr 2022 18:36:36 +0000 (20:36 +0200)] 
detect/multi-tentancy: minor format string fixes

cppcheck:

src/detect-engine.c:3643:5: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
    snprintf(prefix, sizeof(prefix), "multi-detect.%d", tenant_id);
    ^
src/detect-engine.c:3707:5: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
    snprintf(prefix, sizeof(prefix), "multi-detect.%d.reload.%d", tenant_id, reload_cnt);
    ^
src/detect-engine.c:4086:17: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
                snprintf(prefix, sizeof(prefix), "multi-detect.%d", tenant_id);
                ^

Bug: #5291.

3 years agoreference: remove useless var reset
Victor Julien [Tue, 26 Apr 2022 18:18:28 +0000 (20:18 +0200)] 
reference: remove useless var reset

cppcheck:

src/util-reference-config.c:179:9: warning: Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]
        fd = NULL;
        ^

Bug: #5291.

3 years agorunmodes: minor format string fixes
Victor Julien [Tue, 26 Apr 2022 18:17:27 +0000 (20:17 +0200)] 
runmodes: minor format string fixes

cppcheck:

src/util-runmodes.c:210:9: warning: %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
        ^
src/util-runmodes.c:211:9: warning: %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(qname, sizeof(qname), "pickup%u", thread+1);
        ^
src/util-runmodes.c:455:9: warning: %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
        ^
src/util-runmodes.c:457:9: warning: %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(qname, sizeof(qname), "pickup%u", thread+1);
        ^

src/runmode-erf-file.c:188:9: warning: %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
        ^
src/runmode-erf-file.c:189:9: warning: %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(qname, sizeof(qname), "pickup%u", thread+1);
        ^
src/runmode-pcap-file.c:201:9: warning: %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
        ^
src/runmode-pcap-file.c:202:9: warning: %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(qname, sizeof(qname), "pickup%u", thread+1);
        ^

Bug: #5291.

3 years agompm/ac-ks: address int handling issues
Victor Julien [Tue, 26 Apr 2022 18:14:39 +0000 (20:14 +0200)] 
mpm/ac-ks: address int handling issues

cppcheck:

src/util-mpm-ac-ks.c:1452:5: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
    printf("Total states in the state table:    %d\n", ctx->state_count);
    ^
src/util-mpm-ac-ks.c:606:34: error: Signed integer overflow for expression '1<<31'. [integerOverflow]
        encoded_next_state |= (1 << 31);
                                 ^

Bug: #5291.

3 years agoclassification: remove useless clear
Victor Julien [Tue, 26 Apr 2022 18:12:20 +0000 (20:12 +0200)] 
classification: remove useless clear

cppcheck:

src/util-classification-config.c:189:9: warning: Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]
        fd = NULL;
        ^

Bug: #5291.

3 years agodetect/content-inspect: code cleanup
Victor Julien [Tue, 26 Apr 2022 18:06:43 +0000 (20:06 +0200)] 
detect/content-inspect: code cleanup

Rearrange code slightly to make it more clear that `found` cannot
be NULL further down the loop.

cppcheck:

src/detect-engine-content-inspection.c:316:50: warning: Either the condition 'found!=NULL' is redundant or there is overflow in pointer subtraction. [nullPointerArithmeticRedundantCheck]
                match_offset = (uint32_t)((found - buffer) + cd->content_len);
                                                 ^
src/detect-engine-content-inspection.c:308:30: note: Assuming that condition 'found!=NULL' is not redundant
            } else if (found != NULL && (cd->flags & DETECT_CONTENT_NEGATED)) {
                             ^
src/detect-engine-content-inspection.c:316:50: note: Null pointer subtraction
                match_offset = (uint32_t)((found - buffer) + cd->content_len);
                                                 ^

Bug: #5291.

3 years agodetect/analyzer: minor format string fixes
Victor Julien [Tue, 26 Apr 2022 18:05:51 +0000 (20:05 +0200)] 
detect/analyzer: minor format string fixes

cppcheck flagged this as:

src/detect-engine-analyzer.c:1359:13: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
            fprintf(rule_engine_analysis_FD, "    Rule contains %d content options, %d http content options, %d pcre options, and %d pcre options with http modifiers.\n", rule_content, rule_content_http, rule_pcre, rule_pcre_http);
            ^
src/detect-engine-analyzer.c:1359:13: warning: %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
            fprintf(rule_engine_analysis_FD, "    Rule contains %d content options, %d http content options, %d pcre options, and %d pcre options with http modifiers.\n", rule_content, rule_content_http, rule_pcre, rule_pcre_http);
            ^
src/detect-engine-analyzer.c:1359:13: warning: %d in format string (no. 3) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
            fprintf(rule_engine_analysis_FD, "    Rule contains %d content options, %d http content options, %d pcre options, and %d pcre options with http modifiers.\n", rule_content, rule_content_http, rule_pcre, rule_pcre_http);
            ^
src/detect-engine-analyzer.c:1359:13: warning: %d in format string (no. 4) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
            fprintf(rule_engine_analysis_FD, "    Rule contains %d content options, %d http content options, %d pcre options, and %d pcre options with http modifiers.\n", rule_content, rule_content_http, rule_pcre, rule_pcre_http);
            ^

Bug: #5291.

3 years agodetect/address: remove useless checks
Victor Julien [Tue, 26 Apr 2022 18:04:28 +0000 (20:04 +0200)] 
detect/address: remove useless checks

Cppcheck flagged this:

src/detect-engine-address.c:1035:48: warning: Either the condition 'ghn!=NULL' is redundant or there is possible null pointer dereference: gh. [nullPointerRedundantCheck]
    int r = DetectAddressIsCompleteIPSpaceIPv4(gh->ipv4_head);
                                               ^
src/detect-engine-address.c:1297:17: note: Assuming that condition 'ghn!=NULL' is not redundant
        if (ghn != NULL) {
                ^
src/detect-engine-address.c:1283:44: note: Calling function 'DetectAddressIsCompleteIPSpace', 1st argument 'ghn' value is 0
        if (DetectAddressIsCompleteIPSpace(ghn)) {
                                           ^
src/detect-engine-address.c:1035:48: note: Null pointer dereference
    int r = DetectAddressIsCompleteIPSpaceIPv4(gh->ipv4_head);
                                               ^

Cleanup code could only be reached with non-NULL pointers, so simplify checks.

Bug: #5291.