]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
3 years agoreadthedocs: add configuration file 7634/head
Jason Ish [Wed, 20 Jul 2022 19:07:49 +0000 (13:07 -0600)] 
readthedocs: add configuration file

Readthedocs is attempting to use our /requirements.txt file as a Python
requirements file, which it is not. Add a Readthedocs configuration file
to tell it to not use any requirements file.

3 years ago.gitignore: don't ignore *.yaml, just suricata.yaml
Jason Ish [Wed, 20 Jul 2022 19:07:15 +0000 (13:07 -0600)] 
.gitignore: don't ignore *.yaml, just suricata.yaml

3 years agoversion: start development towards 6.0.7
Jason Ish [Wed, 20 Jul 2022 19:12:47 +0000 (13:12 -0600)] 
version: start development towards 6.0.7

3 years agorelease: 6.0.6; update changelog suricata-6.0.6
Jason Ish [Sat, 9 Jul 2022 22:51:17 +0000 (16:51 -0600)] 
release: 6.0.6; update changelog

3 years agooutput: fix integer warnings
Philippe Antoine [Tue, 18 Jan 2022 09:56:48 +0000 (10:56 +0100)] 
output: fix integer warnings

Ticket: 4516

(cherry picked from commit e3180e3248e38311ad56a080233ad1a8d31a623b)

3 years agoprotocol: forbids concurrent protocol upgrades
Philippe Antoine [Fri, 8 Apr 2022 12:40:02 +0000 (14:40 +0200)] 
protocol: forbids concurrent protocol upgrades

Ticket: 5243

When switching from SMTP to TLS, and getting HTTP1 instead of
expected TLS, and HTTP1 requesting upgrade to HTTP2, we do not
overwrite the alproto_orig value so as not to have type confusion
in AppLayerParserStateProtoCleanup

(cherry picked from commit cedffdf14cf1fdd4d551f16c331e5b3e7f0a6927)

3 years agooutput: skip files logging for ICMP packets 7617/head
Philippe Antoine [Mon, 4 Jul 2022 08:30:20 +0000 (10:30 +0200)] 
output: skip files logging for ICMP packets

Ticket: #5408
(cherry picked from commit f8bf5817752f19565f1b7449710d1e6a2a96d00a)

3 years agooutput: use flow's proto for file loggers 7616/head
Philippe Antoine [Fri, 1 Jul 2022 11:22:38 +0000 (13:22 +0200)] 
output: use flow's proto for file loggers

As there can be an ICMP packet which gets related to a TCP flow.

Ticket: #5408
(cherry picked from commit 5781631f858b078ad8e5d7982074f41a08699ee2)

3 years agooutput/alert: don't call basic logging twice 7605/head
Eric Leblond [Mon, 17 Jan 2022 08:31:06 +0000 (09:31 +0100)] 
output/alert: don't call basic logging twice

Issue: 4106
(cherry picked from commit 264eddb81f952c23b5dffc3d31eef87dceb8158f)

3 years agoftp: optimized tx iterator
Philippe Antoine [Fri, 29 Apr 2022 11:12:56 +0000 (13:12 +0200)] 
ftp: optimized tx iterator

To be more efficient with larger number of transactions.

Ticket: #5314
(cherry picked from commit 5a31b3508d6bec7df1a77e0422360c155a3de9f9)

3 years agoevent: only sets APPLAYER_UNEXPECTED_PROTOCOL once
Philippe Antoine [Wed, 1 Jun 2022 13:04:34 +0000 (15:04 +0200)] 
event: only sets APPLAYER_UNEXPECTED_PROTOCOL once

If f->alproto == ALPROTO_UNKNOWN, we do not know the new protocol
yet, so we do not set the event yet.

(cherry picked from commit e6925300212277a7300f4a3aa9b5c745ee10e0df)

3 years agoevents: reset logged event
Philippe Antoine [Tue, 31 May 2022 13:49:38 +0000 (15:49 +0200)] 
events: reset logged event

Otherwise, if we log a first app_layer_event, then reset
with AppLayerDecoderEventsResetEvents for a new packet,
then get another event, it does not get logged

