Skip to content

Commit

Permalink
EnterBstr() error handling bug (#299)
Browse files Browse the repository at this point in the history
Co-authored-by: Laurence Lundblade <[email protected]>
  • Loading branch information
laurencelundblade and Laurence Lundblade authored Jan 21, 2025
1 parent bb98796 commit 4cee345
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/qcbor_tag_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ QCBORDecode_Private_EnterBstrWrapped(QCBORDecodeContext *pMe,
&bTypeMatched);

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


Expand Down
20 changes: 20 additions & 0 deletions test/qcbor_decode_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -8858,6 +8858,26 @@ int32_t EnterBstrTest(void)
return 300 + (int32_t)uErr;
}

/* Try to enter some thing that is not a bstr */
QCBORDecode_Init(&DC,
UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spArrayOfEmpty),
0);
QCBORDecode_EnterBstrWrapped(&DC, QCBOR_TAG_REQUIREMENT_NOT_A_TAG, NULL);
uErr = QCBORDecode_GetError(&DC);
if(uErr != QCBOR_ERR_UNEXPECTED_TYPE) {
return 400 + (int32_t)uErr;
}

/* Try to enter some thing else that is not a bstr */
QCBORDecode_Init(&DC,
UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spEmptyMap),
0);
QCBORDecode_EnterBstrWrapped(&DC, QCBOR_TAG_REQUIREMENT_NOT_A_TAG, NULL);
uErr = QCBORDecode_GetError(&DC);
if(uErr != QCBOR_ERR_UNEXPECTED_TYPE) {
return 500 + (int32_t)uErr;
}

return 0;
}

Expand Down

0 comments on commit 4cee345

Please sign in to comment.