ndpi: don't access flow storage directly

Remove the check for Flow.storage being NULL. With flex arrays, as long as the
flow is allocated, .storage will never be NULL. We do make sure the flow
is not NULL, and the storage functions are safe to the storage being
NULL.

Prevents NDPI from accessing this flow field to be less sensitive to ABI
changes with respect to data structure sizes.

Ticket: #8632
pull/16053/head
Jason Ish 5 months ago committed by Victor Julien
parent e51cc381b7
commit f739a8a73c

@ -71,13 +71,11 @@ static inline struct NdpiThreadContext *NdpiGetThreadContext(ThreadVars *tv)
/** /**
* Safe helper to get nDPI flow context. Returns NULL if the flow * Safe helper to get nDPI flow context. Returns NULL if the flow
* or its storage is not available. Guards against the case where * context is not available.
* f->storage is NULL (uninitialized flow) which would crash inside
* SCStorageGetById.
*/ */
static inline struct NdpiFlowContext *NdpiGetFlowContext(const Flow *f) static inline struct NdpiFlowContext *NdpiGetFlowContext(const Flow *f)
{ {
if (unlikely(f == NULL || flow_storage_id.id < 0 || f->storage == NULL)) if (unlikely(f == NULL || flow_storage_id.id < 0))
return NULL; return NULL;
return SCFlowGetStorageById(f, flow_storage_id); return SCFlowGetStorageById(f, flow_storage_id);
} }
@ -108,11 +106,6 @@ static void OnFlowInit(ThreadVars *tv, Flow *f, const Packet *p, void *_data)
if (unlikely(f == NULL)) if (unlikely(f == NULL))
return; return;
if (unlikely(f->storage == NULL)) {
SCLogDebug("Flow %p has no storage, skipping nDPI init", f);
return;
}
struct NdpiFlowContext *flowctx = SCCalloc(1, sizeof(*flowctx)); struct NdpiFlowContext *flowctx = SCCalloc(1, sizeof(*flowctx));
if (flowctx == NULL) { if (flowctx == NULL) {
SCLogDebug("Failed to allocate nDPI flow context"); SCLogDebug("Failed to allocate nDPI flow context");

Loading…
Cancel
Save