Ticket: #5391
(cherry picked from commit b0298dd0468f150229f9021ebe9c438bc2b7cecf)

3 years agodetect: impose limits on pcrexform 7596/head
Victor Julien [Thu, 30 Jun 2022 14:52:44 +0000 (16:52 +0200)] 
detect: impose limits on pcrexform

Impose match and recursion limits on pcrexform keywords.

Based on: 585e5e0d3c4e ("detect: impose limits on pcrexform")

Bug: #5414.

3 years agofuzz/mime: fix call conditions and args 7587/head
Victor Julien [Tue, 28 Jun 2022 18:20:37 +0000 (20:20 +0200)] 
fuzz/mime: fix call conditions and args

The SMTP parser should not supply lines w/o EOL chars to the mime
parser unless its in the BODY parsing stage. Mimic this in the fuzz
target by testing the state for inputs that have no EOL.

Additionally, make sure the delim cnt reflects the missing EOL.

(cherry picked from commit 816bbeb7dc3684d47d47c35a2255db0671760baa)

3 years agomime: fix and cleanup tests
Victor Julien [Tue, 28 Jun 2022 05:46:54 +0000 (07:46 +0200)] 
mime: fix and cleanup tests

Line count check was failing after recent delim handling updates.

(cherry picked from commit 074cfb5c68e76642f35f78c10e56761eb8010f5f)

3 years agomime: fix corner case
Victor Julien [Tue, 28 Jun 2022 13:29:25 +0000 (15:29 +0200)] 
mime: fix corner case

Fix a corner case where a base64 sequence including a space was followed
by a newline in the input data.

(cherry picked from commit d81582c4a2b5b9cd6000c8637a7c6bc9b8f4dfd6)

3 years agomime: add base64 related debug messages
Victor Julien [Tue, 28 Jun 2022 13:29:11 +0000 (15:29 +0200)] 
mime: add base64 related debug messages

(cherry picked from commit 5805ed47f51edbb2319f687cfa4fe503d6f0f0e3)

3 years agomime: improved empty line handling
Victor Julien [Tue, 28 Jun 2022 11:07:37 +0000 (13:07 +0200)] 
mime: improved empty line handling

Make sure a new body is not set up on empty lines unless it is
a body that is not encoded as base64/quoted printable.

(cherry picked from commit 41c2c1ed5a8a1f71e4cab02bb28567da9171332d)

3 years agosmtp: fix passing a wrong delim len around
Victor Julien [Mon, 27 Jun 2022 18:51:53 +0000 (20:51 +0200)] 
smtp: fix passing a wrong delim len around

(cherry picked from commit 6e2c066ce1cf722e92f08574059b6138be4f0b1e)

3 years agomime: properly pass full lines to non-decoded body
Victor Julien [Mon, 27 Jun 2022 18:15:16 +0000 (20:15 +0200)] 
mime: properly pass full lines to non-decoded body

Use actual delim count and make sure we also pass on empty lines
(so delim(s) only).

(cherry picked from commit b82b8825e79bd43901720813b672a9ff5c7bf120)

3 years agomime/base64: fix final data not getting processed
Victor Julien [Mon, 27 Jun 2022 14:20:02 +0000 (16:20 +0200)] 
mime/base64: fix final data not getting processed

If the last data of the body was not a multple of 4 and not padded
to be a multiple of 4, it would not be processed.

(cherry picked from commit 0d6ab727c55cbda04404ec44c5aa6582f3922478)

3 years agostream: fix GAP check
Victor Julien [Mon, 27 Jun 2022 09:34:14 +0000 (11:34 +0200)] 
stream: fix GAP check

Gap check would consider a GAP when the current data was in fact
exactly not a gap, but next segment(s) were already available.

(cherry picked from commit 100d821a9fbe61709be275f77341438626a561e8)

3 years agomime: remove unused 'linerem' logic
Victor Julien [Sun, 26 Jun 2022 14:25:36 +0000 (16:25 +0200)] 
mime: remove unused 'linerem' logic

(cherry picked from commit 0871029d17d23a7875af074d76965675c31599f0)

