]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
11 years agoCygwin: make configure pass with -Werror 773/head
Victor Julien [Mon, 16 Dec 2013 13:41:46 +0000 (14:41 +0100)] 
Cygwin: make configure pass with -Werror

11 years agoCygwin: fix compilation
Victor Julien [Mon, 16 Dec 2013 12:53:51 +0000 (13:53 +0100)] 
Cygwin: fix compilation

tm-threads.c:1190:5: error: unknown type name ‘DWORD’

11 years agoFix compiler warning:
Victor Julien [Mon, 16 Dec 2013 12:29:06 +0000 (13:29 +0100)] 
Fix compiler warning:

array subscript has type ‘char’ [-Werror=char-subscripts]

11 years agoFix coccinelle autotools check 771/head
Victor Julien [Tue, 14 Jan 2014 13:57:42 +0000 (14:57 +0100)] 
Fix coccinelle autotools check

11 years agococcinelle: add --disable-coccinelle to configure 770/head
Victor Julien [Tue, 14 Jan 2014 12:41:09 +0000 (13:41 +0100)] 
coccinelle: add --disable-coccinelle to configure

This allows disabling of the expensive cocci QA checks during
QA.

11 years agopool thread: undo CLS alignment
Victor Julien [Tue, 14 Jan 2014 12:03:43 +0000 (13:03 +0100)] 
pool thread: undo CLS alignment

This breaks clang on 32bit.

Test PoolThreadTestGrow01                                         : process killed by signal 11

11 years agoFix unittest size_t printing on 32bit
Victor Julien [Tue, 14 Jan 2014 10:48:25 +0000 (11:48 +0100)] 
Fix unittest size_t printing on 32bit

11 years agodns: tag each tx we get a reply for as replied 765/head
Victor Julien [Thu, 12 Dec 2013 12:12:13 +0000 (13:12 +0100)] 
dns: tag each tx we get a reply for as replied

Also, detect and print when server says recursion is desired.

11 years agoDNS: don't store duplicate queries
Victor Julien [Sat, 7 Dec 2013 10:41:45 +0000 (11:41 +0100)] 
DNS: don't store duplicate queries

When an exact duplicate DNS query is received, don't store it in the
tx.

11 years agomemcmp: convert all pointer arguments to be const pointers, like memcmp itself uses.
Victor Julien [Sat, 7 Dec 2013 10:29:22 +0000 (11:29 +0100)] 
memcmp: convert all pointer arguments to be const pointers, like memcmp itself uses.

11 years agodns log: cleanups
Victor Julien [Fri, 6 Dec 2013 13:43:15 +0000 (14:43 +0100)] 
dns log: cleanups

11 years agoapp-layer: API calls to check for TX aware proto
Victor Julien [Fri, 10 Jan 2014 12:02:19 +0000 (13:02 +0100)] 
app-layer: API calls to check for TX aware proto

Introduce AppLayerParserProtocolIsTxAware which returns 1 if protocol
is Tx aware, 0 if not.

11 years agoRemove GCC -no-strict-aliasing compiler flag. 764/head
Ken Steele [Fri, 10 Jan 2014 17:36:02 +0000 (12:36 -0500)] 
Remove GCC -no-strict-aliasing compiler flag.

GCC typically generates better code without the -no-strict-aliasing flag.
It is only required if code makes assumptiosn that break strict aliasing.
The unit tests pass on x86 and Tile without the flag.

11 years agoFix PmqSetup() argument removal in ac-tile MPM unit tests.
Ken Steele [Fri, 10 Jan 2014 15:40:52 +0000 (10:40 -0500)] 
Fix PmqSetup() argument removal in ac-tile MPM unit tests.

Needed to remove the second argument from all the calls, which was always 0
and was removed in other tests in a previous checkin.

11 years agocounters: fix 2 scan-build warnings
Victor Julien [Thu, 19 Dec 2013 20:14:06 +0000 (21:14 +0100)] 
counters: fix 2 scan-build warnings

counters.c:1069:13: warning: Potential leak of memory pointed to by 'temp'
            SCMutexUnlock(&sc_perf_op_ctx->pctmi_lock);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./threads.h:121:28: note: expanded from macro 'SCMutexUnlock'
                           ^~~~~~~~~~~~~~~~~~~~
counters.c:1156:16: warning: Potential leak of memory pointed to by 'pca'
        return NULL;
               ^~~~
/usr/include/clang/3.3/include/stddef.h:77:24: note: expanded from macro 'NULL'
                       ^
