First version of disabling indefinite length array decoding
diff --git a/inc/qcbor/qcbor_common.h b/inc/qcbor/qcbor_common.h
index d9a0dbe..7f97aa0 100644
--- a/inc/qcbor/qcbor_common.h
+++ b/inc/qcbor/qcbor_common.h
@@ -472,6 +472,10 @@
indefinite length string in the input CBOR. */
QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED = 43,
+ /** Indefinite length arrays and maps handling are disabled and there is an
+ indefinite length map or array in the input CBOR. */
+ QCBOR_ERR_INDEF_LEN_ARRAYS_DISABLED = 44,
+
/* This is stored in uint8_t; never add values > 255 */
} QCBORError;
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 585a517..6e41c52 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -76,6 +76,7 @@
static inline bool
QCBORItem_IsIndefiniteLengthMapOrArray(const QCBORItem *pMe)
{
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
if(!QCBORItem_IsMapOrArray(pMe)){
return false;
}
@@ -84,6 +85,10 @@
return false;
}
return true;
+#else /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
+ (void)pMe;
+ return false;
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
}
@@ -157,15 +162,19 @@
// Not a map or array
return false;
}
+
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
if(pNesting->pCurrent->u.ma.uCountTotal == QCBOR_COUNT_INDICATES_INDEFINITE_LENGTH) {
// Is indefinite
return false;
}
+#endif
+
// All checks passed; is a definte length map or array
return true;
}
-
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
static inline bool
DecodeNesting_IsCurrentBstrWrapped(const QCBORDecodeNesting *pNesting)
{
@@ -175,6 +184,7 @@
}
return false;
}
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
static inline bool DecodeNesting_IsCurrentBounded(const QCBORDecodeNesting *pNesting)
@@ -998,7 +1008,12 @@
goto Done;
}
if(nAdditionalInfo == LEN_IS_INDEFINITE) {
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
pDecodedItem->val.uCount = QCBOR_COUNT_INDICATES_INDEFINITE_LENGTH;
+#else
+ nReturn = QCBOR_ERR_INDEF_LEN_ARRAYS_DISABLED;
+ break;
+#endif
} else {
// type conversion OK because of check above
pDecodedItem->val.uCount = (uint16_t)uNumber;
@@ -1399,6 +1414,7 @@
}
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
/*
See if next item is a CBOR break. If it is, it is consumed,
if not it is not consumed.
@@ -1424,6 +1440,7 @@
return QCBOR_SUCCESS;
}
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
/*
@@ -1447,8 +1464,10 @@
}
/* All of a definite length array was consumed; fall through to
ascend */
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
} else {
+
/* If not definite length, have to check for a CBOR break */
bool bIsBreak = false;
uReturn = NextIsBreak(&(pMe->InBuf), &bIsBreak);
@@ -1471,10 +1490,12 @@
uReturn = QCBOR_ERR_BAD_BREAK;
goto Done;
}
-
/* It was a break in an indefinite length map / array */
+
+#endif
}
+
/* All items in the map/array level have been consumed. */
/* But ascent in bounded mode is only by explicit call to
@@ -1496,7 +1517,10 @@
uReturn = QCBOR_SUCCESS;
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
Done:
+#endif /* #ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
+
return uReturn;
}