From 9667cb9034a52fafcbde523e585ae4b1fe6ad4a9 Mon Sep 17 00:00:00 2001 From: Soren Ptak Date: Thu, 18 Aug 2022 21:07:24 +0000 Subject: [PATCH 1/2] A different PR added in 3 new MISRA violations, the changes in core_http_client.c remove those violations. Swapping pField from a const char * to a const unsigned char * to fix a compilation error. --- source/core_http_client.c | 21 +++++++++++++++------ source/include/core_http_client_private.h | 12 ++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/source/core_http_client.c b/source/core_http_client.c index 459f3789..68855f24 100644 --- a/source/core_http_client.c +++ b/source/core_http_client.c @@ -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 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; @@ -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 violation + * Due to this we allocate these pointers for MISRA compliance */ + 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 @@ -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; @@ -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 ); @@ -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 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 ); @@ -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; } @@ -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, diff --git a/source/include/core_http_client_private.h b/source/include/core_http_client_private.h index b2b146da..777f99da 100644 --- a/source/include/core_http_client_private.h +++ b/source/include/core_http_client_private.h @@ -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. */ + 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; /** From b8a96efa83ec0bbb9fe205909a24a261b1952460 Mon Sep 17 00:00:00 2001 From: Soren Ptak Date: Thu, 18 Aug 2022 21:29:28 +0000 Subject: [PATCH 2/2] Stating the rule we are addressing in a comment --- source/core_http_client.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/core_http_client.c b/source/core_http_client.c index 68855f24..99cc545d 100644 --- a/source/core_http_client.c +++ b/source/core_http_client.c @@ -1314,7 +1314,7 @@ static HTTPStatus_t addHeader( HTTPRequestHeaders_t * pRequestHeaders, size_t toAddLen = 0U; size_t backtrackHeaderLen = 0U; - /* Directly passing in these strings to memcpy is a MISRA violation + /* 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; @@ -1411,7 +1411,7 @@ 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 violation + /* 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 * pHttpRangeRequestHeaderValuePrefix = HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX; const char * pHttpRangeRequestHeaderField = HTTP_RANGE_REQUEST_HEADER_FIELD; @@ -1484,7 +1484,7 @@ static HTTPStatus_t writeRequestLine( HTTPRequestHeaders_t * pRequestHeaders, char * pBufferCur = NULL; size_t toAddLen = 0U; - /* Directly passing in these strings to memcpy is a MISRA violation + /* 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;