2 warnings generated.

11 years agoapp-layer: configurable GetActiveTxId function 762/head
Victor Julien [Mon, 9 Dec 2013 16:41:22 +0000 (17:41 +0100)] 
app-layer: configurable GetActiveTxId function

In preparation of a patchset that will allow for disabling the detect
module, this patch introduces a way to register a function for getting
the lowest active tx id. This is used by the app layer for cleaning up
transactions that already fully inspected, and by the flow timeout code
to determine if a flow is fully inspected and logged at timeout.

The registration function RegisterAppLayerGetActiveTxIdFunc allows for
registration of a custom function of type:
  uint64_t (*GetActiveTxIdFunc)(Flow *f, uint8_t flags);

If no function is called, AppLayerTransactionGetActiveDetectLog is used,
which implements the existing behaviour of considering both the
inspect_id's and the log_id.

11 years agoClean up TX clean up
Victor Julien [Mon, 9 Dec 2013 14:56:43 +0000 (15:56 +0100)] 
Clean up TX clean up

In AppLayerTransactionsCleanup instead of figuring out 'done' tx id's
itself, now call AppLayerTransactionGetActive for both directions to
figure out the completed TX id's.

11 years agostream: don't send empty streammsg at stream end 759/head
Victor Julien [Wed, 18 Dec 2013 08:14:20 +0000 (09:14 +0100)] 
stream: don't send empty streammsg at stream end

No longer send an empty StreamMsg through the engine on stream end,
the messages were ignored anyway.

11 years agostream: increase max StreamMsg data
Victor Julien [Tue, 17 Dec 2013 19:56:58 +0000 (20:56 +0100)] 
stream: increase max StreamMsg data

Increase from 4024 bytes to 4072 to make the whole structure
4096 again.

11 years agostream: remove flags from StreamMsg
Victor Julien [Tue, 17 Dec 2013 19:52:38 +0000 (20:52 +0100)] 
stream: remove flags from StreamMsg

11 years agostream: remove per thread queue for stream msgs
Victor Julien [Tue, 17 Dec 2013 15:57:48 +0000 (16:57 +0100)] 
stream: remove per thread queue for stream msgs

StreamMsgs would be stored in a per thread queue before being
attached to the tcp ssn. This is unnecessary, so this patch
removes this queue and puts the smsgs into the ssn directly.

Large patch as it affects a lot of tests.

11 years agostream: remove flow reference from StreamMsg
Victor Julien [Tue, 17 Dec 2013 15:33:26 +0000 (16:33 +0100)] 
stream: remove flow reference from StreamMsg

StreamMsg' flow reference was used mostly to make sure a flow would
not get removed from the hash before inspection. For this it needed
to reference the flow use_cnt reference counter. Nowadays we have
more advanced flow timeout handling. This will make sure that if
there still are pending smsgs' in a flow, these will still be
processed.

11 years agostream: pass TcpSession to StreamTcpReassembleProcessAppLayer
Victor Julien [Tue, 17 Dec 2013 15:19:16 +0000 (16:19 +0100)] 
stream: pass TcpSession to StreamTcpReassembleProcessAppLayer

Preparation for removing flow pointer from StreamMsg. Instead of
getting the ssn indirectly through StreamMsg->flow, we pass it
directly as all callers have it already.

11 years agostream msg: remove structure
Victor Julien [Tue, 17 Dec 2013 14:54:09 +0000 (15:54 +0100)] 
stream msg: remove structure

11 years agostream: remove unused gap structure from StreamMsg.
Victor Julien [Tue, 17 Dec 2013 14:28:47 +0000 (15:28 +0100)] 
stream: remove unused gap structure from StreamMsg.

11 years agostream: no longer process STREAM_GAP smsgs
Victor Julien [Tue, 17 Dec 2013 14:24:44 +0000 (15:24 +0100)] 
stream: no longer process STREAM_GAP smsgs

StreamSmgs are used for raw stream reassembly only. They could also
be used to tell the rest of the engine about sequence gaps. This was
a left over from the older implementation, where the app layer used
the smsgs as well.

11 years agoRemove the old include support.
Jason Ish [Fri, 6 Dec 2013 19:38:26 +0000 (13:38 -0600)] 
Remove the old include support.

11 years agoCorrect coding style in decode-ethernet.c 758/head
Ken Steele [Wed, 8 Jan 2014 17:16:00 +0000 (12:16 -0500)] 
Correct coding style in decode-ethernet.c

