Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MISRA Compliance Update #142

Merged
merged 2 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions source/core_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,8 @@ static HTTPStatus_t addHeader( HTTPRequestHeaders_t * pRequestHeaders,
size_t toAddLen = 0U;
size_t backtrackHeaderLen = 0U;

/* These variables are here to pass into memcpy for MISRA compliance */
/* Directly passing in these strings to memcpy is a MISRA Rule 7.4 violation
* Due to this we allocate these pointers for MISRA compliance */
const char * pHeaderEndIndicator = HTTP_HEADER_END_INDICATOR;
const char * httpFieldSeparator = HTTP_HEADER_FIELD_SEPARATOR;

Expand Down Expand Up @@ -1410,6 +1411,11 @@ static HTTPStatus_t addRangeHeader( HTTPRequestHeaders_t * pRequestHeaders,
char rangeValueBuffer[ HTTP_MAX_RANGE_REQUEST_VALUE_LEN ];
size_t rangeValueLength = 0U;

/* Directly passing in these strings to memcpy is a MISRA Rule 7.4 violation
* Due to this we allocate these pointers for MISRA compliance */
paulbartell marked this conversation as resolved.
Show resolved Hide resolved
const char * pHttpRangeRequestHeaderValuePrefix = HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX;
const char * pHttpRangeRequestHeaderField = HTTP_RANGE_REQUEST_HEADER_FIELD;

assert( pRequestHeaders != NULL );

/* This buffer uses a char type instead of the general purpose uint8_t
Expand All @@ -1421,7 +1427,7 @@ static HTTPStatus_t addRangeHeader( HTTPRequestHeaders_t * pRequestHeaders,

/* Write the range value prefix in the buffer. */
( void ) memcpy( rangeValueBuffer,
HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX,
pHttpRangeRequestHeaderValuePrefix,
HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN );
rangeValueLength += HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN;

Expand Down Expand Up @@ -1458,7 +1464,7 @@ static HTTPStatus_t addRangeHeader( HTTPRequestHeaders_t * pRequestHeaders,

/* Add the Range Request header field and value to the buffer. */
returnStatus = addHeader( pRequestHeaders,
HTTP_RANGE_REQUEST_HEADER_FIELD,
pHttpRangeRequestHeaderField,
HTTP_RANGE_REQUEST_HEADER_FIELD_LEN,
rangeValueBuffer,
rangeValueLength );
Expand All @@ -1478,8 +1484,11 @@ static HTTPStatus_t writeRequestLine( HTTPRequestHeaders_t * pRequestHeaders,
char * pBufferCur = NULL;
size_t toAddLen = 0U;

/* This variable is here to pass into memcpy for MISRA compliance */
/* Directly passing in these strings to memcpy is a MISRA Rule 7.4 violation
* Due to this we allocate these pointers for MISRA compliance */
const char * pHeaderLineSeparator = HTTP_HEADER_LINE_SEPARATOR;
const char * pHttpProtocolVersion = HTTP_PROTOCOL_VERSION;
const char * pHttpEmptyPath = HTTP_EMPTY_PATH;

assert( pRequestHeaders != NULL );
assert( pRequestHeaders->pBuffer != NULL );
Expand Down Expand Up @@ -1513,7 +1522,7 @@ static HTTPStatus_t writeRequestLine( HTTPRequestHeaders_t * pRequestHeaders,
if( ( pPath == NULL ) || ( pathLen == 0U ) )
{
( void ) memcpy( pBufferCur,
HTTP_EMPTY_PATH,
pHttpEmptyPath,
HTTP_EMPTY_PATH_LEN );
pBufferCur += HTTP_EMPTY_PATH_LEN;
}
Expand All @@ -1527,7 +1536,7 @@ static HTTPStatus_t writeRequestLine( HTTPRequestHeaders_t * pRequestHeaders,
pBufferCur += SPACE_CHARACTER_LEN;

( void ) memcpy( pBufferCur,
HTTP_PROTOCOL_VERSION,
pHttpProtocolVersion,
HTTP_PROTOCOL_VERSION_LEN );
pBufferCur += HTTP_PROTOCOL_VERSION_LEN;
( void ) memcpy( pBufferCur,
Expand Down
12 changes: 6 additions & 6 deletions source/include/core_http_client_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ typedef enum HTTPParsingState_t
*/
typedef struct findHeaderContext
{
const char * pField; /**< The field that is being searched for. */
size_t fieldLen; /**< The length of pField. */
const char ** pValueLoc; /**< The location of the value found in the buffer. */
size_t * pValueLen; /**< the length of the value found. */
uint8_t fieldFound; /**< Indicates that the header field was found during parsing. */
uint8_t valueFound; /**< Indicates that the header value was found during parsing. */
const unsigned char * pField; /**< The field that is being searched for. */
paulbartell marked this conversation as resolved.
Show resolved Hide resolved
size_t fieldLen; /**< The length of pField. */
const char ** pValueLoc; /**< The location of the value found in the buffer. */
size_t * pValueLen; /**< the length of the value found. */
uint8_t fieldFound; /**< Indicates that the header field was found during parsing. */
uint8_t valueFound; /**< Indicates that the header value was found during parsing. */
} findHeaderContext_t;

/**
Expand Down