From 6952c1c54ffe56f9c6402ce53ca4255dc9da82c1 Mon Sep 17 00:00:00 2001 From: Thies Moeller Date: Sun, 29 Nov 2015 09:45:39 +0000 Subject: [PATCH] USB: allow usb string descriptor short read Some drivers do a probing access to the descriptor to fetch just the length field Change-Id: Idd07a1e66800afcc838beb795594a4505ce13e82 Reviewed-on: https://code.wireshark.org/review/12250 Reviewed-by: Pascal Quantin --- epan/dissectors/packet-usb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/epan/dissectors/packet-usb.c b/epan/dissectors/packet-usb.c index 4ba7bfdd92..e4ed162131 100644 --- a/epan/dissectors/packet-usb.c +++ b/epan/dissectors/packet-usb.c @@ -1615,8 +1615,10 @@ dissect_usb_string_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree, } } else { /* UTF-16 string */ - proto_tree_add_item(tree, hf_usb_bString, tvb, offset, len-2, ENC_UTF_16 | ENC_LITTLE_ENDIAN); - offset += len-2; + /* handle case of host requesting only substring */ + guint8 len_str = MIN(len-2, usb_trans_info->setup.wLength -2); + proto_tree_add_item(tree, hf_usb_bString, tvb, offset, len_str, ENC_UTF_16 | ENC_LITTLE_ENDIAN); + offset += len_str; } proto_item_set_len(item, offset-old_offset);