This file is given as the example of correct coding style, so make sure it
follows the coding standard.

11 years agodebug: default logging level is notice
Eric Leblond [Mon, 16 Dec 2013 12:41:39 +0000 (13:41 +0100)] 
debug: default logging level is notice

Update the string in message because default logging level is
now notice and not info.

11 years agodoxygen: document some functions
Eric Leblond [Mon, 16 Dec 2013 10:58:47 +0000 (11:58 +0100)] 
doxygen: document some functions

11 years agodoxygen: document all code
Eric Leblond [Mon, 16 Dec 2013 10:44:25 +0000 (11:44 +0100)] 
doxygen: document all code

This patch update doxygen configuration to have all possible functions
documented (even the one without doxygen formated comments). It can be
really useful to have that in case we are trying to get some information
on call graph for example.

11 years agodoxygen: add profiling to generated doc.
Eric Leblond [Mon, 16 Dec 2013 10:39:45 +0000 (11:39 +0100)] 
doxygen: add profiling to generated doc.

Profiling code needs the PROFILING define to be documented.

11 years agoAdd missing UNITTESTS
Eric Leblond [Mon, 16 Dec 2013 10:38:33 +0000 (11:38 +0100)] 
Add missing UNITTESTS

There is no need for test functions to be build in normal code.

11 years agoaf-packet: update packet reading loop logic
Eric Leblond [Wed, 18 Dec 2013 18:46:10 +0000 (19:46 +0100)] 
af-packet: update packet reading loop logic

This patch updates the logic of the packet acquisition loop. When
the reader loop function is called and when the data to read
at offset is a without data (kernel) or still used by suricata. We
try to iter for a loop on the ring to try to find kernel put by
data.
As we are entering the function because the poll said there was some
data. This allow us to jump to the data added to the ring by the
kernel.
When using suricata in autofp mode, with multiple detect threads and
packet acquisition threads attached to a dedicated CPU, the reader
loop function was looping really fast because poll call was returning
immediatly because we did read the data available.

11 years agoprscript: add --norebase option
Eric Leblond [Thu, 19 Dec 2013 14:18:46 +0000 (15:18 +0100)] 
prscript: add --norebase option

If --norebase option is provided, the prscript will start a build
that can be used to check if an out-of-sync branch pass the test.

11 years agohtp layer: add memory cap counter
Eric Leblond [Mon, 30 Dec 2013 16:29:46 +0000 (17:29 +0100)] 
htp layer: add memory cap counter

This patch adds a memcap counter for HTP memory usage. Counter
is increased each time an allocation is not done due to the memcap.

11 years agohtp layer: add memory usage counter
Eric Leblond [Mon, 30 Dec 2013 15:14:54 +0000 (16:14 +0100)] 
htp layer: add memory usage counter

This patch adds a memory counter for HTP memory usage. As
there is no thread variables available in application layer
the counter has been added to the TCP reassembly thread.

11 years agohtp layer: use memcap for HTTP related allocations
Eric Leblond [Mon, 30 Dec 2013 10:06:22 +0000 (11:06 +0100)] 
htp layer: use memcap for HTTP related allocations

This patch introduces wrapper functions around allocation functions
to be able to have a global HTP memcap. A simple subsitution of
function was not enough because allocated size needed to be known
during freeing and reallocation.

The value of the memcap can be set in the YAML and is left by default
to unlimited (0) to avoid any surprise to users.

11 years agoPort unittest from bug #970 for util-mpm-ac.c to util-mpm-ac-tile.c
Ken Steele [Wed, 8 Jan 2014 15:46:04 +0000 (10:46 -0500)] 
Port unittest from bug #970 for util-mpm-ac.c to util-mpm-ac-tile.c

Passes on ac-tile too.

11 years agoAdd 8-bit states to ac-tile
Ken Steele [Wed, 18 Dec 2013 16:16:54 +0000 (11:16 -0500)] 
Add 8-bit states to ac-tile

When running with sgh-mpm-context: full, many more MPMs are created
(16K) and many are small. If they have less than 128 states, they only
need 1 byte for the next state instead of 2 bytes, cutting the size of
the next-state table in half. This reduces total memory usage.

Since that makes 3 different state sizes (1, 2 and 4 bytes), rather
than going from 2 copies of the code to create the MPM to 3, I
factored out the code that fills the next-state table into three
functions so that all the other code could be the same.

