libwireshark: don't allow fields of type FT_PCRE to be registered.

It's a fake "field" type, used only for "field" values in
packet-matching expressions to do regular-expression matching.  There is
*no* reason to allow fields of that type.

Don't bother checking the representation type when generating the string
representation of a field value.  If a developer manages to get past all
the tests for FT_PCRE to register and add an instance of that field to
the protocol tree, either 1) the one and only string representation of
an FT_PCRE value is what they want, in which case, whatever, or 2) it's
*not* what they want, in which case, if they file a bug, ask a question
on a mailing list, or ask a question on the Q&A site, we can explain to
them that what they're doing is bogus.
This commit is contained in:
Guy Harris 2021-03-20 00:02:51 -07:00
parent 54c30c8336
commit 6ffbbcefa3
2 changed files with 13 additions and 4 deletions

View File

@ -88,16 +88,14 @@ val_from_unparsed(fvalue_t *fv, const char *pattern, gboolean allow_partial_valu
}
static int
gregex_repr_len(fvalue_t *fv, ftrepr_t rtype, int field_display _U_)
gregex_repr_len(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_)
{
g_assert(rtype == FTREPR_DFILTER);
return (int)strlen(g_regex_get_pattern(fv->value.re));
}
static void
gregex_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char *buf, unsigned int size)
gregex_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size)
{
g_assert(rtype == FTREPR_DFILTER);
g_strlcpy(buf, g_regex_get_pattern(fv->value.re), size);
}

View File

@ -7101,6 +7101,7 @@ proto_item_get_display_repr(wmem_allocator_t *scope, proto_item *pi)
return "";
fi = PITEM_FINFO(pi);
DISSECTOR_ASSERT(fi->hfinfo != NULL);
DISSECTOR_ASSERT(fi->hfinfo->type != FT_PCRE);
return fvalue_to_string_repr(scope, &fi->value, FTREPR_DISPLAY, fi->hfinfo->display);
}
@ -8235,6 +8236,16 @@ tmp_fld_check_assert(header_field_info *hfinfo)
if (!hfinfo->abbrev || !hfinfo->abbrev[0])
g_error("Field '%s' does not have an abbreviation\n", hfinfo->name);
/*
* FT_PCRE is a special "field" type; it's not for use by
* fields, just by field values in filter expressions.
*/
if (hfinfo->type == FT_PCRE) {
g_error("Field '%s' (%s) is of type FT_PCRE,"
" which is not allowed\n",
hfinfo->name, hfinfo->abbrev);
}
/* These types of fields are allowed to have value_strings,
* true_false_strings or a protocol_t struct
*/