forked from osmocom/wireshark
dfilter: Refactor error location tracking
Remove duplicate location struct by adding a new header. Pass around a structure instead of a pointer.
This commit is contained in:
parent
51a6dfffc7
commit
3938b406fb
2
dftest.c
2
dftest.c
|
@ -42,7 +42,7 @@ static void dftest_cmdarg_err(const char *fmt, va_list ap);
|
|||
static void dftest_cmdarg_err_cont(const char *fmt, va_list ap);
|
||||
|
||||
static void
|
||||
putloc(FILE *fp, dfilter_loc_t loc)
|
||||
putloc(FILE *fp, df_loc_t loc)
|
||||
{
|
||||
for (long i = 0; i < loc.col_start; i++) {
|
||||
fputc(' ', fp);
|
||||
|
|
|
@ -65,8 +65,8 @@ typedef struct {
|
|||
dfwork_t *dfw;
|
||||
GString* quoted_string;
|
||||
gboolean raw_string;
|
||||
stloc_t string_loc;
|
||||
stloc_t location;
|
||||
df_loc_t string_loc;
|
||||
df_loc_t location;
|
||||
} df_scanner_state_t;
|
||||
|
||||
/* Constructor/Destructor prototypes for Lemon Parser */
|
||||
|
@ -80,20 +80,20 @@ void Dfilter(void*, int, stnode_t*, dfwork_t*);
|
|||
#define SCAN_FAILED -1 /* not 0, as that means end-of-input */
|
||||
|
||||
void
|
||||
dfilter_vfail(dfwork_t *dfw, int code, stloc_t *err_loc,
|
||||
dfilter_vfail(dfwork_t *dfw, int code, df_loc_t err_loc,
|
||||
const char *format, va_list args);
|
||||
|
||||
void
|
||||
dfilter_fail(dfwork_t *dfw, int code, stloc_t *err_loc,
|
||||
dfilter_fail(dfwork_t *dfw, int code, df_loc_t err_loc,
|
||||
const char *format, ...) G_GNUC_PRINTF(4, 5);
|
||||
|
||||
WS_NORETURN
|
||||
void
|
||||
dfilter_fail_throw(dfwork_t *dfw, int code, stloc_t *err_loc,
|
||||
dfilter_fail_throw(dfwork_t *dfw, int code, df_loc_t err_loc,
|
||||
const char *format, ...) G_GNUC_PRINTF(4, 5);
|
||||
|
||||
void
|
||||
dfw_set_error_location(dfwork_t *dfw, stloc_t *err_loc);
|
||||
dfw_set_error_location(dfwork_t *dfw, df_loc_t err_loc);
|
||||
|
||||
void
|
||||
add_deprecated_token(dfwork_t *dfw, const char *token);
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
/** @file
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 2001 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef DFILTER_LOC_H
|
||||
#define DFILTER_LOC_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct _dfilter_loc {
|
||||
long col_start;
|
||||
size_t col_len;
|
||||
} df_loc_t;
|
||||
|
||||
extern df_loc_t loc_empty;
|
||||
|
||||
#define DFILTER_LOC_EMPTY loc_empty
|
||||
|
||||
#endif
|
|
@ -41,8 +41,10 @@ static void* ParserObj = NULL;
|
|||
*/
|
||||
dfwork_t *global_dfw;
|
||||
|
||||
df_loc_t loc_empty = {-1, 0};
|
||||
|
||||
void
|
||||
dfilter_vfail(dfwork_t *dfw, int code, stloc_t *loc,
|
||||
dfilter_vfail(dfwork_t *dfw, int code, df_loc_t loc,
|
||||
const char *format, va_list args)
|
||||
{
|
||||
dfw->parse_failure = TRUE;
|
||||
|
@ -53,17 +55,11 @@ dfilter_vfail(dfwork_t *dfw, int code, stloc_t *loc,
|
|||
|
||||
dfw->error.code = code;
|
||||
dfw->error.msg = ws_strdup_vprintf(format, args);
|
||||
if (loc) {
|
||||
dfw->error.loc = *(dfilter_loc_t *)loc;
|
||||
}
|
||||
else {
|
||||
dfw->error.loc.col_start = -1;
|
||||
dfw->error.loc.col_len = 0;
|
||||
}
|
||||
dfw->error.loc = loc;
|
||||
}
|
||||
|
||||
void
|
||||
dfilter_fail(dfwork_t *dfw, int code, stloc_t *loc,
|
||||
dfilter_fail(dfwork_t *dfw, int code, df_loc_t loc,
|
||||
const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
@ -74,7 +70,7 @@ dfilter_fail(dfwork_t *dfw, int code, stloc_t *loc,
|
|||
}
|
||||
|
||||
void
|
||||
dfilter_fail_throw(dfwork_t *dfw, int code, stloc_t *loc, const char *format, ...)
|
||||
dfilter_fail_throw(dfwork_t *dfw, int code, df_loc_t loc, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
|
@ -85,11 +81,9 @@ dfilter_fail_throw(dfwork_t *dfw, int code, stloc_t *loc, const char *format, ..
|
|||
}
|
||||
|
||||
void
|
||||
dfw_set_error_location(dfwork_t *dfw, stloc_t *loc)
|
||||
dfw_set_error_location(dfwork_t *dfw, df_loc_t loc)
|
||||
{
|
||||
/* Set new location. */
|
||||
ws_assert(loc);
|
||||
dfw->error.loc = *(dfilter_loc_t *)loc;
|
||||
dfw->error.loc = loc;
|
||||
}
|
||||
|
||||
header_field_info *
|
||||
|
@ -419,7 +413,7 @@ dfilter_compile_real(const gchar *text, dfilter_t **dfp,
|
|||
df_set_extra(&state, scanner);
|
||||
|
||||
while (1) {
|
||||
df_lval = stnode_new(STTYPE_UNINITIALIZED, NULL, NULL, NULL);
|
||||
df_lval = stnode_new_empty(STTYPE_UNINITIALIZED);
|
||||
token = df_lex(scanner);
|
||||
|
||||
/* Check for scanner failure */
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include <glib.h>
|
||||
#include "ws_symbol_export.h"
|
||||
|
||||
#include "dfilter-loc.h"
|
||||
|
||||
/* Passed back to user */
|
||||
typedef struct epan_dfilter dfilter_t;
|
||||
|
||||
|
@ -55,15 +57,10 @@ dfilter_expand(const char *expr, char **err_ret);
|
|||
#define DF_ERROR_GENERIC -1
|
||||
#define DF_ERROR_UNEXPECTED_END -2
|
||||
|
||||
typedef struct _dfilter_loc {
|
||||
long col_start;
|
||||
size_t col_len;
|
||||
} dfilter_loc_t;
|
||||
|
||||
typedef struct {
|
||||
int code;
|
||||
char *msg;
|
||||
dfilter_loc_t loc;
|
||||
df_loc_t loc;
|
||||
} df_error_t;
|
||||
|
||||
WS_DLL_PUBLIC
|
||||
|
|
|
@ -243,7 +243,7 @@ df_func_abs(GSList *args, guint32 arg_count, GSList **retval)
|
|||
* it is an FT_STRING */
|
||||
static ftenum_t
|
||||
ul_semcheck_is_field_string(dfwork_t *dfw, const char *func_name, ftenum_t lhs_ftype _U_,
|
||||
GSList *param_list, stloc_t *func_loc _U_)
|
||||
GSList *param_list, df_loc_t func_loc _U_)
|
||||
{
|
||||
header_field_info *hfinfo;
|
||||
|
||||
|
@ -261,7 +261,7 @@ ul_semcheck_is_field_string(dfwork_t *dfw, const char *func_name, ftenum_t lhs_f
|
|||
|
||||
static ftenum_t
|
||||
ul_semcheck_is_field(dfwork_t *dfw, const char *func_name, ftenum_t lhs_ftype _U_,
|
||||
GSList *param_list, stloc_t *func_loc _U_)
|
||||
GSList *param_list, df_loc_t func_loc _U_)
|
||||
{
|
||||
ws_assert(g_slist_length(param_list) == 1);
|
||||
stnode_t *st_node = param_list->data;
|
||||
|
@ -274,7 +274,7 @@ ul_semcheck_is_field(dfwork_t *dfw, const char *func_name, ftenum_t lhs_ftype _U
|
|||
|
||||
static ftenum_t
|
||||
ul_semcheck_string_param(dfwork_t *dfw, const char *func_name, ftenum_t lhs_ftype _U_,
|
||||
GSList *param_list, stloc_t *func_loc _U_)
|
||||
GSList *param_list, df_loc_t func_loc _U_)
|
||||
{
|
||||
header_field_info *hfinfo;
|
||||
|
||||
|
@ -328,7 +328,7 @@ ul_semcheck_string_param(dfwork_t *dfw, const char *func_name, ftenum_t lhs_ftyp
|
|||
/* Check arguments are all the same type and they can be compared. */
|
||||
static ftenum_t
|
||||
ul_semcheck_compare(dfwork_t *dfw, const char *func_name, ftenum_t lhs_ftype,
|
||||
GSList *param_list, stloc_t *func_loc _U_)
|
||||
GSList *param_list, df_loc_t func_loc _U_)
|
||||
{
|
||||
stnode_t *arg;
|
||||
ftenum_t ftype, ft_arg;
|
||||
|
@ -396,7 +396,7 @@ ul_semcheck_compare(dfwork_t *dfw, const char *func_name, ftenum_t lhs_ftype,
|
|||
|
||||
static ftenum_t
|
||||
ul_semcheck_absolute_value(dfwork_t *dfw, const char *func_name, ftenum_t lhs_ftype,
|
||||
GSList *param_list, stloc_t *func_loc _U_)
|
||||
GSList *param_list, df_loc_t func_loc _U_)
|
||||
{
|
||||
ws_assert(g_slist_length(param_list) == 1);
|
||||
stnode_t *st_node;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <glib.h>
|
||||
#include <ftypes/ftypes.h>
|
||||
#include "syntax-tree.h"
|
||||
#include "dfilter-int.h"
|
||||
|
||||
/* Functions take any number of arguments and return 1. */
|
||||
|
||||
|
@ -21,7 +22,7 @@ typedef gboolean (*DFFuncType)(GSList *arg_list, guint32 arg_count, GSList **ret
|
|||
|
||||
/* The semantic check for the dfilter function */
|
||||
typedef ftenum_t (*DFSemCheckType)(dfwork_t *dfw, const char *func_name, ftenum_t lhs_ftype,
|
||||
GSList *param_list, stloc_t *func_loc);
|
||||
GSList *param_list, df_loc_t func_loc);
|
||||
|
||||
/* This is a "function definition" record, holding everything
|
||||
* we need to know about a function */
|
||||
|
|
|
@ -61,11 +61,11 @@ DIAG_ON_LEMON()
|
|||
%type set_element {GSList*}
|
||||
%destructor set_element {set_nodelist_free($$);}
|
||||
|
||||
/* This is called as soon as a syntax error happens. After that,
|
||||
/* This is called as soon as a syntax error happens. After that,
|
||||
any "error" symbols are shifted, if possible. */
|
||||
%syntax_error {
|
||||
if (!TOKEN) {
|
||||
dfilter_fail(dfw, DF_ERROR_UNEXPECTED_END, NULL, "Unexpected end of filter expression.");
|
||||
dfilter_fail(dfw, DF_ERROR_UNEXPECTED_END, DFILTER_LOC_EMPTY, "Unexpected end of filter expression.");
|
||||
return;
|
||||
}
|
||||
FAIL(dfw, TOKEN, "\"%s\" was unexpected in this context.", stnode_token(TOKEN));
|
||||
|
@ -181,7 +181,7 @@ field(R) ::= ATSIGN layered_field(F).
|
|||
field(R) ::= ATSIGN UNPARSED(U).
|
||||
{
|
||||
const char *token = stnode_token(U);
|
||||
const stloc_t *loc = stnode_location(U);
|
||||
df_loc_t loc = stnode_location(U);
|
||||
header_field_info *hfinfo = dfilter_resolve_unparsed(dfw, token);
|
||||
if (hfinfo == NULL) {
|
||||
FAIL(dfw, U, "%s is not a valid field", stnode_token(U));
|
||||
|
@ -218,7 +218,7 @@ entity(E) ::= reference(R). { E = R; }
|
|||
entity(E) ::= UNPARSED(U).
|
||||
{
|
||||
const char *token = stnode_token(U);
|
||||
const stloc_t *loc = stnode_location(U);
|
||||
df_loc_t loc = stnode_location(U);
|
||||
header_field_info *hfinfo = dfilter_resolve_unparsed(dfw, token);
|
||||
if (hfinfo != NULL) {
|
||||
E = stnode_new(STTYPE_FIELD, hfinfo, g_strdup(token), loc);
|
||||
|
@ -319,7 +319,7 @@ comparison_test(T) ::= arithmetic_expr(E) cmp_op(O) comparison_test(R).
|
|||
L = O;
|
||||
sttype_oper_set2_args(L, E, stnode_dup(F));
|
||||
|
||||
T = stnode_new(STTYPE_TEST, NULL, NULL, NULL);
|
||||
T = stnode_new_empty(STTYPE_TEST);
|
||||
sttype_oper_set2(T, STNODE_OP_AND, L, R);
|
||||
}
|
||||
|
||||
|
@ -366,7 +366,7 @@ relation(R) ::= ALL relation_test(T).
|
|||
|
||||
set(S) ::= LBRACE set_list(L) RBRACE.
|
||||
{
|
||||
S = stnode_new(STTYPE_SET, L, NULL, NULL);
|
||||
S = stnode_new(STTYPE_SET, L, NULL, DFILTER_LOC_EMPTY);
|
||||
}
|
||||
|
||||
set_list(L) ::= set_element(N).
|
||||
|
@ -411,7 +411,7 @@ set_element(N) ::= set_entity(X) DOTDOT set_entity(Y).
|
|||
|
||||
slice(R) ::= entity(E) LBRACKET range_node_list(L) RBRACKET.
|
||||
{
|
||||
R = stnode_new(STTYPE_SLICE, NULL, NULL, NULL);
|
||||
R = stnode_new(STTYPE_SLICE, NULL, NULL, DFILTER_LOC_EMPTY);
|
||||
sttype_slice_set(R, E, L);
|
||||
|
||||
/* Delete the list, but not the drange_nodes that
|
||||
|
|
|
@ -97,7 +97,7 @@ static gboolean parse_charconst(df_scanner_state_t *state, const char *s, unsign
|
|||
static void update_location(df_scanner_state_t *state, const char *text);
|
||||
static void update_string_loc(df_scanner_state_t *state, const char *text);
|
||||
|
||||
#define FAIL(...) dfilter_fail(yyextra->dfw, DF_ERROR_GENERIC, &yyextra->location, __VA_ARGS__)
|
||||
#define FAIL(...) dfilter_fail(yyextra->dfw, DF_ERROR_GENERIC, yyextra->location, __VA_ARGS__)
|
||||
|
||||
/*
|
||||
* Sleazy hack to suppress compiler warnings in yy_fatal_error().
|
||||
|
@ -501,14 +501,14 @@ update_string_loc(df_scanner_state_t *state, const char *text)
|
|||
static int
|
||||
set_lval_simple(df_scanner_state_t *state, int token, const char *token_value, sttype_id_t type_id)
|
||||
{
|
||||
stnode_init(df_lval, type_id, NULL, g_strdup(token_value), &state->location);
|
||||
stnode_init(df_lval, type_id, NULL, g_strdup(token_value), state->location);
|
||||
return token;
|
||||
}
|
||||
|
||||
static int
|
||||
set_lval_literal(df_scanner_state_t *state, const char *token_value)
|
||||
{
|
||||
stnode_init(df_lval, STTYPE_LITERAL, g_strdup(token_value), g_strdup(token_value), &state->location);
|
||||
stnode_init(df_lval, STTYPE_LITERAL, g_strdup(token_value), g_strdup(token_value), state->location);
|
||||
return TOKEN_LITERAL;
|
||||
}
|
||||
|
||||
|
@ -524,7 +524,7 @@ set_lval_quoted_string(df_scanner_state_t *state, GString *quoted_string)
|
|||
char *token_value;
|
||||
|
||||
token_value = ws_escape_string_len(NULL, quoted_string->str, quoted_string->len, true);
|
||||
stnode_init(df_lval, STTYPE_STRING, quoted_string, token_value, &state->string_loc);
|
||||
stnode_init(df_lval, STTYPE_STRING, quoted_string, token_value, state->string_loc);
|
||||
return TOKEN_STRING;
|
||||
}
|
||||
|
||||
|
@ -540,7 +540,7 @@ set_lval_charconst(df_scanner_state_t *state, GString *quoted_string)
|
|||
g_free(token_value);
|
||||
return SCAN_FAILED;
|
||||
}
|
||||
stnode_init(df_lval, STTYPE_CHARCONST, g_memdup2(&number, sizeof(number)), token_value, &state->string_loc);
|
||||
stnode_init(df_lval, STTYPE_CHARCONST, g_memdup2(&number, sizeof(number)), token_value, state->string_loc);
|
||||
return TOKEN_CHARCONST;
|
||||
}
|
||||
|
||||
|
@ -551,9 +551,9 @@ set_lval_field(df_scanner_state_t *state, const char *token_value)
|
|||
|
||||
hfinfo = dfilter_resolve_unparsed(state->dfw, token_value);
|
||||
if (hfinfo == NULL) {
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, &state->location, "\"%s\" is not a valid protocol or protocol field.", token_value);
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, state->location, "\"%s\" is not a valid protocol or protocol field.", token_value);
|
||||
}
|
||||
stnode_init(df_lval, STTYPE_FIELD, hfinfo, g_strdup(token_value), &state->location);
|
||||
stnode_init(df_lval, STTYPE_FIELD, hfinfo, g_strdup(token_value), state->location);
|
||||
return TOKEN_FIELD;
|
||||
}
|
||||
|
||||
|
@ -587,7 +587,7 @@ append_escaped_char(df_scanner_state_t *state, GString *str, char c)
|
|||
case '\"':
|
||||
break;
|
||||
default:
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, &state->location,
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, state->location,
|
||||
"\\%c is not a valid character escape sequence", c);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -657,7 +657,7 @@ append_universal_character_name(df_scanner_state_t *state, GString *str, const c
|
|||
gunichar val;
|
||||
|
||||
if (!parse_universal_character_name(state, ucn, NULL, &val)) {
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, &state->location, "%s is not a valid universal character name", ucn);
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, state->location, "%s is not a valid universal character name", ucn);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -675,7 +675,7 @@ parse_charconst(df_scanner_state_t *state, const char *s, unsigned long *valuep)
|
|||
|
||||
cp = s + 1; /* skip the leading ' */
|
||||
if (*cp == '\'') {
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, &state->string_loc, "Empty character constant.");
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, state->string_loc, "Empty character constant.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -691,7 +691,7 @@ parse_charconst(df_scanner_state_t *state, const char *s, unsigned long *valuep)
|
|||
switch (*cp) {
|
||||
|
||||
case '\0':
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, &state->string_loc, "%s isn't a valid character constant.", s);
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, state->string_loc, "%s isn't a valid character constant.", s);
|
||||
return FALSE;
|
||||
|
||||
case 'a':
|
||||
|
@ -752,7 +752,7 @@ parse_charconst(df_scanner_state_t *state, const char *s, unsigned long *valuep)
|
|||
else if (*cp >= 'a' && *cp <= 'f')
|
||||
value = 10 + (*cp - 'a');
|
||||
else {
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, &state->string_loc, "%s isn't a valid character constant.", s);
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, state->string_loc, "%s isn't a valid character constant.", s);
|
||||
return FALSE;
|
||||
}
|
||||
cp++;
|
||||
|
@ -765,7 +765,7 @@ parse_charconst(df_scanner_state_t *state, const char *s, unsigned long *valuep)
|
|||
else if (*cp >= 'a' && *cp <= 'f')
|
||||
value |= 10 + (*cp - 'a');
|
||||
else {
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, &state->string_loc, "%s isn't a valid character constant.", s);
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, state->string_loc, "%s isn't a valid character constant.", s);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -775,7 +775,7 @@ parse_charconst(df_scanner_state_t *state, const char *s, unsigned long *valuep)
|
|||
case 'u':
|
||||
case 'U':
|
||||
if (!parse_universal_character_name(state, s+1, &endptr, &unival)) {
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, &state->string_loc, "%s is not a valid universal character name", s);
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, state->string_loc, "%s is not a valid universal character name", s);
|
||||
return FALSE;
|
||||
}
|
||||
value = (unsigned long)unival;
|
||||
|
@ -787,7 +787,7 @@ parse_charconst(df_scanner_state_t *state, const char *s, unsigned long *valuep)
|
|||
if (*cp >= '0' && *cp <= '7')
|
||||
value = *cp - '0';
|
||||
else {
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, &state->string_loc, "%s isn't a valid character constant.", s);
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, state->string_loc, "%s isn't a valid character constant.", s);
|
||||
return FALSE;
|
||||
}
|
||||
if (*(cp + 1) != '\'') {
|
||||
|
@ -796,7 +796,7 @@ parse_charconst(df_scanner_state_t *state, const char *s, unsigned long *valuep)
|
|||
if (*cp >= '0' && *cp <= '7')
|
||||
value |= *cp - '0';
|
||||
else {
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, &state->string_loc, "%s isn't a valid character constant.", s);
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, state->string_loc, "%s isn't a valid character constant.", s);
|
||||
return FALSE;
|
||||
}
|
||||
if (*(cp + 1) != '\'') {
|
||||
|
@ -805,13 +805,13 @@ parse_charconst(df_scanner_state_t *state, const char *s, unsigned long *valuep)
|
|||
if (*cp >= '0' && *cp <= '7')
|
||||
value |= *cp - '0';
|
||||
else {
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, &state->string_loc, "%s isn't a valid character constant.", s);
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, state->string_loc, "%s isn't a valid character constant.", s);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (value > 0xFF) {
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, &state->string_loc, "%s is too large to be a valid character constant.", s);
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, state->string_loc, "%s is too large to be a valid character constant.", s);
|
||||
return FALSE;
|
||||
}
|
||||
cp++;
|
||||
|
@ -819,13 +819,13 @@ parse_charconst(df_scanner_state_t *state, const char *s, unsigned long *valuep)
|
|||
} else {
|
||||
value = *cp++;
|
||||
if (!g_ascii_isprint(value)) {
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, &state->string_loc, "Non-printable value '0x%02lx' in character constant.", value);
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, state->string_loc, "Non-printable value '0x%02lx' in character constant.", value);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if ((*cp != '\'') || (*(cp + 1) != '\0')){
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, &state->string_loc, "%s is too long to be a valid character constant.", s);
|
||||
dfilter_fail(state->dfw, DF_ERROR_GENERIC, state->string_loc, "%s is too long to be a valid character constant.", s);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,8 @@ static void
|
|||
semcheck(dfwork_t *dfw, stnode_t *st_node);
|
||||
|
||||
static fvalue_t *
|
||||
mk_fvalue_from_val_string(dfwork_t *dfw, header_field_info *hfinfo, const char *s);
|
||||
mk_fvalue_from_val_string(dfwork_t *dfw, header_field_info *hfinfo, const char *s,
|
||||
df_loc_t loc);
|
||||
|
||||
typedef gboolean (*FtypeCanFunc)(enum ftenum);
|
||||
|
||||
|
@ -178,7 +179,7 @@ dfilter_fvalue_from_literal(dfwork_t *dfw, ftenum_t ftype, stnode_t *st,
|
|||
|
||||
if (fv == NULL && hfinfo_value_string) {
|
||||
/* check value_string */
|
||||
fv = mk_fvalue_from_val_string(dfw, hfinfo_value_string, s);
|
||||
fv = mk_fvalue_from_val_string(dfw, hfinfo_value_string, s, stnode_location(st));
|
||||
/*
|
||||
* Ignore previous errors if this can be mapped
|
||||
* to an item from value_string.
|
||||
|
@ -209,7 +210,7 @@ dfilter_fvalue_from_string(dfwork_t *dfw, ftenum_t ftype, stnode_t *st,
|
|||
SET_ERROR(dfw, error_message);
|
||||
|
||||
if (fv == NULL && hfinfo_value_string) {
|
||||
fv = mk_fvalue_from_val_string(dfw, hfinfo_value_string, gs->str);
|
||||
fv = mk_fvalue_from_val_string(dfw, hfinfo_value_string, gs->str, stnode_location(st));
|
||||
/*
|
||||
* Ignore previous errors if this can be mapped
|
||||
* to an item from value_string.
|
||||
|
@ -254,7 +255,8 @@ mk_uint64_fvalue(guint64 val)
|
|||
* This works only for ftypes that are integers. Returns the created fvalue_t*
|
||||
* or NULL if impossible. */
|
||||
static fvalue_t*
|
||||
mk_fvalue_from_val_string(dfwork_t *dfw, header_field_info *hfinfo, const char *s)
|
||||
mk_fvalue_from_val_string(dfwork_t *dfw, header_field_info *hfinfo, const char *s,
|
||||
df_loc_t loc)
|
||||
{
|
||||
static const true_false_string default_tf = { "True", "False" };
|
||||
const true_false_string *tf = &default_tf;
|
||||
|
@ -333,7 +335,7 @@ mk_fvalue_from_val_string(dfwork_t *dfw, header_field_info *hfinfo, const char *
|
|||
* has already been set.
|
||||
*/
|
||||
dfw_error_clear(&dfw->error);
|
||||
dfilter_fail(dfw, DF_ERROR_GENERIC, NULL, "\"%s\" cannot be found among the possible values for %s.",
|
||||
dfilter_fail(dfw, DF_ERROR_GENERIC, loc, "\"%s\" cannot be found among the possible values for %s.",
|
||||
s, hfinfo->abbrev);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -341,7 +343,7 @@ mk_fvalue_from_val_string(dfwork_t *dfw, header_field_info *hfinfo, const char *
|
|||
|
||||
/* Do val_strings exist? */
|
||||
if (!hfinfo->strings) {
|
||||
dfilter_fail(dfw, DF_ERROR_GENERIC, NULL, "%s cannot accept strings as values.",
|
||||
dfilter_fail(dfw, DF_ERROR_GENERIC, loc, "%s cannot accept strings as values.",
|
||||
hfinfo->abbrev);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -352,7 +354,7 @@ mk_fvalue_from_val_string(dfwork_t *dfw, header_field_info *hfinfo, const char *
|
|||
dfw_error_clear(&dfw->error);
|
||||
|
||||
if (hfinfo->display & BASE_RANGE_STRING) {
|
||||
dfilter_fail(dfw, DF_ERROR_GENERIC, NULL, "\"%s\" cannot accept [range] strings as values.",
|
||||
dfilter_fail(dfw, DF_ERROR_GENERIC, loc, "\"%s\" cannot accept [range] strings as values.",
|
||||
hfinfo->abbrev);
|
||||
}
|
||||
else if (hfinfo->display & BASE_VAL64_STRING) {
|
||||
|
@ -364,7 +366,7 @@ mk_fvalue_from_val_string(dfwork_t *dfw, header_field_info *hfinfo, const char *
|
|||
}
|
||||
vals++;
|
||||
}
|
||||
dfilter_fail(dfw, DF_ERROR_GENERIC, NULL, "\"%s\" cannot be found among the possible values for %s.",
|
||||
dfilter_fail(dfw, DF_ERROR_GENERIC, loc, "\"%s\" cannot be found among the possible values for %s.",
|
||||
s, hfinfo->abbrev);
|
||||
}
|
||||
else if (hfinfo->display == BASE_CUSTOM) {
|
||||
|
@ -374,7 +376,7 @@ mk_fvalue_from_val_string(dfwork_t *dfw, header_field_info *hfinfo, const char *
|
|||
* integer, we have the string they're trying to match.
|
||||
* -><-
|
||||
*/
|
||||
dfilter_fail(dfw, DF_ERROR_GENERIC, NULL, "\"%s\" cannot accept [custom] strings as values.",
|
||||
dfilter_fail(dfw, DF_ERROR_GENERIC, loc, "\"%s\" cannot accept [custom] strings as values.",
|
||||
hfinfo->abbrev);
|
||||
}
|
||||
else {
|
||||
|
@ -388,7 +390,7 @@ mk_fvalue_from_val_string(dfwork_t *dfw, header_field_info *hfinfo, const char *
|
|||
}
|
||||
vals++;
|
||||
}
|
||||
dfilter_fail(dfw, DF_ERROR_GENERIC, NULL, "\"%s\" cannot be found among the possible values for %s.",
|
||||
dfilter_fail(dfw, DF_ERROR_GENERIC, loc, "\"%s\" cannot be found among the possible values for %s.",
|
||||
s, hfinfo->abbrev);
|
||||
}
|
||||
return NULL;
|
||||
|
@ -992,7 +994,7 @@ check_relation_matches(dfwork_t *dfw, stnode_t *st_node,
|
|||
|
||||
pcre = ws_regex_compile_ex(patt->str, patt->len, &errmsg, WS_REGEX_CASELESS|WS_REGEX_NEVER_UTF);
|
||||
if (errmsg) {
|
||||
dfilter_fail(dfw, DF_ERROR_GENERIC, NULL, "Regex compilation error: %s.", errmsg);
|
||||
dfilter_fail(dfw, DF_ERROR_GENERIC, stnode_location(st_arg2), "Regex compilation error: %s.", errmsg);
|
||||
g_free(errmsg);
|
||||
THROW(TypeError);
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ stnode_clear(stnode_t *node)
|
|||
}
|
||||
|
||||
void
|
||||
stnode_init(stnode_t *node, sttype_id_t type_id, gpointer data, char *token, const stloc_t *loc)
|
||||
stnode_init(stnode_t *node, sttype_id_t type_id, gpointer data, char *token, df_loc_t loc)
|
||||
{
|
||||
sttype_t *type;
|
||||
|
||||
|
@ -112,13 +112,7 @@ stnode_init(stnode_t *node, sttype_id_t type_id, gpointer data, char *token, con
|
|||
node->repr_display = NULL;
|
||||
node->repr_debug = NULL;
|
||||
node->repr_token = token;
|
||||
if (loc) {
|
||||
node->location = *loc;
|
||||
}
|
||||
else {
|
||||
node->location.col_start = -1;
|
||||
node->location.col_len = 0;
|
||||
}
|
||||
node->location = loc;
|
||||
|
||||
if (type_id == STTYPE_UNINITIALIZED) {
|
||||
node->type = NULL;
|
||||
|
@ -143,13 +137,13 @@ void
|
|||
stnode_replace(stnode_t *node, sttype_id_t type_id, gpointer data)
|
||||
{
|
||||
char *token = g_strdup(node->repr_token);
|
||||
stloc_t loc = node->location;
|
||||
df_loc_t loc = node->location;
|
||||
stnode_clear(node);
|
||||
stnode_init(node, type_id, data, token, &loc);
|
||||
stnode_init(node, type_id, data, token, loc);
|
||||
}
|
||||
|
||||
stnode_t*
|
||||
stnode_new(sttype_id_t type_id, gpointer data, char *token, const stloc_t *loc)
|
||||
stnode_new(sttype_id_t type_id, gpointer data, char *token, df_loc_t loc)
|
||||
{
|
||||
stnode_t *node;
|
||||
|
||||
|
@ -161,6 +155,13 @@ stnode_new(sttype_id_t type_id, gpointer data, char *token, const stloc_t *loc)
|
|||
return node;
|
||||
}
|
||||
|
||||
stnode_t*
|
||||
stnode_new_empty(sttype_id_t type_id)
|
||||
{
|
||||
df_loc_t loc = {-1, 0};
|
||||
return stnode_new(type_id, NULL, NULL, loc);
|
||||
}
|
||||
|
||||
stnode_t*
|
||||
stnode_dup(const stnode_t *node)
|
||||
{
|
||||
|
@ -243,10 +244,10 @@ stnode_token(stnode_t *node)
|
|||
return node->repr_token;
|
||||
}
|
||||
|
||||
stloc_t *
|
||||
df_loc_t
|
||||
stnode_location(stnode_t *node)
|
||||
{
|
||||
return &node->location;
|
||||
return node->location;
|
||||
}
|
||||
|
||||
#define IS_OPERATOR(node) \
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <wsutil/ws_assert.h>
|
||||
#include <wsutil/wslog.h>
|
||||
#include <epan/ftypes/ftypes.h>
|
||||
#include "dfilter-loc.h"
|
||||
|
||||
/** @file
|
||||
*/
|
||||
|
@ -53,11 +54,6 @@ typedef struct {
|
|||
STTypeToStrFunc func_tostr;
|
||||
} sttype_t;
|
||||
|
||||
typedef struct {
|
||||
long col_start;
|
||||
size_t col_len;
|
||||
} stloc_t;
|
||||
|
||||
/** Node (type instance) information */
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
|
@ -66,7 +62,7 @@ typedef struct {
|
|||
char *repr_token;
|
||||
char *repr_display;
|
||||
char *repr_debug;
|
||||
stloc_t location;
|
||||
df_loc_t location;
|
||||
} stnode_t;
|
||||
|
||||
typedef enum {
|
||||
|
@ -119,7 +115,10 @@ void
|
|||
sttype_register(sttype_t *type);
|
||||
|
||||
stnode_t*
|
||||
stnode_new(sttype_id_t type_id, gpointer data, char *token, const stloc_t *loc);
|
||||
stnode_new(sttype_id_t type_id, gpointer data, char *token, df_loc_t loc);
|
||||
|
||||
stnode_t*
|
||||
stnode_new_empty(sttype_id_t type_id);
|
||||
|
||||
stnode_t*
|
||||
stnode_dup(const stnode_t *org);
|
||||
|
@ -128,7 +127,7 @@ void
|
|||
stnode_clear(stnode_t *node);
|
||||
|
||||
void
|
||||
stnode_init(stnode_t *node, sttype_id_t type_id, gpointer data, char *token, const stloc_t *loc);
|
||||
stnode_init(stnode_t *node, sttype_id_t type_id, gpointer data, char *token, df_loc_t loc);
|
||||
|
||||
void
|
||||
stnode_replace(stnode_t *node, sttype_id_t type_id, gpointer data);
|
||||
|
@ -154,7 +153,7 @@ stnode_steal_data(stnode_t *node);
|
|||
const char *
|
||||
stnode_token(stnode_t *node);
|
||||
|
||||
stloc_t *
|
||||
df_loc_t
|
||||
stnode_location(stnode_t *node);
|
||||
|
||||
const char *
|
||||
|
|
Loading…
Reference in New Issue