The search function is now parameterize for 8-bit and 16-bit state
sizes and alphabet sizes 8, 16, 32, 64, 128 and 256.

11 years agopfring: fix live device counter usage 757/head
Eric Leblond [Tue, 31 Dec 2013 15:09:43 +0000 (16:09 +0100)] 
pfring: fix live device counter usage

Live device counter was in fact the number of packets seen by suricata
and not the total number of packet reported by pfring. This patch fixes
this by using counter provided by kernel instead.

Pfring kernel counter is per socket and is not cleared after read.
So to get the number of packet on the interface we can add the new
value for this thread and add it to the interface counter.

11 years agoaf-packet: fix live device counter usage
Eric Leblond [Tue, 31 Dec 2013 15:13:50 +0000 (16:13 +0100)] 
af-packet: fix live device counter usage

Live device counter was in fact the number of packets seen by suricata
and not the total number of packet reported by kernel. This patch fixes
this by using counter provided by kernel instead.
The counter is Clear On Read, so by adding the value fetch at each call
and earch sockets we get the number of packets and drops for the
interface.

11 years agocapture: display exit stats at default verbosity
Eric Leblond [Tue, 31 Dec 2013 14:09:10 +0000 (15:09 +0100)] 
capture: display exit stats at default verbosity

This patch updates capture modes not using LiveDecice counters
to display per-thread exit statistics with default verbosity.

11 years agodevice list: clean and display stat at exit
Eric Leblond [Tue, 31 Dec 2013 14:04:33 +0000 (15:04 +0100)] 
device list: clean and display stat at exit

This patch adds a cleaning function to device list. This also
permits to display per-interface statistics during the exit.

11 years agoFix the segmentation fault while logging the host on the custom HTTP logger.
Duarte Silva [Thu, 19 Dec 2013 14:07:30 +0000 (14:07 +0000)] 
Fix the segmentation fault while logging the host on the custom HTTP logger.
- Seems to be a regression introduced in the commit
  796bfab2317699779bb0d7dca257bb97083399d8 (fix was already done in commit
  ee0b21652b00f9398869b097c3ddceb9f86600a9)
- Doesn't happen with htplib v0.5.6, but it does in the latest, v0.5.9

11 years agococcinelle: protecting regexp operator is not needed
Eric Leblond [Fri, 20 Dec 2013 09:23:39 +0000 (10:23 +0100)] 
coccinelle: protecting regexp operator is not needed

It seems there was an evolution of coccinelle and the protection
of regexp is not necessary anymore. And doing it causing the
expression not to match.

11 years agofix size_t printing
Eric Leblond [Fri, 20 Dec 2013 09:22:25 +0000 (10:22 +0100)] 
fix size_t printing

This two problem were found by the new version of the size_t cocci
test.

11 years agoapp-layer: only typedef opaque pointers once 753/head
Victor Julien [Fri, 10 Jan 2014 09:15:48 +0000 (10:15 +0100)] 
app-layer: only typedef opaque pointers once

11 years agoapp layer: void -> AppLayerProtoDetectThreadCtx
Victor Julien [Thu, 9 Jan 2014 15:40:59 +0000 (16:40 +0100)] 
app layer: void -> AppLayerProtoDetectThreadCtx

User AppLayerProtoDetectThreadCtx ptr instead of void.

11 years agoUpdate tests to use AppLayerParserThreadCtx ptr instead of void. Fix a few bugs uncov...
Victor Julien [Thu, 9 Jan 2014 15:20:21 +0000 (16:20 +0100)] 
Update tests to use AppLayerParserThreadCtx ptr instead of void. Fix a few bugs uncovered by this.

11 years agoapp-layer: Use opaque pointers instead of void
Victor Julien [Thu, 9 Jan 2014 14:10:37 +0000 (15:10 +0100)] 
app-layer: Use opaque pointers instead of void

For AppLayerThreadCtx, AppLayerParserState, AppLayerParserThreadCtx
and AppLayerProtoDetectThreadCtx, use opaque pointers instead of
void pointers.

AppLayerParserState is declared in flow.h as it's part of the Flow
structure.

AppLayerThreadCtx is declared in decode.h, as it's part of the
DecodeThreadVars structure.

11 years agoFix HTPBodyReassemblyTest01 Asan error
Victor Julien [Thu, 9 Jan 2014 11:40:08 +0000 (12:40 +0100)] 
Fix HTPBodyReassemblyTest01 Asan error

Fix improper pointer assignment in HTPBodyReassemblyTest01, causing
ASAN to error out.

