fix crash when chat message is too long

Len byte was limited to 255, but would get clipped (masked with 0xFF)
then all the string data would get written. So on receipt, the clipped
length was taken to be that of the string data, with the rest of the
string to be interpreted as something else. An array index, in this
case.
This commit is contained in:
Eric House 2020-03-26 18:12:37 -07:00
parent 1f5ff11a9a
commit 512a8e1afa
3 changed files with 7 additions and 5 deletions

View file

@ -1868,7 +1868,7 @@ public class DBUtils {
{
Assert.assertNotNull( msg );
Assert.assertFalse( -1 == fromPlayer );
ArrayList<ContentValues> valuess = new ArrayList<ContentValues>();
ArrayList<ContentValues> valuess = new ArrayList<>();
valuess.add( cvForChat( rowid, msg, fromPlayer, tsSeconds ) );
appendChatHistory( context, valuess );
Log.i( TAG, "appendChatHistory: inserted \"%s\" from player %d",

View file

@ -722,7 +722,6 @@ sendChatTo( ServerCtxt* server, XP_U16 devIndex, const XP_UCHAR* msg,
XWStreamCtxt* stream = messageStreamWithHeader( server, devIndex,
XWPROTO_CHAT );
stringToStream( stream, msg );
XP_ASSERT( from < server->vol.gi->nPlayers );
stream_putU8( stream, from );
stream_putU32( stream, timestamp );
stream_destroy( stream );
@ -766,7 +765,6 @@ receiveChat( ServerCtxt* server, XWStreamCtxt* incoming )
sendChatToClientsExcept( server, sourceClientIndex, msg, from,
timestamp );
}
XP_ASSERT( from < server->vol.gi->nPlayers );
util_showChat( server->vol.util, msg, from, timestamp );
XP_FREE( server->mpool, msg );
return XP_TRUE;

View file

@ -267,8 +267,12 @@ stringFromStreamHere( XWStreamCtxt* stream, XP_UCHAR* buf, XP_U16 buflen )
void
stringToStream( XWStreamCtxt* stream, const XP_UCHAR* str )
{
XP_U16 len = str==NULL? 0: XP_STRLEN( str );
XP_ASSERT( len < 0xFF );
XP_U16 len = str == NULL? 0: XP_STRLEN( str );
if ( len > 0xFF ) {
XP_LOGFF( "truncating string '%s', dropping len from %d to %d",
str, len, 0xFF );
len = 0xFF;
}
stream_putU8( stream, (XP_U8)len );
stream_putBytes( stream, str, len );
} /* putStringToStream */