Skip to content

Commit

Permalink
Fix CBMC proof of Send function
Browse files Browse the repository at this point in the history
  • Loading branch information
AniruddhaKanhere committed Jan 19, 2024
1 parent 4324547 commit c6b8308
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source/core_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -2099,11 +2099,11 @@ HTTPStatus_t HTTPClient_ReceiveAndParseHttpResponse( const TransportInterface_t
( totalReceived < pResponse->bufferLen ) ) ? 1U : 0U;
}

if( ( returnStatus == HTTPParserPaused ) && pResponse->respOptionFlags & HTTP_RESPONSE_DO_NOT_PARSE_BODY_FLAG )
if( ( returnStatus == HTTPParserPaused ) && ( pResponse->respOptionFlags & HTTP_RESPONSE_DO_NOT_PARSE_BODY_FLAG ) )
{
returnStatus = HTTPSuccess;
/* There may be dangling data if we parse with do not parse body flag. To let libraries built on top of corehttp we expose it through body. */
pResponse->bodyLen = totalReceived - ( ( uint8_t * ) pResponse->pBody - pResponse->pBuffer );
pResponse->bodyLen = totalReceived - ( size_t )( ( ( uintptr_t ) pResponse->pBody ) - ( ( uintptr_t ) pResponse->pBuffer ) );
}

if( returnStatus == HTTPSuccess )
Expand Down
17 changes: 17 additions & 0 deletions test/cbmc/stubs/HTTPClient_Send_llhttp_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,22 @@ llhttp_errno_t llhttp_execute( llhttp_t * parser,
pParsingContext->lastHeaderValueLen = 0U;
}

/* The body pointer is set by the httpParserOnBodyCallback. But since we are
* removing that from CBMC proof execution, the body has to be set here. */
size_t bodyOffset;

if( pParsingContext->pResponse->bufferLen == 0 )
{
bodyOffset = 0;
}
else
{
/* Body offset can be anything as long as it doesn't exceed the buffer length
* and the length of the current data packet. */
__CPROVER_assume( bodyOffset < pParsingContext->pResponse->bufferLen );
__CPROVER_assume( bodyOffset < len );
}
pParsingContext->pResponse->pBody = pParsingContext->pBufferCur + bodyOffset;

return parser->error;
}

0 comments on commit c6b8308

Please sign in to comment.