Commit Graph

5096 Commits (4922cd2d3699a2dcb472adee7569894105f14083)
 

Author SHA1 Message Date
Eric Leblond 8a5a30ba40 fix size_t printing
This two problem were found by the new version of the size_t cocci
test.
11 years ago
Victor Julien 446e68adca app-layer: only typedef opaque pointers once 11 years ago
Victor Julien 3b8e9ffbe9 app layer: void -> AppLayerProtoDetectThreadCtx
User AppLayerProtoDetectThreadCtx ptr instead of void.
11 years ago
Victor Julien 8dbf7a0d78 Update tests to use AppLayerParserThreadCtx ptr instead of void. Fix a few bugs uncovered by this. 11 years ago
Victor Julien 9634e60e7a 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 ago
Victor Julien c7ae662d26 Fix HTPBodyReassemblyTest01 Asan error
Fix improper pointer assignment in HTPBodyReassemblyTest01, causing
ASAN to error out.
11 years ago
Victor Julien fdefb65be4 app-layer: rename AppLayerThreadCtx funcs
AppLayerParserGetCtxThread -> AppLayerParserThreadCtxAlloc
AppLayerParserDestroyCtxThread -> AppLayerParserThreadCtxFree
11 years ago
Victor Julien 0bac43a1ca app layer: fix memory leak
Actually free the ctx in AppLayerParserDestroyCtxThread
11 years ago
Victor Julien f5f148805c app layer: uint16_t alproto -> AppProto alproto
This conversion was missing in a couple of places.
11 years ago
Victor Julien 5cdeadb33d Use u8 for ipproto
In a few places in app layer and unittests u16 was used.
11 years ago
Victor Julien 8527b8e08e App Layer: cleanup state func naming
Rename functions related to AppLayerState to be more consistent.
11 years ago
Victor Julien 30f16ee446 Rename AppLayerProtoDetectCtxThread -> AppLayerProtoDetectThreadCtx 11 years ago
Victor Julien cd0627cd39 Rename AppLayerParserParserState -> AppLayerParserState 11 years ago
Victor Julien c23742a0a7 Rename AppLayerParserpCtx -> AppLayerParserProtoCtx 11 years ago
Victor Julien 72a1645979 Rename AppLayerParserCtxThread -> AppLayerParserThreadCtx 11 years ago
Victor Julien ac77cd790f Rename AppLayerCtxThread -> AppLayerThreadCtx 11 years ago
Victor Julien e111401c10 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 ago
Victor Julien e2f7226569 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 ago
Victor Julien 67053e6ed0 Fix AppLayerProtoDetectPMFreeSignature related valgrind errors 11 years ago
Victor Julien ff16d6fa53 app proto detect: fix valgrind test warnings
Only in unittests when debug is enabled would valgrind warn about
a print statement.
11 years ago
Victor Julien a456bd8181 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 ago
Victor Julien 8801585f10 scan-build fixes 11 years ago
Victor Julien 106e1c7d19 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 ago
Victor Julien 1cbd1cdf36 compile fixes 11 years ago
Victor Julien 59327e0fd4 Various style fixes 11 years ago
Anoop Saldanha 429c6388f6 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 ago
Anoop Saldanha 127ef8f903 Use a typdef AppProto <-> uint16_t for representing app layer protocol.
Some minor refactoring/cleanup, including renaming functions.
11 years ago
Anoop Saldanha abded4200a 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 ago
Victor Julien d3d745d515 Update Changelog for 2.0beta2 11 years ago
Victor Julien b955ca7b86 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 ago
Victor Julien 3714925d2b 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 ago
Victor Julien 1cce207c05 Revert TmqhFlowMode alignment as it breaks on CLANG 11 years ago
Victor Julien 9874c1a83b realloc error handling: remove unnecessary else branch 11 years ago
Eric Leblond 1fbaebad63 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 ago
Eric Leblond 1f07d1521e 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 ago
Victor Julien 5e1f1ee4ff Fix filemagic unittests on OS_DARWIN 11 years ago
Ken Steele d12834769a 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 ago
Giuseppe Longo 8ba0fa7f92 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 ago
Victor Julien de22d6cf02 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 ago
Victor Julien 2913a4a860 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 ago
Victor Julien b605ee6fb2 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 ago
Victor Julien 2f094ca136 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 ago
Victor Julien 1252ee3f04 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 ago
Victor Julien 9d092f35e2 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 ago
Victor Julien 6ac30ae468 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 ago
Victor Julien 66c6c06916 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 ago
Victor Julien 7ea13f0f53 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 ago
Victor Julien 6709fdd8cf log-http: fix compiler warning
log-httplog.c:180: warning: 'cvalue' may be used uninitialized in \
this function
11 years ago
Victor Julien 31a94cd4cb defrag: pass u64 to ParseU64
Fixes: defrag-config.c:97: warning: passing argument 2 \
       of 'ParseSizeStringU64' from incompatible pointer type
11 years ago
Ken Steele 12ab6f3ab4 Fix uninitialized variable warning.
These two lines reported warnings with -Werror -O3 on Tile.
11 years ago