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