dfilter: Assert on invalid dfilter_compile input

This commit is contained in:
João Valverde 2023-04-21 01:35:22 +01:00
parent 435a2186ab
commit c053b96f08
2 changed files with 24 additions and 25 deletions

View File

@ -446,21 +446,12 @@ dfilter_compile_full(const gchar *text, dfilter_t **dfp,
dfwork_t *dfw;
char *tree_str;
ws_assert(text);
ws_assert(*text);
ws_assert(dfp);
*dfp = NULL;
if (text == NULL) {
ws_warning("Called from %s() with null filter", caller);
if (err_ptr)
*err_ptr = df_error_new_msg("BUG: NULL text pointer");
return FALSE;
}
if (*text == '\0') {
ws_warning("Called from %s() with empty filter", caller);
if (err_ptr)
*err_ptr = df_error_new_msg("Filter expression is empty");
return FALSE;
}
if (caller == NULL)
caller = "(unknown)";
ws_debug("Called from %s() with filter: %s", caller, text);

32
file.c
View File

@ -490,7 +490,7 @@ cf_read(capture_file *cf, gboolean reloading)
epan_dissect_t edt;
wtap_rec rec;
Buffer buf;
dfilter_t *dfcode;
dfilter_t *dfcode = NULL;
column_info *cinfo;
volatile gboolean create_proto_tree;
guint tap_flags;
@ -513,8 +513,10 @@ cf_read(capture_file *cf, gboolean reloading)
* We assume this will not fail since cf->dfilter is only set in
* cf_filter IFF the filter was valid.
*/
compiled = dfilter_compile(cf->dfilter, &dfcode, NULL);
ws_assert(!cf->dfilter || (compiled && dfcode));
if (cf->dfilter) {
compiled = dfilter_compile(cf->dfilter, &dfcode, NULL);
ws_assert(compiled && dfcode);
}
/* Get the union of the flags for all tap listeners. */
tap_flags = union_of_tap_listener_flags();
@ -761,7 +763,7 @@ cf_continue_tail(capture_file *cf, volatile int to_read, wtap_rec *rec,
{
gchar *err_info;
volatile int newly_displayed_packets = 0;
dfilter_t *dfcode;
dfilter_t *dfcode = NULL;
epan_dissect_t edt;
gboolean create_proto_tree;
guint tap_flags;
@ -771,8 +773,10 @@ cf_continue_tail(capture_file *cf, volatile int to_read, wtap_rec *rec,
* We assume this will not fail since cf->dfilter is only set in
* cf_filter IFF the filter was valid.
*/
compiled = dfilter_compile(cf->dfilter, &dfcode, NULL);
ws_assert(!cf->dfilter || (compiled && dfcode));
if (cf->dfilter) {
compiled = dfilter_compile(cf->dfilter, &dfcode, NULL);
ws_assert(compiled && dfcode);
}
/* Get the union of the flags for all tap listeners. */
tap_flags = union_of_tap_listener_flags();
@ -893,7 +897,7 @@ cf_finish_tail(capture_file *cf, wtap_rec *rec, Buffer *buf, int *err)
{
gchar *err_info;
gint64 data_offset;
dfilter_t *dfcode;
dfilter_t *dfcode = NULL;
column_info *cinfo;
epan_dissect_t edt;
gboolean create_proto_tree;
@ -904,8 +908,10 @@ cf_finish_tail(capture_file *cf, wtap_rec *rec, Buffer *buf, int *err)
* We assume this will not fail since cf->dfilter is only set in
* cf_filter IFF the filter was valid.
*/
compiled = dfilter_compile(cf->dfilter, &dfcode, NULL);
ws_assert(!cf->dfilter || (compiled && dfcode));
if (cf->dfilter) {
compiled = dfilter_compile(cf->dfilter, &dfcode, NULL);
ws_assert(compiled && dfcode);
}
/* Get the union of the flags for all tap listeners. */
tap_flags = union_of_tap_listener_flags();
@ -1627,7 +1633,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb
gint64 start_time;
gchar status_str[100];
epan_dissect_t edt;
dfilter_t *dfcode;
dfilter_t *dfcode = NULL;
column_info *cinfo;
gboolean create_proto_tree;
guint tap_flags;
@ -1648,8 +1654,10 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb
* We assume this will not fail since cf->dfilter is only set in
* cf_filter IFF the filter was valid.
*/
compiled = dfilter_compile(cf->dfilter, &dfcode, NULL);
ws_assert(!cf->dfilter || (compiled && dfcode));
if (cf->dfilter) {
compiled = dfilter_compile(cf->dfilter, &dfcode, NULL);
ws_assert(compiled && dfcode);
}
/* Update references in display filter (if any) for the protocol
* tree corresponding to the currently selected frame in the GUI. */