3 years agosmtp/mime: fix parsing edge case
Victor Julien [Sun, 26 Jun 2022 00:29:34 +0000 (02:29 +0200)] 
smtp/mime: fix parsing edge case

Correctly track "remaining" bytes after partial base64 decoding.

Add comment clarifications and debug validation checks.

(cherry picked from commit 5953a7d2ebd20be2a9f578fae66face4e172b678)

3 years agosmtp: skip preprocessing for mime headers
Victor Julien [Sat, 25 Jun 2022 11:01:37 +0000 (13:01 +0200)] 
smtp: skip preprocessing for mime headers

Mime parser doesn't expect partial lines, which preprocessing can
provide. Add a check to let mime headers be handled by regular line
parsing.

(cherry picked from commit a38f2f2a52822f150fff0d5e17e9f62582d6558c)

3 years agodetect: set drop reason for rule based drops 7557/head
Victor Julien [Thu, 16 Jun 2022 15:27:35 +0000 (17:27 +0200)] 
detect: set drop reason for rule based drops

Call `PacketDrop` with drop reason for drops, keep old logic
in place for the rest.

(cherry picked from commit a89840929b46b765787bec3ae5cad529f558af0a)

3 years agodetect/tests: improve detection entry 7544/head
Victor Julien [Fri, 10 Sep 2021 11:42:15 +0000 (13:42 +0200)] 
detect/tests: improve detection entry

Lots of tests still use SigMatchSignatures as their main detection
entry function, which bypassed some logic. Make it match main logic
more closely.

(cherry picked from commit e36b9b89a1be5b45b6e071248a17208b617b0c71)

3 years agotests: fix drop test; cleanup
Victor Julien [Fri, 10 Sep 2021 11:43:26 +0000 (13:43 +0200)] 
tests: fix drop test; cleanup

SigTestDropFlow04 was incorrectly expecting an alert in the packet
following a "drop" packet. The first drop is applied to the flow, so
it should lead to the 2nd packet being dropped before inspection is
run.

Clean up the test as well.

(cherry picked from commit 3874d08015f36b79b32e25dbecc4b245d314f269)

3 years agoexceptions: initial exception-policy implementation
Victor Julien [Mon, 14 Mar 2022 06:20:11 +0000 (07:20 +0100)] 
exceptions: initial exception-policy implementation

Adds a framework for setting exception policies. These would be called
when the engine reaches some kind of exception condition, like hitting
a memcap or some traffic processing error.

The policy gives control over what should happen next: drop the packet,
drop the packet and flow, bypass, etc.

Implements the policy for:

    stream: If stream session or reassembly memcaps are hit call the
    memcap policy on the packet and flow.

    flow: Apply policy when memcap is reached and no flow could be
    freed up.

    defrag: Apply policy when no tracker could be picked up.

    app-layer: Apply ppolicy if a parser reaches an error state.

All options default to 'ignore', which means the default behavior
is unchanged.

Adds commandline options: add simulation options for exceptions. These
are only exposed if compiled with `--enable-debug`.

Ticket: #5214.
Ticket: #5215.
Ticket: #5216.
Ticket: #5218.
Ticket: #5194.
(cherry picked from commit 8580499deda6bae88034f1961c01179ded91246e)

3 years agoeve/drop: log drop reason
Victor Julien [Mon, 21 Mar 2022 20:57:04 +0000 (21:57 +0100)] 
eve/drop: log drop reason

Ticket: #5202.
(cherry picked from commit 0035673208e7d3a1d73bd2f18e03a69e78fbc4ba)

3 years agoflow: log action applied to all packets
Victor Julien [Fri, 10 Sep 2021 12:07:49 +0000 (14:07 +0200)] 
flow: log action applied to all packets

Log if action applied to whole flow is drop or pass.

(cherry picked from commit 9a09fe454b846dd2cd42adaa4b569314ad083bdb)

3 years agodetect: enforce flow drops earlier
Victor Julien [Fri, 10 Sep 2021 10:35:13 +0000 (12:35 +0200)] 
detect: enforce flow drops earlier

Enforcing flow drops is now done earlier in the detection engine and
moved out of the IP-only engine where it didn't belong.

