Skip to content

Commit 8ec72d6

Browse files
DakshitBabbarDakshitBabbaraggarg
authored
Add CBMC Proofs for the new APIs (#315)
Description ----------- This PR: Adds CBMC proofs for the new APIs added for publish retransmits in #308 Test Steps ----------- Proofs run without any errors or warnings Checklist: ---------- - [x] I have tested my changes. No regression in existing tests. - [x] I have modified and/or added unit-tests to cover the code changes in this Pull Request. Related Issue ----------- <!-- If any, please provide issue ID. --> By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. --------- Co-authored-by: DakshitBabbar <dakshba@amazon.com> Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
1 parent 86a5750 commit 8ec72d6

File tree

14 files changed

+303
-15
lines changed

14 files changed

+303
-15
lines changed

source/include/core_mqtt.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ const char * MQTT_Status_strerror( MQTTStatus_t status );
12281228
/**
12291229
* @brief Get the bytes in a #MQTTVec pointer which can store the whole array as a an MQTT packet when calling MQTT_SerializeMQTTVec( void * pAllocatedMem, MQTTVec_t *pVec ) function.
12301230
*
1231-
* @param[in] pVec The #MQTTVec pointer.
1231+
* @param[in] pVec The #MQTTVec pointer given as input to the user defined #MQTTStorePacketForRetransmit callback function. Must not be NULL.
12321232
*
12331233
* @return The bytes in the provided #MQTTVec array which can then be used to set aside memory to be used with MQTT_SerializeMQTTVec( void * pAllocatedMem, MQTTVec_t *pVec ) function.
12341234
*/
@@ -1239,8 +1239,8 @@ size_t MQTT_GetBytesInMQTTVec( const MQTTVec_t * pVec );
12391239
/**
12401240
* @brief Serialize the bytes in an array of #MQTTVec in the provided \p pAllocatedMem
12411241
*
1242-
* @param[in] pAllocatedMem Memory in which to serialize the data in the #MQTTVec array. It must be of size provided by MQTT_GetBytesInMQTTVec( MQTTVec_t *pVec ).
1243-
* @param[in] pVec The #MQTTVec pointer.
1242+
* @param[in] pAllocatedMem Memory in which to serialize the data in the #MQTTVec array. It must be of size provided by MQTT_GetBytesInMQTTVec( MQTTVec_t *pVec ). Should not be NULL.
1243+
* @param[in] pVec The #MQTTVec pointer given as input to the user defined #MQTTStorePacketForRetransmit callback function. Must not be NULL.
12441244
*/
12451245
/* @[declare_mqtt_serializemqttvec] */
12461246
void MQTT_SerializeMQTTVec( uint8_t * pAllocatedMem,

test/cbmc/include/mqtt_cbmc_state.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,13 @@ MQTTContext_t * allocateMqttContext( MQTTContext_t * pContext );
165165
*/
166166
bool isValidMqttContext( const MQTTContext_t * pContext );
167167

168+
/**
169+
* @brief Allocate a #MQTTVec_t object.
170+
*
171+
* @param[in] mqttVec #MQTTVec_t object information.
172+
*
173+
* @return NULL or allocated #MQTTContext_t memory.
174+
*/
175+
MQTTVec_t * allocateMqttVec( MQTTVec_t * mqttVec );
176+
168177
#endif /* ifndef MQTT_CBMC_STATE_H_ */
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* coreMQTT <DEVELOPMENT BRANCH>
3+
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* SPDX-License-Identifier: MIT
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
8+
* this software and associated documentation files (the "Software"), to deal in
9+
* the Software without restriction, including without limitation the rights to
10+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11+
* the Software, and to permit persons to whom the Software is furnished to do so,
12+
* subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*/
24+
25+
/**
26+
* @file MQTT_Disconnect_harness.c
27+
* @brief Implements the proof harness for MQTT_Disconnect function.
28+
*/
29+
#include "core_mqtt.h"
30+
#include "mqtt_cbmc_state.h"
31+
32+
void harness()
33+
{
34+
MQTTVec_t * mqttVec;
35+
size_t memoryRequired;
36+
37+
mqttVec = allocateMqttVec( NULL );
38+
39+
memoryRequired = MQTT_GetBytesInMQTTVec( mqttVec );
40+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#
2+
# Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
# this software and associated documentation files (the "Software"), to deal in
6+
# the Software without restriction, including without limitation the rights to
7+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
# the Software, and to permit persons to whom the Software is furnished to do so,
9+
# subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in all
12+
# copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
#
21+
22+
HARNESS_ENTRY=harness
23+
HARNESS_FILE=MQTT_GetBytesInMQTTVec_harness
24+
PROOF_UID=MQTT_GetBytesInMQTTVec
25+
26+
PUBLISH_PACKET_VECTORS = 5
27+
28+
DEFINES +=
29+
INCLUDES +=
30+
31+
REMOVE_FUNCTION_BODY +=
32+
UNWINDSET += MQTT_GetBytesInMQTTVec.0:${PUBLISH_PACKET_VECTORS}
33+
UNWINDSET += allocateMqttVec.0:${PUBLISH_PACKET_VECTORS}
34+
35+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
36+
PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c
37+
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c
38+
39+
include ../Makefile.common
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
MQTT_GetBytesInMQTTVec proof
2+
==============
3+
4+
This directory contains a memory safety proof for MQTT_GetBytesInMQTTVec.
5+
6+
To run the proof.
7+
* Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer
8+
to your path.
9+
* Run "make".
10+
* Open html/index.html in a web browser.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This file marks this directory as containing a CBMC proof.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{ "expected-missing-functions":
2+
[
3+
4+
],
5+
"proof-name": "MQTT_GetBytesInMQTTVec",
6+
"proof-root": "test/cbmc/proofs"
7+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* coreMQTT <DEVELOPMENT BRANCH>
3+
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* SPDX-License-Identifier: MIT
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
8+
* this software and associated documentation files (the "Software"), to deal in
9+
* the Software without restriction, including without limitation the rights to
10+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11+
* the Software, and to permit persons to whom the Software is furnished to do so,
12+
* subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*/
24+
25+
/**
26+
* @file MQTT_Disconnect_harness.c
27+
* @brief Implements the proof harness for MQTT_Disconnect function.
28+
*/
29+
#include "core_mqtt.h"
30+
#include "mqtt_cbmc_state.h"
31+
32+
void harness()
33+
{
34+
MQTTVec_t * mqttVec;
35+
size_t memoryRequired;
36+
uint8_t * memoryBuffer;
37+
38+
mqttVec = allocateMqttVec( NULL );
39+
40+
memoryRequired = MQTT_GetBytesInMQTTVec( mqttVec );
41+
42+
/* It is a part of the API contract that #MQTT_SerializeMQTTVec will be called with
43+
* a memory buffer of size output by #MQTT_GetBytesInMQTTVec function and the
44+
* #MQTTVec_t pointer given by the library as an input to the user defined
45+
* #MQTTStorePacketForRetransmit callback function. Hence the memory buffer must
46+
* not be NULL.
47+
*/
48+
memoryBuffer = malloc( memoryRequired );
49+
__CPROVER_assume( memoryBuffer != NULL );
50+
51+
MQTT_SerializeMQTTVec( memoryBuffer, mqttVec );
52+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#
2+
# Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
# this software and associated documentation files (the "Software"), to deal in
6+
# the Software without restriction, including without limitation the rights to
7+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
# the Software, and to permit persons to whom the Software is furnished to do so,
9+
# subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in all
12+
# copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
#
21+
22+
HARNESS_ENTRY=harness
23+
HARNESS_FILE=MQTT_SerializeMQTTVec_harness
24+
PROOF_UID=MQTT_SerializeMQTTVec
25+
26+
PUBLISH_PACKET_VECTORS = 5
27+
28+
DEFINES +=
29+
INCLUDES +=
30+
31+
REMOVE_FUNCTION_BODY +=
32+
UNWINDSET += MQTT_GetBytesInMQTTVec.0:${PUBLISH_PACKET_VECTORS}
33+
UNWINDSET += allocateMqttVec.0:${PUBLISH_PACKET_VECTORS}
34+
UNWINDSET += MQTT_SerializeMQTTVec.0:${PUBLISH_PACKET_VECTORS}
35+
36+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
37+
PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c
38+
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c
39+
40+
include ../Makefile.common
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
MQTT_SerializeMQTTVec proof
2+
==============
3+
4+
This directory contains a memory safety proof for MQTT_SerializeMQTTVec.
5+
6+
To run the proof.
7+
* Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer
8+
to your path.
9+
* Run "make".
10+
* Open html/index.html in a web browser.

0 commit comments

Comments
 (0)