From bfb86f11401c3c4451f32c21c2294f313a136349 Mon Sep 17 00:00:00 2001 From: Kishen Maloor Date: Sun, 14 Aug 2016 18:22:10 -0700 Subject: [PATCH] Fix for IOT-1214: Incorrect use of tinyCBOR API in security code mapSize is consistently larger than the actual size of doxmMap. This results in an erroneous parse of the resulting payload wherein the last key-value pair is truncated. When creating containers, we must specify CborIndefiniteLength unless we know the exact length the container. Change-Id: I8beb6bc45ae41531e8a7528d9dbd254a27e14be9 Signed-off-by: Kishen Maloor Reviewed-on: https://gerrit.iotivity.org/gerrit/10455 Tested-by: jenkins-iotivity Reviewed-by: Thiago Macieira Reviewed-by: Dave Thaler Reviewed-by: Randeep Singh Reviewed-by: Jaehong Jo Reviewed-by: Phil Coval Reviewed-by: Kevin Kane Reviewed-by: Ziran Sun (cherry picked from commit a909e871afe8a9ea7e0a779302e4d47dac74649d) Reviewed-on: https://gerrit.iotivity.org/gerrit/11711 Reviewed-by: David Antler --- resource/csdk/security/src/doxmresource.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/resource/csdk/security/src/doxmresource.c b/resource/csdk/security/src/doxmresource.c index 60c2949..75a726c 100644 --- a/resource/csdk/security/src/doxmresource.c +++ b/resource/csdk/security/src/doxmresource.c @@ -60,9 +60,6 @@ static const uint16_t CBOR_SIZE = 512; /** Max cbor size payload. */ static const uint16_t CBOR_MAX_SIZE = 4400; -/** DOXM Map size - Number of mandatory items. */ -static const uint8_t DOXM_MAP_SIZE = 9; - static OicSecDoxm_t *gDoxm = NULL; static OCResourceHandle gDoxmHandle = NULL; @@ -131,21 +128,12 @@ OCStackResult DoxmToCBORPayload(const OicSecDoxm_t *doxm, uint8_t **payload, siz char* strUuid = NULL; int64_t cborEncoderResult = CborNoError; - uint8_t mapSize = DOXM_MAP_SIZE; - if (doxm->oxmTypeLen > 0) - { - mapSize++; - } - if (doxm->oxmLen > 0) - { - mapSize++; - } uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen); VERIFY_NON_NULL(TAG, outPayload, ERROR); cbor_encoder_init(&encoder, outPayload, cborLen, 0); - cborEncoderResult = cbor_encoder_create_map(&encoder, &doxmMap, mapSize); + cborEncoderResult = cbor_encoder_create_map(&encoder, &doxmMap, CborIndefiniteLength); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Doxm Map."); //OxmType -- Not Mandatory -- 2.7.4