aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dfilter
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2021-11-27 17:31:16 +0000
committerWireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2021-11-27 18:38:22 +0000
commitfbfb4959ae2c2f9b5ea4c1e8d81c8ebfef0564ea (patch)
tree97603ba1b7a63abe4204aaa6942ce33947b44161 /epan/dfilter
parentc595ecfc2806cc578bcb9870d42ed2e1f9906034 (diff)
dfilter: Better representation for charconst
Diffstat (limited to 'epan/dfilter')
-rw-r--r--epan/dfilter/scanner.l2
-rw-r--r--epan/dfilter/semcheck.c5
-rw-r--r--epan/dfilter/sttype-pointer.c25
3 files changed, 26 insertions, 6 deletions
diff --git a/epan/dfilter/scanner.l b/epan/dfilter/scanner.l
index 96a00024bb..223a800116 100644
--- a/epan/dfilter/scanner.l
+++ b/epan/dfilter/scanner.l
@@ -524,7 +524,7 @@ parse_charconst(dfwork_t *dfw, const char *s, unsigned long *valuep)
} else {
value = *cp;
if (!g_ascii_isprint(value)) {
- dfilter_fail(dfw, "Non-printable character '0x%2lx' in character constant.", value);
+ dfilter_fail(dfw, "Non-printable value '0x%02lx' in character constant.", value);
return FALSE;
}
}
diff --git a/epan/dfilter/semcheck.c b/epan/dfilter/semcheck.c
index 6ba0bc96ce..799b406c6b 100644
--- a/epan/dfilter/semcheck.c
+++ b/epan/dfilter/semcheck.c
@@ -434,14 +434,11 @@ check_exists(dfwork_t *dfw, stnode_t *st_arg1)
break;
case STTYPE_STRING:
case STTYPE_UNPARSED:
+ case STTYPE_CHARCONST:
FAIL(dfw, "\"%s\" is neither a field nor a protocol name.",
stnode_todisplay(st_arg1));
break;
- case STTYPE_CHARCONST:
- FAIL(dfw, "You cannot test whether a character constant is present.");
- break;
-
case STTYPE_RANGE:
/*
* XXX - why not? Shouldn't "eth[3:2]" mean
diff --git a/epan/dfilter/sttype-pointer.c b/epan/dfilter/sttype-pointer.c
index c19694e8f5..c19c2894dc 100644
--- a/epan/dfilter/sttype-pointer.c
+++ b/epan/dfilter/sttype-pointer.c
@@ -68,7 +68,30 @@ pcre_tostr(const void *data, gboolean pretty _U_)
static char *
charconst_tostr(const void *data, gboolean pretty _U_)
{
- return g_strdup_printf("%lu", *(unsigned long *)data);
+ unsigned long num = *(const unsigned long *)data;
+
+ if (num > 0x7f)
+ goto out;
+
+ switch (num) {
+ case 0: return g_strdup("'\\0'");
+ case '\a': return g_strdup("'\\a'");
+ case '\b': return g_strdup("'\\b'");
+ case '\f': return g_strdup("'\\f'");
+ case '\n': return g_strdup("'\\n'");
+ case '\r': return g_strdup("'\\r'");
+ case '\t': return g_strdup("'\\t'");
+ case '\v': return g_strdup("'\\v'");
+ case '\'': return g_strdup("'\\''");
+ case '\\': return g_strdup("'\\\\'");
+ default:
+ break;
+ }
+
+ if (g_ascii_isprint(num))
+ return g_strdup_printf("'%c'", (int)num);
+out:
+ return g_strdup_printf("'\\x%02lx'", num);
}
void