Modifications to resolve issues found during self-code review.

This commit is contained in:
Juan Carlos Luciani
2006-12-08 05:45:03 +00:00
parent 9a0426279c
commit 8ade751650
34 changed files with 524 additions and 268 deletions

View File

@@ -68,7 +68,7 @@ ChannelProto::buildReqDataPktHdr(
//
// Abstract:
//
// Notes:
// Notes: pPktHdr must point to a buffer of size ReqDataPktHdrTemple.length().
//
// L2
//=======================================================================--
@@ -81,16 +81,16 @@ ChannelProto::buildReqDataPktHdr(
// - Req Data Packet Header Format -
//
// ReqDataCarrierType
// ReqIdHdr value (value format=%0X)
// PayloadLengthHdr value (value format=%0X)
// ReqIdHdr value (value format=%08X)
// PayloadLengthHdr value (value format=%08X)
//
// Setup the necessary value strings
char wrkBuffer[10];
sprintf(wrkBuffer, "%0X", reqId);
sprintf(wrkBuffer, "%08X", reqId);
string reqIdValue = wrkBuffer;
sprintf(wrkBuffer, "%0X", payloadLength);
sprintf(wrkBuffer, "%08X", payloadLength);
string payloadLengthValue = wrkBuffer;
// Format the header.
@@ -141,7 +141,7 @@ ChannelProto::buildReqErrorPktHdr(
//
// Abstract:
//
// Notes:
// Notes: pPktHdr must point to a buffer of size ReqErrorPktHdrTemple.length().
//
// L2
//=======================================================================--
@@ -154,16 +154,16 @@ ChannelProto::buildReqErrorPktHdr(
// - Req Error Packet Header Format -
//
// ReqErrorCarrierType
// ReqIdHdr value (value format=%0X)
// PayloadLengthHdr value (value format=%0X)
// ReqIdHdr value (value format=%08X)
// PayloadLengthHdr value (value format=%08X)
//
// Setup the necessary value strings
char wrkBuffer[10];
sprintf(wrkBuffer, "%0X", reqId);
sprintf(wrkBuffer, "%08X", reqId);
string reqIdValue = wrkBuffer;
sprintf(wrkBuffer, "%0X", payloadLength);
sprintf(wrkBuffer, "%08X", payloadLength);
string payloadLengthValue = wrkBuffer;
// Format the header.
@@ -204,7 +204,8 @@ ChannelProto::buildReqErrorPktHdr(
//++=======================================================================
ChannelProto::PacketTypes
ChannelProto::getPktType(
char &buff)
char &buff,
int hdrLength)
//
// Arguments:
//
@@ -223,29 +224,47 @@ ChannelProto::getPktType(
// Find the end of the Channel Packet Type
char *pCurr = &buff;
while (*pCurr != '\r')
int bytesLeft = hdrLength;
bool endFound = false;
while (bytesLeft)
{
if (*pCurr == '\r')
{
endFound = true;
break;
}
pCurr ++;
// Found the end of the Channel Packet Type, now
// calculate its length.
int channelPktTypeLength = pCurr - &buff;
// Now start comparing
if (channelPktTypeLength == ReqDataCarrierType.length()
&& !memcmp(&buff, ReqDataCarrierType.c_str(), channelPktTypeLength))
{
// The type is Channel Req Data Carrier
packetType = ReqDataCarrierPacketType;
bytesLeft --;
}
else if (channelPktTypeLength == ReqErrorCarrierType.length()
&& !memcmp(&buff, ReqErrorCarrierType.c_str(), channelPktTypeLength))
if (endFound)
{
// The type is Channel Req Error Carrier
packetType = ReqErrorCarrierPacketType;
// Found the end of the Channel Packet Type, now
// calculate its length.
int channelPktTypeLength = pCurr - &buff;
// Now start comparing
if (channelPktTypeLength == ReqDataCarrierType.length()
&& !memcmp(&buff, ReqDataCarrierType.c_str(), channelPktTypeLength))
{
// The type is Channel Req Data Carrier
packetType = ReqDataCarrierPacketType;
}
else if (channelPktTypeLength == ReqErrorCarrierType.length()
&& !memcmp(&buff, ReqErrorCarrierType.c_str(), channelPktTypeLength))
{
// The type is Channel Req Error Carrier
packetType = ReqErrorCarrierPacketType;
}
else
{
DbgTrace(0, "ChannelProto::getPktType- No match found\n", 0);
}
}
else
{
DbgTrace(0, "ChannelProto::getPktType- No match found\n", 0);
DbgTrace(0, "ChannelProto::getPktType- Invalid header\n", 0);
}
DbgTrace(1, "ChannelProto::getPktType- End, type = %d\n", packetType);
@@ -283,7 +302,8 @@ ChannelProto::getReqIdAndPayloadLength(
char *pChannelHdr = NULL;
int bytesLeft = hdrLength;
// Skip the Channel Packet Type
// Skip the Channel Packet Type which should always
// be the first header.
while (bytesLeft >= 2)
{
if (*pCurr == '\r'
@@ -334,7 +354,17 @@ ChannelProto::getReqIdAndPayloadLength(
*(pCurr-2) = '\0';
// Convert the value to hex
*pReqId = strtoul(pValue, NULL, 16);
errno = 0;
unsigned long int value = strtoul(pValue, NULL, 16);
if (errno != 0
|| value > UINT32_MAX)
{
DbgTrace(0, "ChannelProto::getReqIdAndPayloadLength- Invalid reqId value, %s\n", pValue);
break;
}
// Use the value
*pReqId = (uint32_t) value;
// Undo the damage that we did
*(pCurr-2) = '\r';
@@ -353,7 +383,17 @@ ChannelProto::getReqIdAndPayloadLength(
*(pCurr-2) = '\0';
// Convert the value to hex
*pPayloadLength = strtoul(pValue, NULL, 16);
errno = 0;
long int value = strtol(pValue, NULL, 16);
if (errno != 0
|| value > INT32_MAX)
{
DbgTrace(0, "ChannelProto::getReqIdAndPayloadLength- Invalid payloadLength value, %s\n", pValue);
break;
}
// Use the value
*pPayloadLength = (int32_t) value;
// Undo the damage that we did
*(pCurr-2) = '\r';

View File

@@ -113,12 +113,16 @@ public:
// Parameters:
// buff (input) -
// Reference to buffer containing the packet data.
//
// hdrLength (input) -
// Length of the channel header.
//
// Abstract: Returns the type of the specified channel packet.
//
// Returns: Channel packet type.
//
static PacketTypes getPktType(char &buff);
static PacketTypes getPktType(char &buff,
int hdrLength);
//
// Get Req Id and Payload Length Values routine