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

[CoreHttp] Add strncasecmp implementation #106

Merged
merged 34 commits into from
Jul 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c7efde6
corehttpclient.c changes
gshvang Jul 1, 2021
5480421
strncasecmp changes
gshvang Jul 7, 2021
f1c7490
strncasecmp changes
gshvang Jul 7, 2021
99615f2
Variable update
gshvang Jul 7, 2021
8a9e332
Semicolon add
gshvang Jul 7, 2021
97c6863
lexicon changes
gshvang Jul 7, 2021
66d7c15
lexicon changes
gshvang Jul 7, 2021
e10f61b
uncrustify changes
gshvang Jul 7, 2021
c7e92a7
uncrustify changes
gshvang Jul 7, 2021
ecd07b1
uncrustify changes
gshvang Jul 7, 2021
22f35b4
uncrustify changes
gshvang Jul 7, 2021
2b56551
uncrustify changes
gshvang Jul 7, 2021
584986d
Reverting commits
gshvang Jul 7, 2021
95bd091
cbmc changes
gshvang Jul 7, 2021
f6782ee
cbmc proof changes
gshvang Jul 8, 2021
15d12b5
unit test change
gshvang Jul 8, 2021
025c7e7
null changes
gshvang Jul 8, 2021
106f8cf
reverting unit tests
gshvang Jul 8, 2021
0b0834e
adding test case
gshvang Jul 8, 2021
78620e5
adding test case
gshvang Jul 8, 2021
f7097e6
removing 1unit test
gshvang Jul 8, 2021
3060639
reverting 1unit test
gshvang Jul 8, 2021
55d5f2e
Function changes
gshvang Jul 8, 2021
c7e98a8
memory statistics changes
gshvang Jul 8, 2021
56df57c
make file changes
gshvang Jul 8, 2021
bbfe466
review addressed
gshvang Jul 9, 2021
56c7a8e
review addressed
gshvang Jul 9, 2021
6ab1cf8
review addressed
gshvang Jul 9, 2021
7606f59
review addressed
gshvang Jul 9, 2021
ff5a393
review addressed
gshvang Jul 9, 2021
a8d3458
review addressed PRBR
gshvang Jul 9, 2021
b5d9ec2
reverting commit
gshvang Jul 9, 2021
7a32a38
Addressing Review comments
gshvang Jul 9, 2021
96c2af5
Addressing PRBR comments
gshvang Jul 10, 2021
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
8 changes: 4 additions & 4 deletions docs/doxygen/include/size_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</tr>
<tr>
<td>core_http_client.c</td>
<td><center>3.1K</center></td>
<td><center>2.5K</center></td>
<td><center>3.2K</center></td>
<td><center>2.6K</center></td>
</tr>
<tr>
<td>http_parser.c (http-parser)</td>
Expand All @@ -19,7 +19,7 @@
</tr>
<tr>
<td><b>Total estimates</b></td>
<td><b><center>18.8K</center></b></td>
<td><b><center>15.5K</center></b></td>
<td><b><center>18.9K</center></b></td>
<td><b><center>15.6K</center></b></td>
</tr>
</table>
1 change: 1 addition & 0 deletions lexicon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ sendflags
sendhttpbody
sendhttpheaders
sendpartialcall
sensitivity
sizeof
snprintf
statuscode
Expand Down
38 changes: 37 additions & 1 deletion source/core_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <assert.h>
#include <string.h>
#include <ctype.h>

#include "core_http_client.h"
#include "core_http_client_private.h"
Expand Down Expand Up @@ -544,6 +545,22 @@ static void processCompleteHeader( HTTPParsingContext_t * pParsingContext );
*/
static HTTPStatus_t processHttpParserError( const http_parser * pHttpParser );

/**
* @brief Compares at most the first n bytes of str1 and str2 without case sensitivity
* and n must be less than the actual size of either string.
*
* @param[in] str1 First string to be compared.
* @param[in] str2 Second string to be compared.
* @param[in] n The maximum number of characters to be compared.
*
* @return One of the following:
* 0 if str1 is equal to str2
* 1 if str1 is not equal to str2.
*/
static int8_t caseInsensitiveStringCmp( const char * str1,
const char * str2,
size_t n );

/*-----------------------------------------------------------*/

static uint32_t getZeroTimestampMs( void )
Expand All @@ -553,6 +570,25 @@ static uint32_t getZeroTimestampMs( void )

/*-----------------------------------------------------------*/

static int8_t caseInsensitiveStringCmp( const char * str1,
const char * str2,
size_t n )
{
size_t i = 0U;

for( i = 0U; i < n; i++ )
{
if( toupper( str1[ i ] ) != toupper( str2[ i ] ) )
gshvang marked this conversation as resolved.
Show resolved Hide resolved
{
break;
}
}

return ( i == n ) ? 0 : 1;
}

/*-----------------------------------------------------------*/

static void processCompleteHeader( HTTPParsingContext_t * pParsingContext )
{
HTTPResponse_t * pResponse = NULL;
Expand Down Expand Up @@ -2237,7 +2273,7 @@ static int findHeaderFieldParserCallback( http_parser * pHttpParser,
/* Check whether the parsed header matches the header we are looking for. */
/* Each header field consists of a case-insensitive field name (RFC 7230, section 3.2). */
if( ( fieldLen == pContext->fieldLen ) &&
( strncasecmp( pContext->pField, pFieldLoc, fieldLen ) == 0 ) )
( caseInsensitiveStringCmp( pContext->pField, pFieldLoc, fieldLen ) == 0 ) )
gshvang marked this conversation as resolved.
Show resolved Hide resolved
{
LogDebug( ( "Found header field in response: "
"HeaderName=%.*s, HeaderLocation=0x%p",
Expand Down
4 changes: 2 additions & 2 deletions test/cbmc/proofs/findHeaderFieldParserCallback/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ HARNESS_FILE=$(HARNESS_ENTRY)

# The header field length is bounded, so strncasecmp can be unwound to an expected
# amount that won't make the proof run too long.
MAX_HEADER_FIELD_LENGTH=10
MAX_HEADER_FIELD_LENGTH=11

DEFINES += -DMAX_HEADER_FIELD_LENGTH=$(MAX_HEADER_FIELD_LENGTH)
INCLUDES +=

REMOVE_FUNCTION_BODY +=
UNWINDSET += strncasecmp.0:$(MAX_HEADER_FIELD_LENGTH)
UNWINDSET += __CPROVER_file_local_core_http_client_c_caseInsensitiveStringCmp.0:$(MAX_HEADER_FIELD_LENGTH)

PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/http_cbmc_state.c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void findHeaderFieldParserCallback_harness()
pResponse->pBuffer != NULL &&
pResponse->bufferLen > 0 );

__CPROVER_assume( 0 < fieldLen && fieldLen <= MAX_HEADER_FIELD_LENGTH && fieldLen <= pResponse->bufferLen );
__CPROVER_assume( 0 < fieldLen && fieldLen < MAX_HEADER_FIELD_LENGTH && fieldLen <= pResponse->bufferLen );
__CPROVER_assume( fieldOffset <= pResponse->bufferLen - fieldLen );
pFieldLoc = pResponse->pBuffer + fieldOffset;

Expand Down