11 years agoapp-layer: rename AppLayerThreadCtx funcs
Victor Julien [Thu, 9 Jan 2014 11:13:03 +0000 (12:13 +0100)] 
app-layer: rename AppLayerThreadCtx funcs

AppLayerParserGetCtxThread -> AppLayerParserThreadCtxAlloc
AppLayerParserDestroyCtxThread -> AppLayerParserThreadCtxFree

11 years agoapp layer: fix memory leak
Victor Julien [Thu, 9 Jan 2014 10:52:46 +0000 (11:52 +0100)] 
app layer: fix memory leak

Actually free the ctx in AppLayerParserDestroyCtxThread

11 years agoapp layer: uint16_t alproto -> AppProto alproto
Victor Julien [Thu, 9 Jan 2014 10:32:40 +0000 (11:32 +0100)] 
app layer: uint16_t alproto -> AppProto alproto

This conversion was missing in a couple of places.

11 years agoUse u8 for ipproto
Victor Julien [Thu, 9 Jan 2014 10:19:58 +0000 (11:19 +0100)] 
Use u8 for ipproto

In a few places in app layer and unittests u16 was used.

11 years agoApp Layer: cleanup state func naming
Victor Julien [Thu, 9 Jan 2014 10:06:59 +0000 (11:06 +0100)] 
App Layer: cleanup state func naming

Rename functions related to AppLayerState to be more consistent.

11 years agoRename AppLayerProtoDetectCtxThread -> AppLayerProtoDetectThreadCtx
Victor Julien [Thu, 9 Jan 2014 09:41:22 +0000 (10:41 +0100)] 
Rename AppLayerProtoDetectCtxThread -> AppLayerProtoDetectThreadCtx

11 years agoRename AppLayerParserParserState -> AppLayerParserState
Victor Julien [Thu, 9 Jan 2014 09:38:12 +0000 (10:38 +0100)] 
Rename AppLayerParserParserState -> AppLayerParserState

11 years agoRename AppLayerParserpCtx -> AppLayerParserProtoCtx
Victor Julien [Thu, 9 Jan 2014 09:33:54 +0000 (10:33 +0100)] 
Rename AppLayerParserpCtx -> AppLayerParserProtoCtx

11 years agoRename AppLayerParserCtxThread -> AppLayerParserThreadCtx
Victor Julien [Thu, 9 Jan 2014 09:28:34 +0000 (10:28 +0100)] 
Rename AppLayerParserCtxThread -> AppLayerParserThreadCtx

11 years agoRename AppLayerCtxThread -> AppLayerThreadCtx
Victor Julien [Thu, 9 Jan 2014 09:25:33 +0000 (10:25 +0100)] 
Rename AppLayerCtxThread -> AppLayerThreadCtx

11 years agodetect unittests: clang build fix and cleanups
Victor Julien [Thu, 9 Jan 2014 09:10:19 +0000 (10:10 +0100)] 
detect unittests: clang build fix and cleanups

A number of unittests would lead to clang build errors because
of unsafe det_ctx ptr usage. This patch fixes these and inits
det_ctx to NULL in the other detect tests.

11 years agoApp Layer: fix memory leaks
Victor Julien [Wed, 8 Jan 2014 17:43:48 +0000 (18:43 +0100)] 
App Layer: fix memory leaks

Call FlowCleanupAppLayer before setting f->proto to 0, as the former
bails out without doing anything if proto is 0.

11 years agoFix AppLayerProtoDetectPMFreeSignature related valgrind errors
Victor Julien [Wed, 8 Jan 2014 17:10:16 +0000 (18:10 +0100)] 
Fix AppLayerProtoDetectPMFreeSignature related valgrind errors

11 years agoapp proto detect: fix valgrind test warnings
Victor Julien [Wed, 8 Jan 2014 16:20:58 +0000 (17:20 +0100)] 
app proto detect: fix valgrind test warnings

Only in unittests when debug is enabled would valgrind warn about
a print statement.

11 years agoCleanup and fix scan-build warning
Victor Julien [Wed, 8 Jan 2014 16:05:04 +0000 (17:05 +0100)] 
Cleanup and fix scan-build warning

Add comments and slightly refactor to make function more understandable
and fix a scan-build warning too.

11 years agoscan-build fixes
Victor Julien [Wed, 8 Jan 2014 16:04:49 +0000 (17:04 +0100)] 
scan-build fixes

