CBOR: Avoid infinite loop when sequence has not-well-formed data

This fixes a defect in the original MR !4752 adding cbor sequence dissecting.
This commit is contained in:
Brian Sipos 2021-10-25 23:31:24 -04:00 committed by Wireshark GitLab Utility
parent a114a115ba
commit 1120f545d3
2 changed files with 14 additions and 4 deletions

View File

@ -709,12 +709,16 @@ dissect_cborseq(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void
gint offset = 0;
proto_item *cbor_root;
proto_tree *cbor_tree;
proto_item *elem;
cbor_root = proto_tree_add_item(parent_tree, proto_cbor, tvb, offset, -1, ENC_NA);
proto_item_append_text(cbor_root, " Sequence");
cbor_tree = proto_item_add_subtree(cbor_root, ett_cbor);
while ((guint)offset < tvb_reported_length(tvb)) {
dissect_cbor_main_type(tvb, pinfo, cbor_tree, &offset);
elem = dissect_cbor_main_type(tvb, pinfo, cbor_tree, &offset);
if (!elem) {
break;
}
}
return offset;

View File

@ -29,16 +29,22 @@ def main():
help='The diagnostic text input file, or "-" for stdin')
parser.add_argument('--outfile', default='-',
help='The PCAP output file, or "-" for stdout')
parser.add_argument('--intype', default='cbordiag',
choices=['cbordiag', 'raw'],
help='The input data type.')
args = parser.parse_args()
# First get the CBOR data itself
infile_name = args.infile.strip()
if infile_name != '-':
infile = open(infile_name, 'r')
infile = open(infile_name, 'rb')
else:
infile = sys.stdin
infile = sys.stdin.buffer
cbordata = check_output('diag2cbor.rb', stdin=infile)
if args.intype == 'raw':
cbordata = infile.read()
elif args.intype == 'cbordiag':
cbordata = check_output('diag2cbor.rb', stdin=infile)
# Now synthesize an HTTP request with that body
req = HTTPRequest(