datajson: fix thread safety violation

pull/13432/head
Eric Leblond 3 months ago committed by Victor Julien
parent 40f86571d9
commit 0bc21eec48

@ -44,6 +44,13 @@ static inline void DatajsonUnlockData(THashData *d)
THashDataUnlock(d);
}
void DatajsonUnlockElt(DataJsonResultType *r)
{
if (r->hashdata) {
DatajsonUnlockData(r->hashdata);
}
}
/* return true if number is a float or an integer */
static bool IsFloat(const char *in, size_t ins)
{
@ -786,7 +793,7 @@ static DataJsonResultType DatajsonLookupString(
StringType *found = rdata->data;
rrep.found = true;
rrep.json = found->json;
DatajsonUnlockData(rdata);
rrep.hashdata = rdata;
return rrep;
}
return rrep;
@ -810,7 +817,7 @@ static DataJsonResultType DatajsonLookupMd5(
Md5Type *found = rdata->data;
rrep.found = true;
rrep.json = found->json;
DatajsonUnlockData(rdata);
rrep.hashdata = rdata;
return rrep;
}
return rrep;
@ -834,7 +841,7 @@ static DataJsonResultType DatajsonLookupSha256(
Sha256Type *found = rdata->data;
rrep.found = true;
rrep.json = found->json;
DatajsonUnlockData(rdata);
rrep.hashdata = rdata;
return rrep;
}
return rrep;
@ -858,7 +865,7 @@ static DataJsonResultType DatajsonLookupIPv4(
IPv4Type *found = rdata->data;
rrep.found = true;
rrep.json = found->json;
DatajsonUnlockData(rdata);
rrep.hashdata = rdata;
return rrep;
}
return rrep;
@ -883,7 +890,7 @@ static DataJsonResultType DatajsonLookupIPv6(
IPv6Type *found = rdata->data;
rrep.found = true;
rrep.json = found->json;
DatajsonUnlockData(rdata);
rrep.hashdata = rdata;
return rrep;
}
return rrep;

@ -37,6 +37,7 @@ typedef struct DataJsonType {
typedef struct DataJsonResultType {
bool found;
DataJsonType json;
THashData *hashdata;
} DataJsonResultType;
/* Common functions */
@ -49,4 +50,6 @@ DataJsonResultType DatajsonLookup(Dataset *set, const uint8_t *data, const uint3
int DatajsonAddSerialized(Dataset *set, const char *value, const char *json);
void DatajsonUnlockElt(DataJsonResultType *r);
#endif /* SURICATA_DATAJSON_H*/

@ -89,6 +89,7 @@ static int DetectDatajsonBufferMatch(DetectEngineThreadCtx *det_ctx, const Detec
det_ctx->json_content[det_ctx->json_content_len].id = sd->id;
det_ctx->json_content_len++;
}
DatajsonUnlockElt(&r);
}
return 1;
}

Loading…
Cancel
Save