11 years agoprofiling: fix compilation
Victor Julien [Wed, 8 Jan 2014 15:11:43 +0000 (16:11 +0100)] 
profiling: fix compilation

Stream engine can't access app layer proto detection datatypes
anymore, so moved some of the logic into app-layer.c

11 years agocompile fixes
Victor Julien [Wed, 8 Jan 2014 15:11:21 +0000 (16:11 +0100)] 
compile fixes

11 years agoVarious style fixes
Victor Julien [Wed, 8 Jan 2014 15:10:26 +0000 (16:10 +0100)] 
Various style fixes

11 years agoApp layer API rewritten. The main files in question are: 745/head
Anoop Saldanha [Tue, 24 Dec 2013 10:00:57 +0000 (15:30 +0530)] 
App layer API rewritten.  The main files in question are:
app-layer.[ch], app-layer-detect-proto.[ch] and app-layer-parser.[ch].

Things addressed in this commit:
- Brings out a proper separation between protocol detection phase and the
  parser phase.
- The dns app layer now is registered such that we don't use "dnstcp" and
  "dnsudp" in the rules.  A user who previously wrote a rule like this -

  "alert dnstcp....." or
  "alert dnsudp....."

  would now have to use,

  alert dns (ipproto:tcp;) or
  alert udp (app-layer-protocol:dns;) or
  alert ip (ipproto:udp; app-layer-protocol:dns;)

  The same rules extend to other another such protocol, dcerpc.
- The app layer parser api now takes in the ipproto while registering
  callbacks.
- The app inspection/detection engine also takes an ipproto.
- All app layer parser functions now take direction as STREAM_TOSERVER or
  STREAM_TOCLIENT, as opposed to 0 or 1, which was taken by some of the
  functions.
- FlowInitialize() and FlowRecycle() now resets proto to 0.  This is
  needed by unittests, which would try to clean the flow, and that would
  call the api, AppLayerParserCleanupParserState(), which would try to
  clean the app state, but the app layer now needs an ipproto to figure
  out which api to internally call to clean the state, and if the ipproto
  is 0, it would return without trying to clean the state.
- A lot of unittests are now updated where if they are using a flow and
  they need to use the app layer, we would set a flow ipproto.
- The "app-layer" section in the yaml conf has also been updated as well.

11 years agoUse a typdef AppProto <-> uint16_t for representing app layer protocol.
Anoop Saldanha [Fri, 6 Dec 2013 11:51:57 +0000 (17:21 +0530)] 
Use a typdef AppProto <-> uint16_t for representing app layer protocol.

Some minor refactoring/cleanup, including renaming functions.

11 years agoDisabling the ssh parser temporarily, since we are moving away from some
Anoop Saldanha [Wed, 23 Oct 2013 05:55:46 +0000 (11:25 +0530)] 
Disabling the ssh parser temporarily, since we are moving away from some
of the archaic features we use in the app layer. We will reintroduce this
parser shortly. Also do note that keywords that rely on the ssh parser
would now be disabled.

11 years agoUpdate Changelog for 2.0beta2 suricata-2.0beta2
Victor Julien [Wed, 18 Dec 2013 13:01:28 +0000 (14:01 +0100)] 
Update Changelog for 2.0beta2

11 years agoconf: fix potential use-after-free on error 730/head
Victor Julien [Wed, 18 Dec 2013 11:23:50 +0000 (12:23 +0100)] 
conf: fix potential use-after-free on error

Coverity 1139544

If strdup would fail, 'node' was freed but it wasn't set to NULL. The
code then returned node. The caller would not detect there was an error
and use the freed pointer.

11 years agostream: fix potential memory loss on error
Victor Julien [Wed, 18 Dec 2013 11:17:56 +0000 (12:17 +0100)] 
stream: fix potential memory loss on error

Coverity 1139543.

If StreamTcpPseudoPacket would be called with len == 0, the packet
it acquired before checking the len value would be lost.

11 years agoRevert TmqhFlowMode alignment as it breaks on CLANG
Victor Julien [Fri, 13 Dec 2013 11:50:43 +0000 (12:50 +0100)] 
Revert TmqhFlowMode alignment as it breaks on CLANG

11 years agorealloc error handling: remove unnecessary else branch
Victor Julien [Fri, 13 Dec 2013 11:20:00 +0000 (12:20 +0100)] 
realloc error handling: remove unnecessary else branch

11 years agococcinelle: add test on realloc
Eric Leblond [Thu, 12 Dec 2013 12:34:54 +0000 (13:34 +0100)] 
coccinelle: add test on realloc

