mmse: Handle encoding

Use tvb_get_stringz_enc with ENC_ASCII instead of tvb_strsize
and tvb_memdup. Note that, in MMS encoding at least,
OMA-TS-MMS-CONF says that Text-string (where encoding is
not specified) is always US-ASCII.

For Encoded-string-values, get and process the MIBEnum charset,
at least when it's an integer (which OMA-TS-MMS-CONF says it
must be.)

Fix #18575
This commit is contained in:
John Thacker 2022-11-06 05:29:56 -05:00
parent b860351e7f
commit 9a3d091933
1 changed files with 54 additions and 40 deletions

View File

@ -26,6 +26,7 @@
#include <epan/expert.h>
#include <epan/to_str.h>
#include <epan/strutil.h>
#include <epan/iana_charsets.h>
#include "packet-wap.h"
#include "packet-wsp.h"
@ -453,12 +454,17 @@ get_text_string(tvbuff_t *tvb, guint offset, wmem_allocator_t *pool, const char
DebugLog(("get_text_string(tvb = %p, offset = %u, **strval) - start\n",
tvb, offset));
len = tvb_strsize(tvb, offset);
DebugLog((" [1] tvb_strsize(tvb, offset) == %u\n", len));
if (tvb_get_guint8(tvb, offset) == MM_QUOTE)
*strval = (const char *)tvb_memdup(pool, tvb, offset+1, len-1);
else
*strval = (const char *)tvb_memdup(pool, tvb, offset, len);
/* OMA-TS-MMS-CONF says that Text-string encoding is always US-ASCII.
* (In other WSP protocols it might be the document encoding.)
* It is allowed to be Base64 or Quoted-Printable encoded, but
* we won't bother with that.
*/
if (tvb_get_guint8(tvb, offset) == MM_QUOTE) {
*strval = (const char *)tvb_get_stringz_enc(pool, tvb, offset+1, &len, ENC_ASCII);
len += 1;
} else {
*strval = (const char *)tvb_get_stringz_enc(pool, tvb, offset, &len, ENC_ASCII);
}
DebugLog((" [3] Return(len) == %u\n", len));
return len;
}
@ -501,40 +507,6 @@ get_value_length(tvbuff_t *tvb, guint offset, guint *byte_count, packet_info *pi
return field;
}
/*!
* Decodes an Encoded-string-value from the protocol data
* Encoded-string-value = Text-string | Value-length Char-set Text-string
*
* \param tvb The buffer with PDU-data
* \param offset Offset within that buffer
* \param strval Pointer to variable into which to put pointer to
* buffer allocated to hold the text; must be freed
* when no longer used
*
* \return The length in bytes of the entire field
*/
static guint
get_encoded_strval(tvbuff_t *tvb, guint offset, const char **strval, packet_info *pinfo)
{
guint field;
guint length;
guint count;
field = tvb_get_guint8(tvb, offset);
if (field < 32) {
length = get_value_length(tvb, offset, &count, pinfo);
if (length < 2) {
*strval = "";
} else {
/* \todo Something with "Char-set", skip for now */
*strval = (char *)tvb_get_string_enc(pinfo->pool, tvb, offset + count + 1, length - 1, ENC_ASCII);
}
return count + length;
} else
return get_text_string(tvb, offset, pinfo->pool, strval);
}
/*!
* Decodes a Long-integer from the protocol data
* Long-integer = Short-length Multi-octet-integer
@ -631,6 +603,48 @@ get_integer_value(tvbuff_t *tvb, guint offset, guint *byte_count)
return val;
}
/*!
* Decodes an Encoded-string-value from the protocol data
* Encoded-string-value = Text-string | Value-length Char-set Text-string
*
* \param tvb The buffer with PDU-data
* \param offset Offset within that buffer
* \param strval Pointer to variable into which to put pointer to
* buffer allocated to hold the text; must be freed
* when no longer used
*
* \return The length in bytes of the entire field
*/
static guint
get_encoded_strval(tvbuff_t *tvb, guint offset, const char **strval, packet_info *pinfo)
{
guint field;
guint length;
guint count, count1;
guint charset;
field = tvb_get_guint8(tvb, offset);
if (field < 32) {
length = get_value_length(tvb, offset, &count, pinfo);
if (length < 2) {
*strval = "";
} else {
/* OMA-TS-MMS-CONF says that char-set is encoded as an integer
* value, so don't bother to handle the string case. */
field = tvb_get_guint8(tvb, offset + count);
if ((field < 32) | (field & 0x80)) {
charset = get_integer_value(tvb, offset + count, &count1);
*strval = (char *)tvb_get_string_enc(pinfo->pool, tvb, offset + count + count1, length - count1, mibenum_charset_to_encoding(charset));
} else {
*strval = (char *)tvb_get_string_enc(pinfo->pool, tvb, offset + count, length, ENC_ASCII);
}
}
return count + length;
} else
return get_text_string(tvb, offset, pinfo->pool, strval);
}
/* Code to actually dissect the packets */
static gboolean
dissect_mmse_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)