fix crash when 0-length mqtt buffers arrive

Which is what happens when you "clear" retained messages
This commit is contained in:
Eric House 2022-12-28 23:19:52 -08:00
parent 5175775b1d
commit ae9d576bad
2 changed files with 5 additions and 4 deletions

View file

@ -1756,7 +1756,7 @@
device supports, or you may have recently removed its last way of device supports, or you may have recently removed its last way of
connecting.)</string> connecting.)</string>
<!-- --> <!-- -->
<string name="connstat_net_fmt">Network status for game (ID=%2$d) connected via <string name="connstat_net_fmt">Network status for game (ID=%2$X) connected via
%1$s:</string> %1$s:</string>
<!-- Debug-only menuitem to launch net status info --> <!-- Debug-only menuitem to launch net status info -->

View file

@ -464,7 +464,7 @@ void
dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* topic, dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* topic,
const XP_U8* buf, XP_U16 len ) const XP_U8* buf, XP_U16 len )
{ {
XP_LOGFF( "(topic=%s)", topic ); XP_LOGFF( "(topic=%s, len=%d)", topic, len );
MQTTDevID myID; MQTTDevID myID;
dvc_getMQTTDevID( dutil, xwe, &myID ); dvc_getMQTTDevID( dutil, xwe, &myID );
@ -474,8 +474,9 @@ dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* topic,
XWStreamCtxt* stream = mkStream( dutil ); XWStreamCtxt* stream = mkStream( dutil );
stream_putBytes( stream, buf, len ); stream_putBytes( stream, buf, len );
XP_U8 proto = stream_getU8( stream ); XP_U8 proto = 0;
if ( proto == PROTO_1 || proto == PROTO_2 || proto == PROTO_3 ) { if ( stream_gotU8( stream, &proto )
&& (proto == PROTO_1 || proto == PROTO_2 || proto == PROTO_3 ) ) {
MQTTDevID senderID; MQTTDevID senderID;
stream_getBytes( stream, &senderID, sizeof(senderID) ); stream_getBytes( stream, &senderID, sizeof(senderID) );
senderID = be64toh( senderID ); senderID = be64toh( senderID );