WBXML: add a basic sanity check for offset overflow

This is a naive approach allowing to detact that something went wrong,
without the need to replace all proto_tree_add_text() calls as what was
done in master-2.0 branch.

Bug: 12408
Change-Id: Ia14905005e17ae322c2fc639ad5e491fa08b0108
Reviewed-on: https://code.wireshark.org/review/15310
Reviewed-by: Michael Mann <mmann78@netscape.net>
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
wv_integer_from_opaque(tvbuff_t *tvb, guint32 offset, guint32 data_len)
{
	char *str;

	switch (data_len) {
	case 1:
		str = wmem_strdup_printf(wmem_packet_scope(), "WV-CSP Integer: %d",
				      tvb_get_guint8(tvb, offset));
		break;
	case 2:
		str = wmem_strdup_printf(wmem_packet_scope(), "WV-CSP Integer: %d",
				      tvb_get_ntohs(tvb, offset));
		break;
	case 3:
		str = wmem_strdup_printf(wmem_packet_scope(), "WV-CSP Integer: %d",
				      tvb_get_ntoh24(tvb, offset));
		break;
	case 4:
		str = wmem_strdup_printf(wmem_packet_scope(), "WV-CSP Integer: %d",
				      tvb_get_ntohl(tvb, offset));
		break;
	default:
		str = wmem_strdup_printf(wmem_packet_scope(), "<Error: invalid binary WV-CSP Integer value "
				      "(%d bytes of opaque data)>", data_len);
		break;
	}

	return str;
}

wv_integer_from_opaque(tvbuff_t *tvb, guint32 offset, guint32 data_len)
{
	char *str;

	switch (data_len) {
	case 1:
		str = wmem_strdup_printf(wmem_packet_scope(), "WV-CSP Integer: %d",
				      tvb_get_guint8(tvb, offset));
		break;
	case 2:
		str = wmem_strdup_printf(wmem_packet_scope(), "WV-CSP Integer: %d",
				      tvb_get_ntohs(tvb, offset));
		break;
	case 3:
		str = wmem_strdup_printf(wmem_packet_scope(), "WV-CSP Integer: %d",
				      tvb_get_ntoh24(tvb, offset));
		break;
	case 4:
		str = wmem_strdup_printf(wmem_packet_scope(), "WV-CSP Integer: %d",
				      tvb_get_ntohl(tvb, offset));
		break;
	default:
		str = wmem_strdup_printf(wmem_packet_scope(), "<Error: invalid binary WV-CSP Integer value "
				      "(%d bytes of opaque data)>", data_len);
		break;
	}

	return str;
}