(cherry picked from commit 802c1ffee35250d1ac753aec1343e481b83d854f)

3 years agoclang-format: disable for option table
Victor Julien [Tue, 14 Jun 2022 19:11:11 +0000 (21:11 +0200)] 
clang-format: disable for option table

3 years agobypass: fix memory leak - reassign of FlowBypassInfo 7535/head
Lukas Sismis [Fri, 20 May 2022 19:33:38 +0000 (21:33 +0200)] 
bypass: fix memory leak - reassign of FlowBypassInfo

In some situations bypass callback is called on already bypassed
flow. This allocates FlowBypassInfo structure for the flow but
does not check if the flow already has one.

Issue: #5368
(cherry picked from commit 05797c45bb5bb8b23a7af3dea2aa794c6f33e02d)

3 years agobypass: af-packet: fix memory leak - reassign of EBPFBypassData
Lukas Sismis [Sat, 21 May 2022 06:30:06 +0000 (08:30 +0200)] 
bypass: af-packet: fix memory leak - reassign of EBPFBypassData

AF-Packet bypass function in some situations allocates EBPF bypass data
for an already bypassed flow and assigns it to the flow without any checks

Issue: #5368
(cherry picked from commit 8845c07a90ff6ad8304c25f6ccdd495623d35d53)

3 years agodetect/threshold: fix offline time handling issue
Victor Julien [Tue, 7 Jun 2022 20:57:39 +0000 (22:57 +0200)] 
detect/threshold: fix offline time handling issue

Due to the TIMEVAL_DIFF_SEC calculating the delta into an unsigned
integer, it would underflow to a high positive value leading to
and incorrect result if the packet timestamp was below the timestamp
for the threshold entry. In normal conditions this shouldn't happen,
but in offline mode each thread has its own concept of time which
might differ significantly based on the pcap. In this case the
overflow would be very common.

Changing it to a signed value calculation triggered fuzz undefined
behavior if the packet timeval was very high, so this patch takes a
new approach where it no longer calculates a diff but sets up the
"seconds" value we compare against as a timeval itself, and uses
that to compare.

Fixes: 9fafc1031c0c ("time: Add TIMEVAL_EARLIER and TIMEVAL_DIFF_SEC macros.")
Fixes: 82dc61f4c3e3 ("detect/threshold: Refactor threshold calculation to handle by_rule and by_both.")
Uses add `timeradd` specific version where available.

Bug: #5386.
(cherry picked from commit df2e408d96d0e37a0599f885dc29fff4011f8899)

3 years agostream/midstream: fix double flow reverse case
Victor Julien [Wed, 8 Jun 2022 11:11:55 +0000 (13:11 +0200)] 
stream/midstream: fix double flow reverse case

In the case of midstream SYN/ACK pickup, we reverse the flow based on
the SYN/ACK. If we then later get traffic that appears to be in the
reverse direction based on the app-layer, we would reverse it again.
This isn't correct. When we have the SYN/ACK we know the flow's real
direction.

(cherry picked from commit fea374626ac9d0dfe69df24958596867f9e42734)

3 years agoapp-layer: don't switch dir if proto already known
Victor Julien [Sun, 10 Apr 2022 18:21:18 +0000 (20:21 +0200)] 
app-layer: don't switch dir if proto already known

(cherry picked from commit 86e8611f5edd461bc13aa5665a40f9d241c4f23d)

3 years agodetect/dcerpc: simplify keyword validation
Victor Julien [Fri, 10 Jun 2022 09:05:40 +0000 (11:05 +0200)] 
detect/dcerpc: simplify keyword validation

Now that the engine understands the relation between SMB and DCERPC better
we can get rid of some of the special case handling in keywords.

(cherry picked from commit 84e26d670e39e6ec40af9f3b0f2910d9accdf356)

3 years agodetect/dcerpc: apply dcerpc to smb as well
Victor Julien [Thu, 9 Jun 2022 11:53:20 +0000 (13:53 +0200)] 
detect/dcerpc: apply dcerpc to smb as well

So 'alert dcerpc' also matches if the DCERPC is over SMB.

Explicitly refuse smb keywords for the 'dcerpc' app proto setting:
`alert dceprc ... smb.share; ...` is rejected.

