Skip to content

Commit 4cee345

Browse files
laurencelundbladeLaurence Lundblade
andauthored
EnterBstr() error handling bug (#299)
Co-authored-by: Laurence Lundblade <[email protected]>
1 parent bb98796 commit 4cee345

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/qcbor_tag_decode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ QCBORDecode_Private_EnterBstrWrapped(QCBORDecodeContext *pMe,
632632
&bTypeMatched);
633633

634634
if(pItem->uDataType != QCBOR_TYPE_BYTE_STRING) {
635-
uError = QCBOR_ERR_BAD_TAG_CONTENT; // TODO: error
635+
return QCBOR_ERR_UNEXPECTED_TYPE;
636636
}
637637

638638

test/qcbor_decode_tests.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8858,6 +8858,26 @@ int32_t EnterBstrTest(void)
88588858
return 300 + (int32_t)uErr;
88598859
}
88608860

8861+
/* Try to enter some thing that is not a bstr */
8862+
QCBORDecode_Init(&DC,
8863+
UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spArrayOfEmpty),
8864+
0);
8865+
QCBORDecode_EnterBstrWrapped(&DC, QCBOR_TAG_REQUIREMENT_NOT_A_TAG, NULL);
8866+
uErr = QCBORDecode_GetError(&DC);
8867+
if(uErr != QCBOR_ERR_UNEXPECTED_TYPE) {
8868+
return 400 + (int32_t)uErr;
8869+
}
8870+
8871+
/* Try to enter some thing else that is not a bstr */
8872+
QCBORDecode_Init(&DC,
8873+
UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spEmptyMap),
8874+
0);
8875+
QCBORDecode_EnterBstrWrapped(&DC, QCBOR_TAG_REQUIREMENT_NOT_A_TAG, NULL);
8876+
uErr = QCBORDecode_GetError(&DC);
8877+
if(uErr != QCBOR_ERR_UNEXPECTED_TYPE) {
8878+
return 500 + (int32_t)uErr;
8879+
}
8880+
88618881
return 0;
88628882
}
88638883

0 commit comments

Comments
 (0)