From 397f5f5fdf11204027b045bb4e8ca89676dac2ed Mon Sep 17 00:00:00 2001 From: Giuseppe Longo Date: Thu, 18 Jan 2018 12:49:53 +0100 Subject: [PATCH] app-layer-parser: don't overwrite stream_depth value When an app-layer parser is enabled, it could set its own stream_depth value calling the API AppLayerParserSetStreamDepth. Then, the function AppLayerParserPostStreamSetup will replace the stream_depth value already set with stream_config.reassembly_depth. To avoid overwriting, in AppLayerParserSetStreamDepth API a flag will be set internally to specify that a value is already set. --- src/app-layer-parser.c | 9 +++++++-- src/app-layer-parser.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index a91ad052f5..cd42cfc057 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -209,8 +209,11 @@ void AppLayerParserPostStreamSetup(void) /* lets set a default value for stream_depth */ for (flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) { for (alproto = 0; alproto < ALPROTO_MAX; alproto++) { - alp_ctx.ctxs[flow_proto][alproto].stream_depth = - stream_config.reassembly_depth; + if (!(alp_ctx.ctxs[flow_proto][alproto].flags & + APP_LAYER_PARSER_OPT_STREAM_DEPTH_SET)) { + alp_ctx.ctxs[flow_proto][alproto].stream_depth = + stream_config.reassembly_depth; + } } } } @@ -1315,6 +1318,8 @@ void AppLayerParserSetStreamDepth(uint8_t ipproto, AppProto alproto, uint32_t st SCEnter(); alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].stream_depth = stream_depth; + alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].flags |= + APP_LAYER_PARSER_OPT_STREAM_DEPTH_SET; SCReturn; } diff --git a/src/app-layer-parser.h b/src/app-layer-parser.h index 61d28db610..cec6bf1ac1 100644 --- a/src/app-layer-parser.h +++ b/src/app-layer-parser.h @@ -39,6 +39,7 @@ /* Flags for AppLayerParserProtoCtx. */ #define APP_LAYER_PARSER_OPT_ACCEPT_GAPS BIT_U64(0) +#define APP_LAYER_PARSER_OPT_STREAM_DEPTH_SET BIT_U64(1) /* applies to DetectFlags uint64_t field */ -- 2.47.2