Remove a now useless special case in the stateless rule processing
matching for dcerpc/smb.

Bug: #5208.
(cherry picked from commit 7d38f5667d1fe7dccd355f85434d2fb709578f57)

3 years agogithub/workflows: add cargo for all Ubuntu jobs
Victor Julien [Mon, 13 Jun 2022 15:21:51 +0000 (17:21 +0200)] 
github/workflows: add cargo for all Ubuntu jobs

(cherry picked from commit 7ced8de6c4659f21bb928d70a950f32016037da2)

3 years agofile: consistently track size of gaps
Victor Julien [Mon, 13 Jun 2022 10:55:52 +0000 (12:55 +0200)] 
file: consistently track size of gaps

Until now only the size of gaps counted in the regular append, not
close and open.

Bug: #5392.
(cherry picked from commit 71ef62bfc5ee8ffe4798467935f4f9386178565e)

3 years agostream: tcp: Handle retransmitted SYN with TSval
Michael Tremer [Fri, 11 Mar 2022 11:08:10 +0000 (11:08 +0000)] 
stream: tcp: Handle retransmitted SYN with TSval

For connections that use TCP timestamps for which the first SYN packet
does not reach the server, any replies to retransmitted SYNs will be
tropped.

This is happening in StateSynSentValidateTimestamp, where the timestamp
value in a SYN-ACK packet must match the one from the SYN packet.
However, since the server never received the first SYN packet, it will
respond with an updated timestamp from any of the following SYN packets.

The timestamp value inside suricata is not being updated at any time
which should happen. This patch fixes that problem.

Bug: #4376.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
(cherry picked from commit f50af12068d0af529acdaa4e45f0d4acc8c372d1)

3 years agodetect/content: fix FNs due to bad depth calc
Victor Julien [Thu, 9 Jun 2022 20:25:44 +0000 (22:25 +0200)] 
detect/content: fix FNs due to bad depth calc

When trying to propegate the depth/offset, within/distance chains
a logic error would set too a restrictive depth on a pattern that
followed more than one "unchained" patterns.

Bug: #5162.
(cherry picked from commit 8d20b40cdd3c8e911b0c4b06fb4fdc999b2d5c7c)

3 years agodetect/content: simplify int bounds checking
Victor Julien [Thu, 9 Jun 2022 20:25:08 +0000 (22:25 +0200)] 
detect/content: simplify int bounds checking

Use a macro to validate the ranges for overflows. This removes
the clutter of all the checks and warnings, and also no longer
puts the state machine in an undefined state when hitting such
a condition.

(cherry picked from commit 50d02ebc055ac99db9ea565ed7bd623c357cceb0)

3 years agodetect: fix integer warnings for content
Philippe Antoine [Fri, 3 Jun 2022 13:45:01 +0000 (15:45 +0200)] 
detect: fix integer warnings for content

Ticket: #4516
(cherry picked from commit ac8fb553a1b1e1ed19f33ac29f62123be51c9713)

3 years agodetect: parsing avoiding infinite loop
Philippe Antoine [Sat, 16 Apr 2022 14:51:42 +0000 (16:51 +0200)] 
detect: parsing avoiding infinite loop

by comparing size_t to strlen result
Instead of uint16_t which would loop

Ticket: #5310
(cherry picked from commit ced96a8aadd8a9a4ce3d8d689ac53f7eedbbe8e9)

3 years agodetect: introduce "like" ip-only signature type 7495/head
Jason Ish [Wed, 11 May 2022 17:23:24 +0000 (11:23 -0600)] 
detect: introduce "like" ip-only signature type

Rules that look like they should be IP-only but contain a negated rule
address are now marked with an LIKE_IPONLY flag. This is so they are
treated like IPONLY rules with respect to flow action, but don't
interfere with other IPONLY processing like using the radix tree.

Ticket: #5361
(cherry picked from commit c8a52070835c16612346ef14c2633412b6344a8c)

3 years agodetect/iponly: remove unused code 7494/head
Victor Julien [Fri, 13 May 2022 08:01:51 +0000 (10:01 +0200)] 
detect/iponly: remove unused code

