Bug 1059813: Use getter/setter methods of |UnixSocketRawData| in Bluetooth, r=btian

This commit is contained in:
Thomas Zimmermann 2014-09-08 11:44:02 +02:00
parent 7eed41850f
commit bc211f689d
6 changed files with 74 additions and 66 deletions

View File

@ -751,6 +751,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aMessage); MOZ_ASSERT(aMessage);
const uint8_t* data = aMessage->GetData();
int frameHeaderLength = 0; int frameHeaderLength = 0;
// See if this is the first part of each Put packet // See if this is the first part of each Put packet
@ -759,8 +760,9 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
// [opcode:1][length:2][Headers:var] // [opcode:1][length:2][Headers:var]
frameHeaderLength = 3; frameHeaderLength = 3;
mPacketLength = ((((int)aMessage->mData[1]) << 8) | aMessage->mData[2]) - mPacketLength = ((static_cast<int>(data[1]) << 8) | data[2]) -
frameHeaderLength; frameHeaderLength;
/** /**
* A PUT request from remote devices may be divided into multiple parts. * A PUT request from remote devices may be divided into multiple parts.
* In other words, one request may need to be received multiple times, * In other words, one request may need to be received multiple times,
@ -771,7 +773,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal); mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal);
} }
int dataLength = aMessage->mSize - frameHeaderLength; int dataLength = aMessage->GetSize() - frameHeaderLength;
// Check length before memcpy to prevent from memory pollution // Check length before memcpy to prevent from memory pollution
if (dataLength < 0 || if (dataLength < 0 ||
@ -786,7 +788,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
} }
memcpy(mReceivedDataBuffer.get() + mPutPacketReceivedLength, memcpy(mReceivedDataBuffer.get() + mPutPacketReceivedLength,
&aMessage->mData[frameHeaderLength], dataLength); &data[frameHeaderLength], dataLength);
mPutPacketReceivedLength += dataLength; mPutPacketReceivedLength += dataLength;
@ -799,12 +801,13 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
uint8_t opCode; uint8_t opCode;
int receivedLength = aMessage->mSize; int receivedLength = aMessage->GetSize();
const uint8_t* data = aMessage->GetData();
if (mPutPacketReceivedLength > 0) { if (mPutPacketReceivedLength > 0) {
opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put; opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put;
} else { } else {
opCode = aMessage->mData[0]; opCode = data[0];
// When there's a Put packet right after a PutFinal packet, // When there's a Put packet right after a PutFinal packet,
// which means it's the start point of a new file. // which means it's the start point of a new file.
@ -821,7 +824,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
// Section 3.3.1 "Connect", IrOBEX 1.2 // Section 3.3.1 "Connect", IrOBEX 1.2
// [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2] // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
// [Headers:var] // [Headers:var]
if (!ParseHeaders(&aMessage->mData[7], receivedLength - 7, &pktHeaders)) { if (!ParseHeaders(&data[7], receivedLength - 7, &pktHeaders)) {
ReplyError(ObexResponseCode::BadRequest); ReplyError(ObexResponseCode::BadRequest);
return; return;
} }
@ -831,7 +834,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
} else if (opCode == ObexRequestCode::Abort) { } else if (opCode == ObexRequestCode::Abort) {
// Section 3.3.5 "Abort", IrOBEX 1.2 // Section 3.3.5 "Abort", IrOBEX 1.2
// [opcode:1][length:2][Headers:var] // [opcode:1][length:2][Headers:var]
if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
ReplyError(ObexResponseCode::BadRequest); ReplyError(ObexResponseCode::BadRequest);
return; return;
} }
@ -841,7 +844,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
} else if (opCode == ObexRequestCode::Disconnect) { } else if (opCode == ObexRequestCode::Disconnect) {
// Section 3.3.2 "Disconnect", IrOBEX 1.2 // Section 3.3.2 "Disconnect", IrOBEX 1.2
// [opcode:1][length:2][Headers:var] // [opcode:1][length:2][Headers:var]
if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
ReplyError(ObexResponseCode::BadRequest); ReplyError(ObexResponseCode::BadRequest);
return; return;
} }
@ -924,7 +927,8 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
uint8_t opCode = aMessage->mData[0]; const uint8_t* data = aMessage->GetData();
uint8_t opCode = data[0];
// Check response code and send out system message as finished if the response // Check response code and send out system message as finished if the response
// code is somehow incorrect. // code is somehow incorrect.
@ -981,10 +985,9 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage)
AfterOppConnected(); AfterOppConnected();
// Keep remote information // Keep remote information
mRemoteObexVersion = aMessage->mData[3]; mRemoteObexVersion = data[3];
mRemoteConnectionFlags = aMessage->mData[4]; mRemoteConnectionFlags = data[4];
mRemoteMaxPacketLength = mRemoteMaxPacketLength = ((static_cast<int>(data[5]) << 8) | data[6]);
(((int)(aMessage->mData[5]) << 8) | aMessage->mData[6]);
// The length of file name exceeds maximum length. // The length of file name exceeds maximum length.
int fileNameByteLen = (mFileName.Length() + 1) * 2; int fileNameByteLen = (mFileName.Length() + 1) * 2;
@ -1253,8 +1256,7 @@ BluetoothOppManager::SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize)
mLastCommand = aOpcode; mLastCommand = aOpcode;
} }
UnixSocketRawData* s = new UnixSocketRawData(aSize); UnixSocketRawData* s = new UnixSocketRawData(aData, aSize);
memcpy(s->mData, aData, s->mSize);
mSocket->SendSocketData(s); mSocket->SendSocketData(s);
} }

View File

@ -707,7 +707,8 @@ BluetoothHfpManager::ReceiveSocketData(BluetoothSocket* aSocket,
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aSocket); MOZ_ASSERT(aSocket);
nsAutoCString msg((const char*)aMessage->mData.get(), aMessage->mSize); nsAutoCString msg(reinterpret_cast<const char*>(aMessage->GetData()),
aMessage->GetSize());
msg.StripWhitespace(); msg.StripWhitespace();
nsTArray<nsCString> atCommandValues; nsTArray<nsCString> atCommandValues;

View File

@ -774,6 +774,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
MOZ_ASSERT(aMessage); MOZ_ASSERT(aMessage);
int frameHeaderLength = 0; int frameHeaderLength = 0;
const uint8_t* data = aMessage->GetData();
// See if this is the first part of each Put packet // See if this is the first part of each Put packet
if (mPutPacketReceivedLength == 0) { if (mPutPacketReceivedLength == 0) {
@ -781,8 +782,8 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
// [opcode:1][length:2][Headers:var] // [opcode:1][length:2][Headers:var]
frameHeaderLength = 3; frameHeaderLength = 3;
mPacketLength = ((((int)aMessage->mData[1]) << 8) | aMessage->mData[2]) - mPacketLength = ((static_cast<int>(data[1]) << 8) | data[2]) -
frameHeaderLength; frameHeaderLength;
/** /**
* A PUT request from remote devices may be divided into multiple parts. * A PUT request from remote devices may be divided into multiple parts.
* In other words, one request may need to be received multiple times, * In other words, one request may need to be received multiple times,
@ -793,7 +794,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal); mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal);
} }
int dataLength = aMessage->mSize - frameHeaderLength; int dataLength = aMessage->GetSize() - frameHeaderLength;
// Check length before memcpy to prevent from memory pollution // Check length before memcpy to prevent from memory pollution
if (dataLength < 0 || if (dataLength < 0 ||
@ -808,7 +809,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
} }
memcpy(mReceivedDataBuffer.get() + mPutPacketReceivedLength, memcpy(mReceivedDataBuffer.get() + mPutPacketReceivedLength,
&aMessage->mData[frameHeaderLength], dataLength); &data[frameHeaderLength], dataLength);
mPutPacketReceivedLength += dataLength; mPutPacketReceivedLength += dataLength;
@ -821,12 +822,13 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
uint8_t opCode; uint8_t opCode;
int receivedLength = aMessage->mSize; int receivedLength = aMessage->GetSize();
const uint8_t* data = aMessage->GetData();
if (mPutPacketReceivedLength > 0) { if (mPutPacketReceivedLength > 0) {
opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put; opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put;
} else { } else {
opCode = aMessage->mData[0]; opCode = data[0];
// When there's a Put packet right after a PutFinal packet, // When there's a Put packet right after a PutFinal packet,
// which means it's the start point of a new file. // which means it's the start point of a new file.
@ -843,7 +845,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
// Section 3.3.1 "Connect", IrOBEX 1.2 // Section 3.3.1 "Connect", IrOBEX 1.2
// [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2] // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
// [Headers:var] // [Headers:var]
if (!ParseHeaders(&aMessage->mData[7], receivedLength - 7, &pktHeaders)) { if (!ParseHeaders(&data[7], receivedLength - 7, &pktHeaders)) {
ReplyError(ObexResponseCode::BadRequest); ReplyError(ObexResponseCode::BadRequest);
return; return;
} }
@ -853,7 +855,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
} else if (opCode == ObexRequestCode::Abort) { } else if (opCode == ObexRequestCode::Abort) {
// Section 3.3.5 "Abort", IrOBEX 1.2 // Section 3.3.5 "Abort", IrOBEX 1.2
// [opcode:1][length:2][Headers:var] // [opcode:1][length:2][Headers:var]
if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
ReplyError(ObexResponseCode::BadRequest); ReplyError(ObexResponseCode::BadRequest);
return; return;
} }
@ -863,7 +865,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
} else if (opCode == ObexRequestCode::Disconnect) { } else if (opCode == ObexRequestCode::Disconnect) {
// Section 3.3.2 "Disconnect", IrOBEX 1.2 // Section 3.3.2 "Disconnect", IrOBEX 1.2
// [opcode:1][length:2][Headers:var] // [opcode:1][length:2][Headers:var]
if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
ReplyError(ObexResponseCode::BadRequest); ReplyError(ObexResponseCode::BadRequest);
return; return;
} }
@ -946,7 +948,8 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
uint8_t opCode = aMessage->mData[0]; const uint8_t* data = aMessage->GetData();
uint8_t opCode = data[0];
// Check response code and send out system message as finished if the response // Check response code and send out system message as finished if the response
// code is somehow incorrect. // code is somehow incorrect.
@ -1003,10 +1006,9 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage)
AfterOppConnected(); AfterOppConnected();
// Keep remote information // Keep remote information
mRemoteObexVersion = aMessage->mData[3]; mRemoteObexVersion = data[3];
mRemoteConnectionFlags = aMessage->mData[4]; mRemoteConnectionFlags = data[4];
mRemoteMaxPacketLength = mRemoteMaxPacketLength = (static_cast<int>(data[5]) << 8) | data[6];
(((int)(aMessage->mData[5]) << 8) | aMessage->mData[6]);
// The length of file name exceeds maximum length. // The length of file name exceeds maximum length.
int fileNameByteLen = (mFileName.Length() + 1) * 2; int fileNameByteLen = (mFileName.Length() + 1) * 2;
@ -1274,8 +1276,7 @@ BluetoothOppManager::SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize)
mLastCommand = aOpcode; mLastCommand = aOpcode;
} }
UnixSocketRawData* s = new UnixSocketRawData(aSize); UnixSocketRawData* s = new UnixSocketRawData(aData, aSize);
memcpy(s->mData, aData, s->mSize);
mSocket->SendSocketData(s); mSocket->SendSocketData(s);
} }

View File

@ -751,6 +751,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aMessage); MOZ_ASSERT(aMessage);
const uint8_t* data = aMessage->GetData();
int frameHeaderLength = 0; int frameHeaderLength = 0;
// See if this is the first part of each Put packet // See if this is the first part of each Put packet
@ -759,8 +760,9 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
// [opcode:1][length:2][Headers:var] // [opcode:1][length:2][Headers:var]
frameHeaderLength = 3; frameHeaderLength = 3;
mPacketLength = ((((int)aMessage->mData[1]) << 8) | aMessage->mData[2]) - mPacketLength = ((static_cast<int>(data[1]) << 8) | data[2]) -
frameHeaderLength; frameHeaderLength;
/** /**
* A PUT request from remote devices may be divided into multiple parts. * A PUT request from remote devices may be divided into multiple parts.
* In other words, one request may need to be received multiple times, * In other words, one request may need to be received multiple times,
@ -771,7 +773,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal); mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal);
} }
int dataLength = aMessage->mSize - frameHeaderLength; int dataLength = aMessage->GetSize() - frameHeaderLength;
// Check length before memcpy to prevent from memory pollution // Check length before memcpy to prevent from memory pollution
if (dataLength < 0 || if (dataLength < 0 ||
@ -786,7 +788,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
} }
memcpy(mReceivedDataBuffer.get() + mPutPacketReceivedLength, memcpy(mReceivedDataBuffer.get() + mPutPacketReceivedLength,
&aMessage->mData[frameHeaderLength], dataLength); &data[frameHeaderLength], dataLength);
mPutPacketReceivedLength += dataLength; mPutPacketReceivedLength += dataLength;
@ -799,12 +801,13 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
uint8_t opCode; uint8_t opCode;
int receivedLength = aMessage->mSize; int receivedLength = aMessage->GetSize();
const uint8_t* data = aMessage->GetData();
if (mPutPacketReceivedLength > 0) { if (mPutPacketReceivedLength > 0) {
opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put; opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put;
} else { } else {
opCode = aMessage->mData[0]; opCode = data[0];
// When there's a Put packet right after a PutFinal packet, // When there's a Put packet right after a PutFinal packet,
// which means it's the start point of a new file. // which means it's the start point of a new file.
@ -821,7 +824,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
// Section 3.3.1 "Connect", IrOBEX 1.2 // Section 3.3.1 "Connect", IrOBEX 1.2
// [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2] // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
// [Headers:var] // [Headers:var]
if (!ParseHeaders(&aMessage->mData[7], receivedLength - 7, &pktHeaders)) { if (!ParseHeaders(&data[7], receivedLength - 7, &pktHeaders)) {
ReplyError(ObexResponseCode::BadRequest); ReplyError(ObexResponseCode::BadRequest);
return; return;
} }
@ -831,7 +834,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
} else if (opCode == ObexRequestCode::Abort) { } else if (opCode == ObexRequestCode::Abort) {
// Section 3.3.5 "Abort", IrOBEX 1.2 // Section 3.3.5 "Abort", IrOBEX 1.2
// [opcode:1][length:2][Headers:var] // [opcode:1][length:2][Headers:var]
if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
ReplyError(ObexResponseCode::BadRequest); ReplyError(ObexResponseCode::BadRequest);
return; return;
} }
@ -841,7 +844,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
} else if (opCode == ObexRequestCode::Disconnect) { } else if (opCode == ObexRequestCode::Disconnect) {
// Section 3.3.2 "Disconnect", IrOBEX 1.2 // Section 3.3.2 "Disconnect", IrOBEX 1.2
// [opcode:1][length:2][Headers:var] // [opcode:1][length:2][Headers:var]
if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
ReplyError(ObexResponseCode::BadRequest); ReplyError(ObexResponseCode::BadRequest);
return; return;
} }
@ -924,7 +927,8 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
uint8_t opCode = aMessage->mData[0]; const uint8_t* data = aMessage->GetData();
uint8_t opCode = data[0];
// Check response code and send out system message as finished if the response // Check response code and send out system message as finished if the response
// code is somehow incorrect. // code is somehow incorrect.
@ -981,10 +985,9 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage)
AfterOppConnected(); AfterOppConnected();
// Keep remote information // Keep remote information
mRemoteObexVersion = aMessage->mData[3]; mRemoteObexVersion = data[3];
mRemoteConnectionFlags = aMessage->mData[4]; mRemoteConnectionFlags = data[4];
mRemoteMaxPacketLength = mRemoteMaxPacketLength = ((static_cast<int>(data[5]) << 8) | data[6]);
(((int)(aMessage->mData[5]) << 8) | aMessage->mData[6]);
// The length of file name exceeds maximum length. // The length of file name exceeds maximum length.
int fileNameByteLen = (mFileName.Length() + 1) * 2; int fileNameByteLen = (mFileName.Length() + 1) * 2;
@ -1253,8 +1256,7 @@ BluetoothOppManager::SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize)
mLastCommand = aOpcode; mLastCommand = aOpcode;
} }
UnixSocketRawData* s = new UnixSocketRawData(aSize); UnixSocketRawData* s = new UnixSocketRawData(aData, aSize);
memcpy(s->mData, aData, s->mSize);
mSocket->SendSocketData(s); mSocket->SendSocketData(s);
} }

View File

@ -707,7 +707,8 @@ BluetoothHfpManager::ReceiveSocketData(BluetoothSocket* aSocket,
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aSocket); MOZ_ASSERT(aSocket);
nsAutoCString msg((const char*)aMessage->mData.get(), aMessage->mSize); nsAutoCString msg(reinterpret_cast<const char*>(aMessage->GetData()),
aMessage->GetSize());
msg.StripWhitespace(); msg.StripWhitespace();
nsTArray<nsCString> atCommandValues; nsTArray<nsCString> atCommandValues;

View File

@ -774,6 +774,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
MOZ_ASSERT(aMessage); MOZ_ASSERT(aMessage);
int frameHeaderLength = 0; int frameHeaderLength = 0;
const uint8_t* data = aMessage->GetData();
// See if this is the first part of each Put packet // See if this is the first part of each Put packet
if (mPutPacketReceivedLength == 0) { if (mPutPacketReceivedLength == 0) {
@ -781,8 +782,8 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
// [opcode:1][length:2][Headers:var] // [opcode:1][length:2][Headers:var]
frameHeaderLength = 3; frameHeaderLength = 3;
mPacketLength = ((((int)aMessage->mData[1]) << 8) | aMessage->mData[2]) - mPacketLength = ((static_cast<int>(data[1]) << 8) | data[2]) -
frameHeaderLength; frameHeaderLength;
/** /**
* A PUT request from remote devices may be divided into multiple parts. * A PUT request from remote devices may be divided into multiple parts.
* In other words, one request may need to be received multiple times, * In other words, one request may need to be received multiple times,
@ -793,7 +794,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal); mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal);
} }
int dataLength = aMessage->mSize - frameHeaderLength; int dataLength = aMessage->GetSize() - frameHeaderLength;
// Check length before memcpy to prevent from memory pollution // Check length before memcpy to prevent from memory pollution
if (dataLength < 0 || if (dataLength < 0 ||
@ -808,7 +809,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage)
} }
memcpy(mReceivedDataBuffer.get() + mPutPacketReceivedLength, memcpy(mReceivedDataBuffer.get() + mPutPacketReceivedLength,
&aMessage->mData[frameHeaderLength], dataLength); &data[frameHeaderLength], dataLength);
mPutPacketReceivedLength += dataLength; mPutPacketReceivedLength += dataLength;
@ -821,12 +822,13 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
uint8_t opCode; uint8_t opCode;
int receivedLength = aMessage->mSize; int receivedLength = aMessage->GetSize();
const uint8_t* data = aMessage->GetData();
if (mPutPacketReceivedLength > 0) { if (mPutPacketReceivedLength > 0) {
opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put; opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put;
} else { } else {
opCode = aMessage->mData[0]; opCode = data[0];
// When there's a Put packet right after a PutFinal packet, // When there's a Put packet right after a PutFinal packet,
// which means it's the start point of a new file. // which means it's the start point of a new file.
@ -843,7 +845,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
// Section 3.3.1 "Connect", IrOBEX 1.2 // Section 3.3.1 "Connect", IrOBEX 1.2
// [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2] // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2]
// [Headers:var] // [Headers:var]
if (!ParseHeaders(&aMessage->mData[7], receivedLength - 7, &pktHeaders)) { if (!ParseHeaders(&data[7], receivedLength - 7, &pktHeaders)) {
ReplyError(ObexResponseCode::BadRequest); ReplyError(ObexResponseCode::BadRequest);
return; return;
} }
@ -853,7 +855,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
} else if (opCode == ObexRequestCode::Abort) { } else if (opCode == ObexRequestCode::Abort) {
// Section 3.3.5 "Abort", IrOBEX 1.2 // Section 3.3.5 "Abort", IrOBEX 1.2
// [opcode:1][length:2][Headers:var] // [opcode:1][length:2][Headers:var]
if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
ReplyError(ObexResponseCode::BadRequest); ReplyError(ObexResponseCode::BadRequest);
return; return;
} }
@ -863,7 +865,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage)
} else if (opCode == ObexRequestCode::Disconnect) { } else if (opCode == ObexRequestCode::Disconnect) {
// Section 3.3.2 "Disconnect", IrOBEX 1.2 // Section 3.3.2 "Disconnect", IrOBEX 1.2
// [opcode:1][length:2][Headers:var] // [opcode:1][length:2][Headers:var]
if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) {
ReplyError(ObexResponseCode::BadRequest); ReplyError(ObexResponseCode::BadRequest);
return; return;
} }
@ -946,7 +948,8 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
uint8_t opCode = aMessage->mData[0]; const uint8_t* data = aMessage->GetData();
uint8_t opCode = data[0];
// Check response code and send out system message as finished if the response // Check response code and send out system message as finished if the response
// code is somehow incorrect. // code is somehow incorrect.
@ -1003,10 +1006,9 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage)
AfterOppConnected(); AfterOppConnected();
// Keep remote information // Keep remote information
mRemoteObexVersion = aMessage->mData[3]; mRemoteObexVersion = data[3];
mRemoteConnectionFlags = aMessage->mData[4]; mRemoteConnectionFlags = data[4];
mRemoteMaxPacketLength = mRemoteMaxPacketLength = (static_cast<int>(data[5]) << 8) | data[6];
(((int)(aMessage->mData[5]) << 8) | aMessage->mData[6]);
// The length of file name exceeds maximum length. // The length of file name exceeds maximum length.
int fileNameByteLen = (mFileName.Length() + 1) * 2; int fileNameByteLen = (mFileName.Length() + 1) * 2;
@ -1274,8 +1276,7 @@ BluetoothOppManager::SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize)
mLastCommand = aOpcode; mLastCommand = aOpcode;
} }
UnixSocketRawData* s = new UnixSocketRawData(aSize); UnixSocketRawData* s = new UnixSocketRawData(aData, aSize);
memcpy(s->mData, aData, s->mSize);
mSocket->SendSocketData(s); mSocket->SendSocketData(s);
} }