From: Mikko Rasa Date: Sat, 21 Sep 2019 15:23:01 +0000 (+0300) Subject: Prevent serializing packets without an ID X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e6b880a3764447fff13b9fd0aff8e53a02add688;p=libs%2Fnet.git 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. --- 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);