Skip to content

Commit

Permalink
Fix broken tag handling in QRCodeSetupPayloadParser. (#13201)
Browse files Browse the repository at this point in the history
The only reason this worked in any way is that TLV::IsProfileTag()
tests true for small integers, so the VerifyOrReturnError was a no-op,
even though we were testing IsContextTag() and IsProfileTag() on the
tag _number_, not the tag.

Per spec, only context tags are allowed here, so just allow those.

Fixes #10188
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jul 6, 2023
1 parent 9bd635b commit 5441301
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/setup_payload/QRCodeSetupPayloadParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ CHIP_ERROR QRCodeSetupPayloadParser::retrieveOptionalInfos(SetupPayload & outPay
continue;
}

const uint8_t tag = static_cast<uint8_t>(TLV::TagNumFromTag(reader.GetTag()));
VerifyOrReturnError(TLV::IsContextTag(tag) == true || TLV::IsProfileTag(tag) == true, CHIP_ERROR_INVALID_TLV_TAG);
TLV::Tag tag = reader.GetTag();
VerifyOrReturnError(TLV::IsContextTag(tag), CHIP_ERROR_INVALID_TLV_TAG);
const uint8_t tagNumber = static_cast<uint8_t>(TLV::TagNumFromTag(tag));

optionalQRCodeInfoType elemType = optionalQRCodeInfoTypeUnknown;
if (type == TLV::kTLVType_UTF8String)
Expand All @@ -204,21 +205,21 @@ CHIP_ERROR QRCodeSetupPayloadParser::retrieveOptionalInfos(SetupPayload & outPay
}
if (type == TLV::kTLVType_SignedInteger || type == TLV::kTLVType_UnsignedInteger)
{
elemType = outPayload.getNumericTypeFor(tag);
elemType = outPayload.getNumericTypeFor(tagNumber);
}

if (IsCHIPTag(tag))
if (IsCHIPTag(tagNumber))
{
OptionalQRCodeInfoExtension info;
info.tag = tag;
info.tag = tagNumber;
ReturnErrorOnFailure(retrieveOptionalInfo(reader, info, elemType));

ReturnErrorOnFailure(outPayload.addOptionalExtensionData(info));
}
else
{
OptionalQRCodeInfo info;
info.tag = tag;
info.tag = tagNumber;
ReturnErrorOnFailure(retrieveOptionalInfo(reader, info, elemType));

ReturnErrorOnFailure(outPayload.addOptionalVendorData(info));
Expand Down

0 comments on commit 5441301

Please sign in to comment.