mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +01:00
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:
parent
3b80e51439
commit
de3809aa7d
3 changed files with 7 additions and 5 deletions
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue