forked from osmocom/wireshark
dfilter: Handle missing error location more gracefully
If we don't have an offset, don't print anything with underline. Also it can underline filters using macros correctly now. $ tshark -Y 'ip and ${private_ipv4:ip.sr}' -r /dev/null tshark: Left side of "==" expression must be a field or function, not "ip.sr". ip and ip.sr == 192.168.0.0/16 or ip.sr == 172.16.0.0/12 or ip.sr == 10.0.0.0/8 ^~~~~
This commit is contained in:
parent
ceef8aa8ee
commit
2f02cd6e19
8
dftest.c
8
dftest.c
|
@ -167,9 +167,11 @@ main(int argc, char **argv)
|
|||
if (!dfilter_compile_real(expanded_text, &df, &err_msg, &err_loc,
|
||||
"dftest", TRUE, FALSE)) {
|
||||
fprintf(stderr, "dftest: %s\n", err_msg);
|
||||
fprintf(stderr, "\t%s\n", expanded_text);
|
||||
fputc('\t', stderr);
|
||||
putloc(stderr, err_loc.col_start, err_loc.col_len);
|
||||
if (err_loc.col_start >= 0) {
|
||||
fprintf(stderr, "\t%s\n", expanded_text);
|
||||
fputc('\t', stderr);
|
||||
putloc(stderr, err_loc.col_start, err_loc.col_len);
|
||||
}
|
||||
g_free(err_msg);
|
||||
g_free(expanded_text);
|
||||
epan_cleanup();
|
||||
|
|
|
@ -58,6 +58,10 @@ dfilter_vfail(dfwork_t *dfw, stloc_t *loc,
|
|||
if (loc) {
|
||||
dfw->err_loc = *loc;
|
||||
}
|
||||
else {
|
||||
dfw->err_loc.col_start = -1;
|
||||
dfw->err_loc.col_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -304,6 +304,8 @@ sprint_node(stnode_t *node)
|
|||
wmem_strbuf_append_printf(buf, "magic=0x%"PRIx32", ", node->magic);
|
||||
wmem_strbuf_append_printf(buf, "type=%s, ", stnode_type_name(node));
|
||||
wmem_strbuf_append_printf(buf, "data=<%s>, ", stnode_todebug(node));
|
||||
wmem_strbuf_append_printf(buf, "location=%d:%zu",
|
||||
node->location.col_start, node->location.col_len);
|
||||
return wmem_strbuf_finalize(buf);
|
||||
}
|
||||
|
||||
|
|
51
tshark.c
51
tshark.c
|
@ -606,6 +606,40 @@ gather_tshark_runtime_info(feature_list l)
|
|||
epan_gather_runtime_info(l);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_compile_dfilter(const char *text, dfilter_t **dfp, const char *caller)
|
||||
{
|
||||
gboolean ok;
|
||||
dfilter_loc_t err_loc;
|
||||
char *err_msg = NULL;
|
||||
char *err_off;
|
||||
char *expanded;
|
||||
|
||||
expanded = dfilter_expand(text, &err_msg);
|
||||
if (expanded == NULL) {
|
||||
cmdarg_err("%s", err_msg);
|
||||
g_free(err_msg);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ok = dfilter_compile_real(expanded, dfp, &err_msg, &err_loc, caller, FALSE, FALSE);
|
||||
if (!ok ) {
|
||||
cmdarg_err("%s", err_msg);
|
||||
g_free(err_msg);
|
||||
if (err_loc.col_start >= 0) {
|
||||
err_off = ws_strdup_error_offset(NULL, err_loc.col_start, err_loc.col_len);
|
||||
cmdarg_err_cont(" %s", expanded);
|
||||
cmdarg_err_cont(" %s", err_off);
|
||||
g_free(err_off);
|
||||
}
|
||||
}
|
||||
|
||||
g_free(expanded);
|
||||
return ok;
|
||||
}
|
||||
|
||||
#define compile_dfilter(text, dfp) _compile_dfilter(text, dfp, __func__)
|
||||
|
||||
static void
|
||||
about_folders(void)
|
||||
{
|
||||
|
@ -722,7 +756,7 @@ must_do_dissection(dfilter_t *rfcode, dfilter_t *dfcode,
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char *err_msg, *err_msg_cont;
|
||||
char *err_msg;
|
||||
static const struct report_message_routines tshark_report_routines = {
|
||||
failure_message,
|
||||
failure_message,
|
||||
|
@ -777,7 +811,6 @@ main(int argc, char *argv[])
|
|||
gchar *volatile dfilter = NULL;
|
||||
dfilter_t *rfcode = NULL;
|
||||
dfilter_t *dfcode = NULL;
|
||||
dfilter_loc_t df_loc;
|
||||
e_prefs *prefs_p;
|
||||
gchar *output_only = NULL;
|
||||
gchar *volatile pdu_export_arg = NULL;
|
||||
|
@ -2014,12 +2047,7 @@ main(int argc, char *argv[])
|
|||
|
||||
if (rfilter != NULL) {
|
||||
ws_debug("Compiling read filter: '%s'", rfilter);
|
||||
if (!dfilter_compile2(rfilter, &rfcode, &err_msg, &df_loc)) {
|
||||
cmdarg_err("%s", err_msg);
|
||||
err_msg_cont = ws_strdup_error_offset(NULL, df_loc.col_start, df_loc.col_len);
|
||||
cmdarg_err_cont(" %s\n %s\n", rfilter, err_msg_cont);
|
||||
g_free(err_msg);
|
||||
g_free(err_msg_cont);
|
||||
if (!compile_dfilter(rfilter, &rfcode)) {
|
||||
epan_cleanup();
|
||||
extcap_cleanup();
|
||||
|
||||
|
@ -2044,12 +2072,7 @@ main(int argc, char *argv[])
|
|||
|
||||
if (dfilter != NULL) {
|
||||
ws_debug("Compiling display filter: '%s'", dfilter);
|
||||
if (!dfilter_compile2(dfilter, &dfcode, &err_msg, &df_loc)) {
|
||||
cmdarg_err("%s", err_msg);
|
||||
err_msg_cont = ws_strdup_error_offset(NULL, df_loc.col_start, df_loc.col_len);
|
||||
cmdarg_err_cont(" %s\n %s\n", dfilter, err_msg_cont);
|
||||
g_free(err_msg);
|
||||
g_free(err_msg_cont);
|
||||
if (!compile_dfilter(dfilter, &dfcode)) {
|
||||
epan_cleanup();
|
||||
extcap_cleanup();
|
||||
|
||||
|
|
Loading…
Reference in New Issue