decode: propagate PacketAlertCreate failure instead of crashing

PacketAlertCreate is called from PacketInit on the packet allocation
path. Make PacketInit return bool and propagate the NULL result from
PacketAlertCreate up through PacketGetFromAlloc, which already returns
NULL to signal allocation failure to its callers.

Update the UNITTESTS-only helpers in defrag.c accordingly: helpers
returning Packet * use an explicit NULL check; the one returning int
keeps the existing FAIL_IF style.
This commit is contained in:
Denis Balashov
2026-06-10 20:57:40 +00:00
committed by Victor Julien
parent 344e89e3c6
commit 3828de20ed
4 changed files with 24 additions and 11 deletions
+5 -5
View File
@@ -143,10 +143,7 @@ ExceptionPolicyStatsSetts flow_memcap_eps_stats = {
*/
PacketAlert *PacketAlertCreate(void)
{
PacketAlert *pa_array = SCCalloc(packet_alert_max, sizeof(PacketAlert));
DEBUG_VALIDATE_BUG_ON(pa_array == NULL);
return pa_array;
return SCCalloc(packet_alert_max, sizeof(PacketAlert));
}
void PacketAlertRecycle(PacketAlert *pa_array, uint16_t cnt)
@@ -267,7 +264,10 @@ Packet *PacketGetFromAlloc(void)
if (unlikely(p == NULL)) {
return NULL;
}
PacketInit(p);
if (!PacketInit(p)) {
SCFree(p);
return NULL;
}
p->ReleasePacket = PacketFree;
SCLogDebug("allocated a new packet only using alloc...");
+13 -4
View File
@@ -1158,7 +1158,10 @@ static Packet *BuildIpv4TestPacket(
if (unlikely(p == NULL))
return NULL;
PacketInit(p);
if (!PacketInit(p)) {
SCFree(p);
return NULL;
}
struct timeval tval;
gettimeofday(&tval, NULL);
@@ -1222,7 +1225,7 @@ static int BuildIpv4TestPacketWithContent(Packet **packet, uint8_t proto, uint16
p = SCCalloc(1, sizeof(*p) + default_packet_size);
FAIL_IF_NULL(p);
PacketInit(p);
FAIL_IF(!PacketInit(p));
struct timeval tval;
gettimeofday(&tval, NULL);
@@ -1277,7 +1280,10 @@ static Packet *BuildIpv6TestPacket(
if (unlikely(p == NULL))
return NULL;
PacketInit(p);
if (!PacketInit(p)) {
SCFree(p);
return NULL;
}
struct timeval tval;
gettimeofday(&tval, NULL);
@@ -1347,7 +1353,10 @@ static Packet *BuildIpv6TestPacketWithContent(
if (unlikely(p == NULL))
return NULL;
PacketInit(p);
if (!PacketInit(p)) {
SCFree(p);
return NULL;
}
struct timeval tval;
gettimeofday(&tval, NULL);
+5 -1
View File
@@ -70,12 +70,16 @@ uint8_t PacketGetAction(const Packet *p)
/**
* \brief Initialize a packet structure for use.
*/
void PacketInit(Packet *p)
bool PacketInit(Packet *p)
{
SCSpinInit(&p->persistent.tunnel_lock, 0);
p->alerts.alerts = PacketAlertCreate();
if (unlikely(p->alerts.alerts == NULL)) {
return false;
}
p->livedev_id = 0;
p->livedev_dst_id = 0;
return true;
}
void PacketReleaseRefs(Packet *p)
+1 -1
View File
@@ -32,7 +32,7 @@ static inline uint8_t PacketTestAction(const Packet *p, const uint8_t a)
}
#endif
void PacketInit(Packet *p);
bool PacketInit(Packet *p);
void PacketReleaseRefs(Packet *p);
void PacketReinit(Packet *p);
void PacketRecycle(Packet *p);