fix allocate all bug introduced early in PR
diff --git a/inc/qcbor/qcbor_common.h b/inc/qcbor/qcbor_common.h
index 195b418..752d149 100644
--- a/inc/qcbor/qcbor_common.h
+++ b/inc/qcbor/qcbor_common.h
@@ -31,6 +31,7 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ========================================================================= */
+
#ifndef qcbor_common_h
#define qcbor_common_h
diff --git a/inc/qcbor/qcbor_decode.h b/inc/qcbor/qcbor_decode.h
index 98a76eb..14b8f15 100644
--- a/inc/qcbor/qcbor_decode.h
+++ b/inc/qcbor/qcbor_decode.h
@@ -510,6 +510,7 @@
} val;
+ /** Union holding the different label types selected based on @c uLabelType */
union {
/** The label for @c uLabelType for @ref QCBOR_TYPE_INT64 */
int64_t int64;
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 9c5d2d2..7b8ce5c 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -982,18 +982,18 @@
goto Done;
}
+ if(bAllocate) {
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
- if(bAllocate) {
- /* --- Put string in allocated memory --- */
+ /* --- Put string in allocated memory --- */
- /* Note that this is not where allocation to coalesce
- * indefinite-length strings is done. This is for when the
- * caller has requested all strings be allocated. Disabling
- * indefinite length strings also disables this allocate-all
- * option.
- */
+ /* Note that this is not where allocation to coalesce
+ * indefinite-length strings is done. This is for when the
+ * caller has requested all strings be allocated. Disabling
+ * indefinite length strings also disables this allocate-all
+ * option.
+ */
- if(pMe->StringAllocator.pfAllocator == NULL) {
+ if(pMe->StringAllocator.pfAllocator == NULL) {
uReturn = QCBOR_ERR_NO_STRING_ALLOCATOR;
goto Done;
}
@@ -1004,14 +1004,13 @@
}
pDecodedItem->val.string = UsefulBuf_Copy(NewMem, Bytes);
pDecodedItem->uDataAlloc = 1;
- goto Done;
- }
#else
- (void)bAllocate;
-#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
-
- /* --- Normal case with no string allocator --- */
- pDecodedItem->val.string = Bytes;
+ uReturn = QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED;
+#endif /* ! QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
+ } else {
+ /* --- Normal case with no string allocator --- */
+ pDecodedItem->val.string = Bytes;
+ }
}
Done:
@@ -1074,7 +1073,7 @@
pDecodedItem->val.uCount = QCBOR_COUNT_INDICATES_INDEFINITE_LENGTH;
#else /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
uReturn = QCBOR_ERR_INDEF_LEN_ARRAYS_DISABLED;
-#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
+#endif /* ! QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
} else {
#ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
@@ -1315,7 +1314,7 @@
* @retval QCBOR_ERR_ARRAY_DECODE_TOO_LONG Too many items in array/map.
* @retval QCBOR_ERR_TAGS_DISABLED QCBOR_DISABLE_TAGS is defined.
*
- * This decodes the most primitive / atomic data item. It does no
+ * This decodes the most primitive/atomic data item. It does no
* combining of data items.
*/
static QCBORError
@@ -1329,7 +1328,7 @@
int nAdditionalInfo = 0;
/* Decode the "head" that every CBOR item has into the major type,
- * length and the additional info.
+ * argument and the additional info.
*/
uReturn = QCBOR_Private_DecodeHead(&(pMe->InBuf), &nMajorType, &uArgument, &nAdditionalInfo);
if(uReturn != QCBOR_SUCCESS) {
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 45e4eab..ea4d6ce 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -5324,7 +5324,9 @@
Item1.val.int64 != 42 ||
Item1.uDataAlloc != 0 ||
Item1.uLabelAlloc == 0 ||
- UsefulBufCompareToSZ(Item1.label.string, "first integer")) {
+ UsefulBufCompareToSZ(Item1.label.string, "first integer") ||
+ Item1.label.string.ptr < Pool.ptr ||
+ Item1.label.string.ptr > (const void *)((const uint8_t *)Pool.ptr + Pool.len)) {
return -4;
}