Changeset View
Standalone View
source/network/NMTCreator.h
Show First 20 Lines • Show All 214 Lines • ▼ Show 20 Lines | |||||
#define BAIL_DESERIALIZER return NULL | #define BAIL_DESERIALIZER return NULL | ||||
#define START_NMT_CLASS(_nm, _tp) \ | #define START_NMT_CLASS(_nm, _tp) \ | ||||
START_NMT_CLASS_DERIVED(CNetMessage, _nm, _tp) | START_NMT_CLASS_DERIVED(CNetMessage, _nm, _tp) | ||||
#define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \ | #define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \ | ||||
const u8 *_nm::Deserialize(const u8 *pos, const u8 *end) \ | const u8 *_nm::Deserialize(const u8 *pos, const u8 *end) \ | ||||
{ \ | { \ | ||||
pos=_base::Deserialize(pos, end); \ | pos=_base::Deserialize(pos, end); \ | ||||
if (pos == NULL) BAIL_DESERIALIZER;\ | |||||
wraitii: I would suggest putting the if null check here. | |||||
_nm *thiz=this; \ | _nm *thiz=this; \ | ||||
/*printf("In Deserialize" #_nm "\n"); */\ | /*printf("In Deserialize" #_nm "\n"); */\ | ||||
UNUSED2(thiz); // preempt any "unused" warning | UNUSED2(thiz); // preempt any "unused" warning | ||||
#define NMT_START_ARRAY(_nm) \ | #define NMT_START_ARRAY(_nm) \ | ||||
while (pos < end) \ | while (pos < end) \ | ||||
{ \ | { \ | ||||
ARRAY_STRUCT_PREFIX(_nm) *thiz=&*_nm.insert(_nm.end(), ARRAY_STRUCT_PREFIX(_nm)());\ | ARRAY_STRUCT_PREFIX(_nm) *thiz=&*_nm.insert(_nm.end(), ARRAY_STRUCT_PREFIX(_nm)());\ | ||||
UNUSED2(thiz); // preempt any "unused" warning | UNUSED2(thiz); // preempt any "unused" warning | ||||
#define NMT_END_ARRAY() \ | #define NMT_END_ARRAY() \ | ||||
} | } | ||||
#define NMT_FIELD_INT(_nm, _hosttp, _netsz) \ | #define NMT_FIELD_INT(_nm, _hosttp, _netsz) \ | ||||
if (pos+_netsz > end) BAIL_DESERIALIZER; \ | if (pos+_netsz > end) BAIL_DESERIALIZER; \ | ||||
Deserialize_int_##_netsz(pos, thiz->_nm); \ | Deserialize_int_##_netsz(pos, thiz->_nm); \ | ||||
/*printf("\t" #_nm " == 0x%x\n", thiz->_nm);*/ | /*printf("\t" #_nm " == 0x%x\n", thiz->_nm);*/ | ||||
#define NMT_FIELD(_tp, _nm) \ | #define NMT_FIELD(_tp, _nm) \ | ||||
if ((pos=thiz->_nm.Deserialize(pos, end)) == NULL) BAIL_DESERIALIZER; | if ((pos=thiz->_nm.Deserialize(pos, end)) == NULL) BAIL_DESERIALIZER; | ||||
Not Done Inline ActionsSpace before \, nullptr instead of NULL. Why that was NULL instead of a correct value? vladislavbelov: Space before `\`, `nullptr` instead of `NULL`. Why that was `NULL` instead of a correct value? | |||||
Done Inline ActionsSee summary, it is NULL because CNetMessage::Deserialize returns NULL "CNetMessage: Corrupt packet (incorrect size)". elexis: See summary, it is NULL because `CNetMessage::Deserialize` returns NULL `"CNetMessage: Corrupt… | |||||
Not Done Inline ActionsYes, but why we continue the deserializing if we know that it's impossible? vladislavbelov: Yes, but why we continue the deserializing if we know that it's impossible? | |||||
Done Inline ActionsIt continued to deserialize because the check that this patch added had not been added when the code was written (rP122?). (And CNetMessage::Deserialize only deserializes message type and data length, detects failure, returns null, so it does abandon, it just can't abandon the entire packet deserialization because the entire packet deserialization is coded in NMTCreator.h here) elexis: It continued to deserialize because the check that this patch added had not been added when the… | |||||
Not Done Inline ActionsOk, that seems more reasonable. So in which place we got pos == nullptr? vladislavbelov: Ok, that seems more reasonable. So in which place we got `pos == nullptr`? | |||||
Not Done Inline ActionsI would move the check above (cf other inline), it looks cleaner (and would be slightly more performant) wraitii: I would move the check above (cf other inline), it looks cleaner (and would be slightly more… | |||||
#define END_NMT_CLASS() \ | #define END_NMT_CLASS() \ | ||||
return pos; \ | return pos; \ | ||||
} | } | ||||
#include "NMTCreator.h" | #include "NMTCreator.h" | ||||
#undef BAIL_DESERIALIZER | #undef BAIL_DESERIALIZER | ||||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |
I would suggest putting the if null check here.