From e6b880a3764447fff13b9fd0aff8e53a02add688 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 21 Sep 2019 18:23:01 +0300 Subject: [PATCH] Prevent serializing packets without an ID An attempt at such may arise from sending a structure intended to be used as part of other packets, but not a packet on its own. --- source/net/protocol.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/net/protocol.h b/source/net/protocol.h index 05ea60e..256d978 100644 --- a/source/net/protocol.h +++ b/source/net/protocol.h @@ -294,6 +294,8 @@ template unsigned Protocol::serialize(const P &pkt, char *buf, unsigned size) const { const PacketTypeDef

&pdef = get_packet_by_class

(); + if(!pdef.get_id()) + throw std::invalid_argument("no packet id"); char *ptr = pdef.serialize(pkt, buf+4, buf+size); size = ptr-buf; header_def.serialize(PacketHeader(pdef.get_id(), size), buf, buf+4); -- 2.43.0