|
@@ -12,11 +12,21 @@ __declspec( dllexport ) Frame &Frame::operator+=( const Frame &b ) // baut frame
|
|
|
if( opcode == 0 )
|
|
|
opcode = b.opcode;
|
|
|
dataLength += b.dataLength;
|
|
|
- char *data = new char[ dataLength ];
|
|
|
- memcpy( data, this->data, dataLength - b.dataLength );
|
|
|
- memcpy( data + dataLength, b.data, b.dataLength );
|
|
|
- delete[] this->data;
|
|
|
- this->data = data;
|
|
|
+ if( dataLength )
|
|
|
+ {
|
|
|
+ char *data = new char[ dataLength ];
|
|
|
+ if( data )
|
|
|
+ memcpy( data, this->data, dataLength - b.dataLength );
|
|
|
+ if( b.data )
|
|
|
+ memcpy( data + dataLength, b.data, b.dataLength );
|
|
|
+ delete[] this->data;
|
|
|
+ this->data = data;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ delete[] this->data;
|
|
|
+ this->data = 0;
|
|
|
+ }
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
@@ -151,6 +161,7 @@ __declspec( dllexport ) void WebSocketClient::thread()
|
|
|
}
|
|
|
if( klient->hatNachricht( 100 ) )
|
|
|
{
|
|
|
+ bool ok = 1;
|
|
|
c2.unlock();
|
|
|
bool first = 1;
|
|
|
Frame m;
|
|
@@ -164,58 +175,60 @@ __declspec( dllexport ) void WebSocketClient::thread()
|
|
|
return;
|
|
|
}
|
|
|
Frame message;
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.fin = ( byte & 0x80 ) != 0;
|
|
|
message.rsv1 = ( byte & 0x40 ) != 0;
|
|
|
message.rsv2 = ( byte & 0x20 ) != 0;
|
|
|
message.rsv3 = ( byte & 0x10 ) != 0;
|
|
|
message.opcode = byte & 0xF;
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.mask = ( byte & 0x80 ) != 0;
|
|
|
message.dataLength = byte & 0x7F;
|
|
|
if( message.dataLength == 126 )
|
|
|
{
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.dataLength = byte << 8;
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.dataLength |= byte;
|
|
|
}
|
|
|
else if( message.dataLength == 127 )
|
|
|
{
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.dataLength = (__int64)byte << 56;
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.dataLength |= (__int64)byte << 48;
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.dataLength |= (__int64)byte << 40;
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.dataLength |= (__int64)byte << 32;
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.dataLength |= (__int64)byte << 24;
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.dataLength |= (__int64)byte << 16;
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.dataLength |= (__int64)byte << 8;
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.dataLength |= (__int64)byte;
|
|
|
}
|
|
|
if( message.mask )
|
|
|
{
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.key[ 0 ] = byte;
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.key[ 1 ] = byte;
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.key[ 2 ] = byte;
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
message.key[ 3 ] = byte;
|
|
|
}
|
|
|
+ if( !ok )
|
|
|
+ message.dataLength = 1;
|
|
|
message.data = 0;
|
|
|
if( message.dataLength )
|
|
|
message.data = new char[ message.dataLength ];
|
|
|
for( int i = 0; i < message.dataLength; i++ )
|
|
|
{
|
|
|
- klient->getNachricht( (char*)&byte, 1 );
|
|
|
+ ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
if( message.mask )
|
|
|
message.data[ i ] = byte ^ message.key[ i % 4 ];
|
|
|
else
|
|
@@ -230,7 +243,14 @@ __declspec( dllexport ) void WebSocketClient::thread()
|
|
|
delete[] message.data;
|
|
|
}
|
|
|
first = 0;
|
|
|
+ if( !ok )
|
|
|
+ break;
|
|
|
} while( !m.fin );
|
|
|
+ if( !ok )
|
|
|
+ {
|
|
|
+ delete[] m.data;
|
|
|
+ return;
|
|
|
+ }
|
|
|
if( m.opcode == 0x9 )
|
|
|
{
|
|
|
m.opcode = 0xA;
|