(cherry picked from commit 51ef6f4e3a124816ba8cb17f63060c03120d96ae)

3 years agodetect/iponly: include postmatch in determination
Victor Julien [Mon, 23 May 2022 11:59:31 +0000 (13:59 +0200)] 
detect/iponly: include postmatch in determination

(cherry picked from commit beecc1890fafb2381c42af2344d74eddd4064085)

3 years agosmtp: remove defunct check for line with single LF 7493/head
Victor Julien [Sun, 5 Jun 2022 16:23:55 +0000 (18:23 +0200)] 
smtp: remove defunct check for line with single LF

Don't fix it as DATA processing needs all the bytes.

(cherry picked from commit 96bb67f474242936c029e57be3d4da1365150943)

3 years agosmtp: turn assertions in to debug asserts
Victor Julien [Sat, 4 Jun 2022 06:49:41 +0000 (08:49 +0200)] 
smtp: turn assertions in to debug asserts

(cherry picked from commit 77fae275efb54221d9cf3badd25df38eb1ea0b86)

3 years agosmtp: simplify preprocess loop
Victor Julien [Sat, 4 Jun 2022 06:49:25 +0000 (08:49 +0200)] 
smtp: simplify preprocess loop

(cherry picked from commit 3a631085bb853d6d42c5218235cd9a581a3e106c)

3 years agomime/base64: decode cleanups and simplification
Victor Julien [Fri, 3 Jun 2022 15:10:59 +0000 (17:10 +0200)] 
mime/base64: decode cleanups and simplification

Addresses edge case: > 4 bytes at the end of the input with 2 or more
spaces.

Changes length type for remainder processing to allow for much longer
lines, which can happen in practice.

Adds a series of debug validation checks with real error handling
as well, to assist the fuzzer to find more edge cases.

(cherry picked from commit 30e47b21714b5d9039f22df7b406b201bdd15b7e)

3 years agobase64: no special case for nul char
Victor Julien [Sat, 4 Jun 2022 05:09:27 +0000 (07:09 +0200)] 
base64: no special case for nul char

Let it be handled like other invalid input.

(cherry picked from commit 92cd95b4165eef540bc974d50f54a47a6b74503d)

3 years agobase64: make decoder handle decoded data space constraints
Shivani Bhardwaj [Thu, 2 Jun 2022 15:20:07 +0000 (20:50 +0530)] 
base64: make decoder handle decoded data space constraints

So far, it was the job of caller to send the bae64 decoder a perfect
block of data and take care of the destination buffer (decoded data)
size. Now, make it the decoder's job to take care of any space
constraints that the destination buffer may have and return accordingly.

Also, handle space characters in base64 encoded data as per RFC 2045.

Update MIME parser accordingly to handle the base64 data.

Ticket: 5315
(cherry picked from commit 5b2761977871a94d559a9ba3b026593bb1ffd68b)

3 years agobase64: add Base64Ecode enum
Shivani Bhardwaj [Fri, 3 Jun 2022 10:26:36 +0000 (15:56 +0530)] 
base64: add Base64Ecode enum

(cherry picked from commit cb01cc6929b6bfdf02f7b3049d7bd110a1465fa4)

3 years agobase64: add Base64Mode enum
Shivani Bhardwaj [Thu, 12 May 2022 18:00:00 +0000 (23:30 +0530)] 
base64: add Base64Mode enum

(cherry picked from commit 9131d1d85715c817a22d2a987f4a01cf42e07757)

3 years agosmtp: treat CR as a line terminator
Shivani Bhardwaj [Fri, 29 Apr 2022 08:51:40 +0000 (14:21 +0530)] 
smtp: treat CR as a line terminator

The ideal line terminator for an SMTP line is <CRLF>. But, given that
bare LF is still allowed by many systems despite the prohibition by
standards, we have to consider that. In order to simplify things, we
consider bare CR as line terminators as well while updating the
delimiter parameter correctly if they were to be followed by a LF
immediately or as a part of next fragment.

This takes care of some edge cases that made base64 decoder error out
because unexpected data was sent to it at times.

Ticket: 5316
(cherry picked from commit 1e3282f36343c59a18d8e342d5e78aa3018b8edd)

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

(cherry picked from commit a535cc5a2552d3c46792c5e5b4b3b3b6e74d4b41)

3 years agodetect/alert: directly increment alerts.discarded
Juliana Fajardini [Mon, 9 May 2022 14:24:18 +0000 (11:24 -0300)] 
detect/alert: directly increment alerts.discarded

In the unlikely case of AlertQueueExpand failure, we were incrementing
the discarded alerts stats in AlertQueueAppend via the Packet member in the
DetectEngineThreadCtx, which may not be initialized yet.

Bug #5353

(cherry picked from commit 28ac75b50594f464949c036bbb34ceff759bdc9c)

3 years agorust: Unused doc comment warning fixup 7437/head
Jeff Lucovsky [Sun, 29 May 2022 19:21:31 +0000 (15:21 -0400)] 
rust: Unused doc comment warning fixup

Since rustdoc does not generate documentation for extern blocks, Fedora
35 builds flagged 2 occurrences where doc comments existed on extern C
blocks.

3 years agostream/unittests: fix failures after last_ack fix
Victor Julien [Fri, 22 Apr 2022 17:33:13 +0000 (19:33 +0200)] 
stream/unittests: fix failures after last_ack fix

Work around many tests not setting up stream completely or correctly.

(cherry picked from commit 3d6e733aa7297f64fe87cc3b59fbbd9a527513fa)

3 years agostream: improve last_ack validation check
Victor Julien [Fri, 22 Apr 2022 16:27:15 +0000 (18:27 +0200)] 
stream: improve last_ack validation check

If a packet after the initialization would come with ACK flag set
but a ACK value of 0, the last_ack tracking could get confused. Fix
this by not checking for 0 but instead checking if the ACK flag
has been seen.

Bug: #4549.
(cherry picked from commit 1f43e1477f3c5781381e75f4bed918cbc6c18dfd)

3 years agouserguide: dynamically determine copyright date
Juliana Fajardini [Wed, 9 Feb 2022 19:46:24 +0000 (19:46 +0000)] 
userguide: dynamically determine copyright date

This uses the date of doc generation to determine the copyright date
for the trailing date. Based on Jeff Lucovsky solution.

(cherry picked from commit e0c8dba7ac6eaa757daf80245688f9f2b2496eff)

3 years agodetect: optimize mpm-engine setup
Victor Julien [Fri, 1 Apr 2022 10:22:51 +0000 (12:22 +0200)] 
detect: optimize mpm-engine setup

Instead of a loop over the rules in a group *per engine* do a single
loop in which all the engines are prepared in parallel.

(cherry picked from commit 9e6370ae2eb77ee5e43a2b152adfca0484431bd4)

3 years agossh: install app-layer events rules
Philippe Antoine [Fri, 25 Mar 2022 14:03:12 +0000 (15:03 +0100)] 
ssh: install app-layer events rules

(cherry picked from commit acbe6a33a21ee0b1d8712a3a3db86a653ecdb242)

3 years agosmb: ntlmssp domain_blob_offset underflow check
Philippe Antoine [Mon, 4 Apr 2022 20:51:01 +0000 (22:51 +0200)] 
smb: ntlmssp domain_blob_offset underflow check

Ticket: 5246
(cherry picked from commit e72036f12f577fb37b985147c2c847d147e49db2)

3 years agosmb: check on param parsing
Philippe Antoine [Mon, 4 Apr 2022 20:45:56 +0000 (22:45 +0200)] 
smb: check on param parsing

Ticket: 5246

so as not to overflow u16

(cherry picked from commit 817a5001a50a90800547e66fef067c0443eb9f72)

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

(cherry picked from commit c78722a671e819261dea9ce148966718cfca7c64)

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()

(cherry picked from commit 5ec6f3ba51c449f7588afac0820ad57b1cea5de9)

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

(cherry picked from commit 394356f73c026879672843fbb20b4de68a09d0ac)

3 years agodetect: initialization optimization
Victor Julien [Thu, 31 Mar 2022 16:00:57 +0000 (18:00 +0200)] 
detect: initialization optimization

