Better error for QCBORDecode_EnterBstrWrapped on allocated (indef) strings
diff --git a/inc/qcbor/qcbor_common.h b/inc/qcbor/qcbor_common.h
index b58a332..411308e 100644
--- a/inc/qcbor/qcbor_common.h
+++ b/inc/qcbor/qcbor_common.h
@@ -523,6 +523,11 @@
* (to save object code). */
QCBOR_ERR_RECOVERABLE_BAD_TAG_CONTENT = 78,
+ /** QCBORDecode_EnterBstrWrapped() cannot be used on
+ * indefinite-length strings because they exist in memory pool for
+ * a @ref QCBORStringAllocate. */
+ QCBOR_ERR_CANNOT_ENTER_ALLOCATED_STRING = 79,
+
/** A range of error codes that can be made use of by the
* caller. QCBOR internally does nothing with these except notice
* that they are not QCBOR_SUCCESS. See QCBORDecode_SetError(). */
diff --git a/inc/qcbor/qcbor_spiffy_decode.h b/inc/qcbor/qcbor_spiffy_decode.h
index 84fb516..31154a4 100644
--- a/inc/qcbor/qcbor_spiffy_decode.h
+++ b/inc/qcbor/qcbor_spiffy_decode.h
@@ -1783,8 +1783,8 @@
* CBOR. QCBORDecode_ExitBstrWrapped() must be called to resume
* processing CBOR outside the wrapped CBOR.
*
- * This does not (currently) work on indefinite-length strings. The
- * (confusing) error @ref QCBOR_ERR_INPUT_TOO_LARGE will be set.
+ * This does not work on indefinite-length strings. The
+ * error @ref QCBOR_ERR_CANNOT_ENTER_ALLOCATED_STRING will be set.
*
* If @c pBstr is not @c NULL the pointer and length of the wrapped
* CBOR will be returned. This is usually not needed, but sometimes
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 2188211..bf80526 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -4106,6 +4106,11 @@
return;
}
+ if(Item.uDataAlloc) {
+ pMe->uLastError = QCBOR_ERR_CANNOT_ENTER_ALLOCATED_STRING;
+ return;
+ }
+
pMe->uLastError = (uint8_t)QCBORDecode_Private_EnterBstrWrapped(pMe,
&Item,
uTagRequirement,
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 16ab10f..326421e 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -8631,16 +8631,14 @@
QCBORDecode_EnterArray(&DCtx, NULL);
QCBORDecode_EnterBstrWrapped(&DCtx, 2, NULL);
- if(QCBORDecode_GetError(&DCtx) != QCBOR_ERR_INPUT_TOO_LARGE) {
- /* TODO: This is what happens when trying to enter
- * indefinite-length byte string wrapped CBOR. Tolerate for
- * now. Eventually it needs to be fixed so this works, but that
- * is not simple.
- */
+ if(QCBORDecode_GetError(&DCtx) != QCBOR_ERR_CANNOT_ENTER_ALLOCATED_STRING) {
return 7300;
}
/*
+ Improvement: Fix QCBORDecode_EnterBstrWrapped() so it can work on
+ allocated strings. This is a fairly big job because of all the
+ UsefulBuf internal book keeping that needs tweaking.
QCBORDecode_GetUInt64(&DCtx, &i);
if(i != 42) {
return 7110;
@@ -8649,7 +8647,8 @@
QCBORDecode_GetUInt64(&DCtx, &i);
if(i != 42) {
return 7220;
- }*/
+ }
+ */
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */