Fix for IOT-1214: Incorrect use of tinyCBOR API in security code
authorKishen Maloor <kishen.maloor@intel.com>
Mon, 15 Aug 2016 01:22:10 +0000 (18:22 -0700)
committerRandeep Singh <randeep.s@samsung.com>
Mon, 26 Sep 2016 10:28:21 +0000 (10:28 +0000)
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 <kishen.maloor@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10455
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Dave Thaler <dthaler@microsoft.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: Kevin Kane <kkane@microsoft.com>
Reviewed-by: Ziran Sun <ziran.sun@samsung.com>
(cherry picked from commit a909e871afe8a9ea7e0a779302e4d47dac74649d)
Reviewed-on: https://gerrit.iotivity.org/gerrit/11711
Reviewed-by: David Antler <david.a.antler@intel.com>
resource/csdk/security/src/doxmresource.c

index 60c2949..75a726c 100644 (file)
@@ -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