If we use SCRealloc like:
 x = SCRealloc(x, ...)
then in case of failure we are loosing the original pointer value
and the memory is lost and can not be free.

This test just check for this construction and output an error if
it finds it.

11 years agoFix realloc error handling
Eric Leblond [Thu, 12 Dec 2013 12:10:01 +0000 (13:10 +0100)] 
Fix realloc error handling

This patch is fixing realloc error handling. In case of a realloc
failure, it free the initial memory and continue existing error
handling.

The patch has been obtained via the following semantic patch and
a bit oh hand editing:

@@
expression x, E;
identifier f;
@@

f(...)
{
+ void *ptmp;
<+...
- x = SCRealloc(x, E);
+ ptmp = SCRealloc(x, E);
... when != x
- if (x == NULL)
+ if (ptmp == NULL)
{
+ SCFree(x);
+ x = NULL;
...
- }
+ } else {
+     x = ptmp;
+ }
...+>
}

@@
expression x, E;
identifier f;
statement ES;
@@

f(...) {
+ void *ptmp;

<+...
- x = SCRealloc(x, E);
+ ptmp = SCRealloc(x, E);
... when != x
- if (x == NULL) ES
+ if (ptmp == NULL) {
+ SCFree(x);
+ x = NULL;
+ ES
+ } else {
+     x = ptmp;
+ }
...+>

}

@@
expression x, E;
identifier f;
@@

f(...)
{
+ void *ptmp;
<+...
- x = SCRealloc(x, E);
+ ptmp = SCRealloc(x, E);
... when != x
- if (unlikely(x == NULL))
+ if (unlikely(ptmp == NULL))
{
+ SCFree(x);
+ x = NULL;
...
- }
+ } else {
+     x = ptmp;
+ }
...+>
}

@@
expression x, E;
identifier f;
statement ES;
@@

f(...) {
+ void *ptmp;

<+...
- x = SCRealloc(x, E);
+ ptmp = SCRealloc(x, E);
... when != x
- if (unlikely(x == NULL)) ES
+ if (unlikely(ptmp == NULL)) {
+ SCFree(x);
+ x = NULL;
+ ES
+ } else {
+     x = ptmp;
+ }
...+>

}

11 years agoFix filemagic unittests on OS_DARWIN
Victor Julien [Thu, 12 Dec 2013 16:01:49 +0000 (17:01 +0100)] 
Fix filemagic unittests on OS_DARWIN

11 years agoAdd const for Packet * in flow functions.
Ken Steele [Sat, 16 Nov 2013 16:13:42 +0000 (11:13 -0500)] 
Add const for Packet * in flow functions.

By moving FlowReference() out of FlowGetFlowFromHash() and into the one
function that calls it, all the flow functions take const Packet * instead
of Packet *.

11 years agodefrag-config: fix a bug
Giuseppe Longo [Thu, 12 Dec 2013 22:03:42 +0000 (23:03 +0100)] 
defrag-config: fix a bug

A ptr to local var is stored in the radix tree currently,
this patch permits to alloc space to store host timeout
and thus also free it when data is removed.

11 years agodefrag: fix compiler warning
Victor Julien [Thu, 12 Dec 2013 18:28:22 +0000 (19:28 +0100)] 
defrag: fix compiler warning

defrag-config.c: In function 'DefragParseParameters':
defrag-config.c:105: warning: passing argument 2 of 'DefragPolicyAddHostInfo' from incompatible pointer type
make[3]: *** [defrag-config.o] Error 1

11 years agodebug: fix realloc error checking on flowbit print 720/head
Victor Julien [Wed, 11 Dec 2013 12:26:55 +0000 (13:26 +0100)] 
debug: fix realloc error checking on flowbit print

detect.c:1074:17: warning: Potential leak of memory pointed to by \
                                field 'debuglog_flowbits_names'
                return;

Bug #1062.

11 years agoDER decoding: fix potential memory leak
Victor Julien [Wed, 11 Dec 2013 10:00:41 +0000 (11:00 +0100)] 
DER decoding: fix potential memory leak

This would only happen in memory failure conditions.

util-decode-der.c:634:27: warning: Potential leak of memory pointed to by 'child'
    return (Asn1Generic *)node;

11 years agodetect-ssl: suppress harmless scan-build warning
Victor Julien [Wed, 11 Dec 2013 09:35:41 +0000 (10:35 +0100)] 
detect-ssl: suppress harmless scan-build warning