A lot of time was spent in `SigMatchListSMBelongsTo` for the `mpm_sm`.

Optimize this by keeping the value at hand during Signature parsing and
detection engine setup.

(cherry picked from commit 3352c0bee419818f138be5837729f63a9b31bb03)

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
(cherry picked from commit d2f00ac824068475414a6ee402c9ecf4b0de1308)

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
(cherry picked from commit b5d1a800027c25f8edcc82a9770038d3948d6293)

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

(cherry picked from commit f0479987ff6f5321613395a8bf1a5eb38530b977)

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

(cherry picked from commit 0fc7ba45aa6c494bdedd5276e7ec7e4e9012facb)

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) {
                 ^

(cherry picked from commit ca97ed44361fe84cae72fad1807825f149f983eb)

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.
(cherry picked from commit 87c5d6943709de225d946f5eab8f1d24cdefa491)

3 years agostacktrace-on-signal: Use kill(getpid(), sig_num)
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.

(cherry picked from commit b6407c4253b2037cec7390364b4f0f69ccea6b0e)

3 years agogithub-ci: remove fedora 34: eol in 2 weeks 7426/head
Jason Ish [Tue, 24 May 2022 17:40:05 +0000 (11:40 -0600)] 
github-ci: remove fedora 34: eol in 2 weeks

Bump F34 to build to F35, and F35 to F36.

3 years agoutil/ebpf: fix deprecation warning 7401/head
Eric Leblond [Thu, 11 Feb 2021 22:32:38 +0000 (23:32 +0100)] 
util/ebpf: fix deprecation warning

The function bpf_program__title has been deprecated in favor of
bpf_program__section_name.

(cherry picked from commit d477d3a8789d55828861c515e609d024e95a0dc8)

3 years agoutil/ebpf: fix compilation
Eric Leblond [Wed, 11 May 2022 07:01:23 +0000 (09:01 +0200)] 
util/ebpf: fix compilation

Bug: #5360

3 years agolog-pcap: remove redundant check 7369/head
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.
(cherry picked from commit 3dfbf0bf1124aab7c7060f46b364877ab25455ee)

3 years agolog/pcap: exit on invalid filename
Eric Leblond [Wed, 10 Feb 2021 15:23:25 +0000 (16:23 +0100)] 
log/pcap: exit on invalid filename

If the filename has to % sign and if pcap logging is using multi
mode, then the pcap capture will fail. So let's exit if ever this
is the case.

(cherry picked from commit 921d44b262f30555ea747653b050dfde4188c042)

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.
(cherry picked from commit 69b8b48b9422279943c083a24e5baf64e1c4aa94)

3 years agologopenfile: fix minor format string warning
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.
(cherry picked from commit 07d0ae04d34cdf029729b474fb22598f154fcea6)

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.
(cherry picked from commit 1e13f7278585555623ff0be2d3a98476617b1219)

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.
(cherry picked from commit fedced209dc25443ec5eee22bfab6c99f9f652ab)

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.
(cherry picked from commit 3bc50df9c3397b9ab06376657c5e8c3467fbc7c5)

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.
(cherry picked from commit 7e2ed11a11cae89bc07e9a25425192581687993d)

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.
(cherry picked from commit 2f48e432cd4465bbb1f42fe7778fee44a5d0aa47)

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.
(cherry picked from commit 4fcb8740e7b98eee1b5e65bd66045c9440cef8b6)

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.
(cherry picked from commit 5a0bbb5289cd0fbf4ef50294127cb1018baf82a2)

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.
(cherry picked from commit 2965d809a44817223d3e6bc81e55c2286da5212b)

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.
(cherry picked from commit a8d3cd6eb4f181000256986ea7cf83074a0d2b59)

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.
(cherry picked from commit 9c672a805fe1fe78591ec0f06da56e23c99d0751)

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.
(cherry picked from commit 27e9a871d0f7feeafb8fff266b2bb4d97abd39f3)

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.
(cherry picked from commit a0847e6c697055b127343cc338029bc69bbc0791)

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.
(cherry picked from commit f8a0f3d9b9f4e1aa758a493e00d38e98a552a0d6)