]> git.tdb.fi Git - libs/net.git/commitdiff
Prevent serializing packets without an ID
authorMikko Rasa <tdb@tdb.fi>
Sat, 21 Sep 2019 15:23:01 +0000 (18:23 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 21 Sep 2019 15:23:01 +0000 (18:23 +0300)
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

index 05ea60e2f13232305a0ca18c9b50850db25e013c..256d978ec1d2ca0dfc24ce0bb29da4ac9f006445 100644 (file)
@@ -294,6 +294,8 @@ template<typename P>
 unsigned Protocol::serialize(const P &pkt, char *buf, unsigned size) const
 {
        const PacketTypeDef<P> &pdef = get_packet_by_class<P>();
+       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);