detect-ssl-version.c:271:17: warning: Value stored to 'neg' is never read
                neg = 0;

11 years agostream: suppress minor scan-build warnings
Victor Julien [Wed, 11 Dec 2013 09:33:15 +0000 (10:33 +0100)] 
stream: suppress minor scan-build warnings

stream-tcp-reassemble.c:2569:17: warning: Value stored to 'seg' is never read
                seg = seg->next;
                ^     ~~~~~~~~~
stream-tcp-reassemble.c:2587:17: warning: Value stored to 'seg' is never read
                seg = seg->next;

11 years agodns: suppress minor scan-build warnings
Victor Julien [Wed, 11 Dec 2013 09:31:27 +0000 (10:31 +0100)] 
dns: suppress minor scan-build warnings

These were only used if debug is enabled.

app-layer-dns-tcp.c:407:13: warning: Value stored to 'length' is never read
            length = *data;
app-layer-dns-udp.c:236:13: warning: Value stored to 'length' is never read
            length = *data;

11 years agodns: suppress harmless cppcheck warning
Victor Julien [Wed, 11 Dec 2013 09:29:19 +0000 (10:29 +0100)] 
dns: suppress harmless cppcheck warning

[src/app-layer-dns-common.c:273]: (warning) Assignment of function \
                        parameter has no effect outside the function.

11 years agohttp: clear header pointer on realloc failure
Victor Julien [Wed, 11 Dec 2013 09:13:02 +0000 (10:13 +0100)] 
http: clear header pointer on realloc failure

Fixes:

detect-engine-hhd.c:188:5: warning: Use of memory after it is freed
    return headers_buffer;

11 years agodns: fix passing NULL to memcpy
Victor Julien [Wed, 11 Dec 2013 09:11:13 +0000 (10:11 +0100)] 
dns: fix passing NULL to memcpy

app-layer-dns-common.c:401:5: warning: Null pointer passed as \
                              an argument to a 'nonnull' parameter
    memcpy(ptr, fqdn, fqdn_len);

11 years agolog-http: fix compiler warning
Victor Julien [Wed, 11 Dec 2013 08:44:42 +0000 (09:44 +0100)] 
log-http: fix compiler warning

log-httplog.c:180: warning: 'cvalue' may be used uninitialized in \
this function

11 years agodefrag: pass u64 to ParseU64
Victor Julien [Wed, 11 Dec 2013 08:35:41 +0000 (09:35 +0100)] 
defrag: pass u64 to ParseU64

Fixes: defrag-config.c:97: warning: passing argument 2 \
       of 'ParseSizeStringU64' from incompatible pointer type

11 years agoFix uninitialized variable warning.
Ken Steele [Wed, 11 Dec 2013 14:48:50 +0000 (09:48 -0500)] 
Fix uninitialized variable warning.

These two lines reported warnings with -Werror -O3 on Tile.

11 years agoFix pfring so that zero-copy mode can work. 717/head
Ken Steele [Mon, 11 Nov 2013 18:11:39 +0000 (13:11 -0500)] 
Fix pfring so that zero-copy mode can work.

Detect when default_packet_size is zero, which enables zero-copy mode for
pfring and in that case, do what AF Packet does and set pkt_ext pointer to
the data and set PKT_ZERO_COPY flag.

11 years agoRemove pkt variable from Packet structure.
Ken Steele [Mon, 11 Nov 2013 16:58:31 +0000 (11:58 -0500)] 
Remove pkt variable from Packet structure.

The uint8_t *pkt in the Packet structure always points to the memory
immediately following the Packet structure. It is better to simply
calculate that value every time than store the 8 byte pointer.

11 years agoSplit AC-Tile MPM context into Search and Initialization structures. 714/head
Ken Steele [Wed, 13 Nov 2013 19:16:21 +0000 (14:16 -0500)] 
Split AC-Tile MPM context into Search and Initialization structures.

Some of the fields in the SCACTileCtx struct are only used to create the MPM,
but are not needed to search the MPM. Create a new structure to contain just
the data needed by AC Search. After creating the MPM, copy the data into the
new structure and then free the memory only needed during initialization.

This reduces the size of the AC-Tile MPM context from 1360 bytes down to 296
bytes.

11 years agompipe code cleanup: indent fixes
Victor Julien [Wed, 11 Dec 2013 10:53:08 +0000 (11:53 +0100)] 
mpipe code cleanup: indent fixes