Have fvalue_to_string_repr always return an (wmem) allocated buffer.
Previous patches converted all fvalue_to_string_repr calls to expect an allocated buffer (and not a passed in one). Now changing signature to force an allocated buffer. Added wmem in case that can be taken advantage of within epan (and since the function signature was changing anyway). Change-Id: Ica1ac4a9a182ce0e73303856329e198d9d525b7b Reviewed-on: https://code.wireshark.org/review/15343 Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
parent
931603c4b8
commit
1dccd1ee07
|
@ -55,7 +55,7 @@ void dump_dfilter_macro_t(const dfilter_macro_t *m, const char *function, const
|
|||
|
||||
static gboolean free_value(gpointer k _U_, gpointer v, gpointer u _U_) {
|
||||
fvt_cache_entry_t* e = (fvt_cache_entry_t*)v;
|
||||
g_free(e->repr);
|
||||
wmem_free(NULL, e->repr);
|
||||
g_free(e);
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ static gboolean fvt_cache_cb(proto_node * node, gpointer data _U_) {
|
|||
}
|
||||
e = g_new(fvt_cache_entry_t,1);
|
||||
e->name = finfo->hfinfo->abbrev,
|
||||
e->repr = fvalue_to_string_repr(&(finfo->value), FTREPR_DFILTER, finfo->hfinfo->display, NULL);
|
||||
e->repr = fvalue_to_string_repr(NULL, &(finfo->value), FTREPR_DFILTER, finfo->hfinfo->display);
|
||||
e->usable = TRUE;
|
||||
g_hash_table_insert(fvt_cache,(void*)finfo->hfinfo->abbrev,e);
|
||||
}
|
||||
|
|
|
@ -109,13 +109,13 @@ dfvm_dump(FILE *f, dfilter_t *df)
|
|||
|
||||
switch (insn->op) {
|
||||
case PUT_FVALUE:
|
||||
value_str = fvalue_to_string_repr(arg1->value.fvalue,
|
||||
FTREPR_DFILTER, BASE_NONE, NULL);
|
||||
value_str = fvalue_to_string_repr(NULL, arg1->value.fvalue,
|
||||
FTREPR_DFILTER, BASE_NONE);
|
||||
fprintf(f, "%05d PUT_FVALUE\t%s <%s> -> reg#%u\n",
|
||||
id, value_str,
|
||||
fvalue_type_name(arg1->value.fvalue),
|
||||
arg2->value.numeric);
|
||||
g_free(value_str);
|
||||
wmem_free(NULL, value_str);
|
||||
break;
|
||||
case CHECK_EXISTS:
|
||||
case READ_TREE:
|
||||
|
|
|
@ -376,21 +376,22 @@ fvalue_string_repr_len(fvalue_t *fv, ftrepr_t rtype, int field_display)
|
|||
}
|
||||
|
||||
char *
|
||||
fvalue_to_string_repr(fvalue_t *fv, ftrepr_t rtype, int field_display, char *buf)
|
||||
fvalue_to_string_repr(wmem_allocator_t *scope, fvalue_t *fv, ftrepr_t rtype, int field_display)
|
||||
{
|
||||
char *buf;
|
||||
int len;
|
||||
if (fv->ftype->val_to_string_repr == NULL) {
|
||||
/* no value-to-string-representation function, so the value cannot be represented */
|
||||
return NULL;
|
||||
}
|
||||
if (!buf) {
|
||||
int len;
|
||||
if ((len = fvalue_string_repr_len(fv, rtype, field_display)) >= 0) {
|
||||
buf = (char *)g_malloc0(len + 1);
|
||||
} else {
|
||||
/* the value cannot be represented in the given representation type (rtype) */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((len = fvalue_string_repr_len(fv, rtype, field_display)) >= 0) {
|
||||
buf = (char *)wmem_alloc0(scope, len + 1);
|
||||
} else {
|
||||
/* the value cannot be represented in the given representation type (rtype) */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fv->ftype->val_to_string_repr(fv, rtype, field_display, buf);
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#define __FTYPES_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include "../wmem/wmem.h"
|
||||
#include "ws_symbol_export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -256,20 +257,15 @@ int
|
|||
fvalue_string_repr_len(fvalue_t *fv, ftrepr_t rtype, int field_display);
|
||||
|
||||
/* Creates the string representation of the field value.
|
||||
* If given non-NULL 'buf', the string is written at the memory
|
||||
* location pointed to by 'buf'. If 'buf' is NULL, new memory
|
||||
* is malloc'ed and the string representation is written there.
|
||||
* The pointer to the beginning of the string representation is
|
||||
* returned. If 'buf' was NULL, this points to the newly-allocated
|
||||
* memory. if 'buf' was non-NULL, then the return value will be
|
||||
* 'buf'.
|
||||
* Memory for the buffer is allocated based on wmem allocator
|
||||
* provided.
|
||||
*
|
||||
* field_display parameter should be a BASE_ value (enum field_display_e)
|
||||
* BASE_NONE should be used if field information isn't available.
|
||||
*
|
||||
* Returns NULL if the string cannot be represented in the given rtype.*/
|
||||
WS_DLL_PUBLIC char *
|
||||
fvalue_to_string_repr(fvalue_t *fv, ftrepr_t rtype, int field_display, char *buf);
|
||||
fvalue_to_string_repr(wmem_allocator_t *scope, fvalue_t *fv, ftrepr_t rtype, int field_display);
|
||||
|
||||
WS_DLL_PUBLIC ftenum_t
|
||||
fvalue_type_ftenum(fvalue_t *fv);
|
||||
|
|
10
epan/print.c
10
epan/print.c
|
@ -404,13 +404,13 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
|
|||
fputs("\" show=\"\" value=\"", pdata->fh);
|
||||
break;
|
||||
default:
|
||||
dfilter_string = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, fi->hfinfo->display, NULL);
|
||||
dfilter_string = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, fi->hfinfo->display);
|
||||
if (dfilter_string != NULL) {
|
||||
|
||||
fputs("\" show=\"", pdata->fh);
|
||||
print_escaped_xml(pdata->fh, dfilter_string);
|
||||
}
|
||||
g_free(dfilter_string);
|
||||
wmem_free(NULL, dfilter_string);
|
||||
|
||||
/*
|
||||
* XXX - should we omit "value" for any fields?
|
||||
|
@ -1439,9 +1439,11 @@ gchar* get_node_field_value(field_info* fi, epan_dissect_t* edt)
|
|||
* FT_NONE can be checked when using -T fields */
|
||||
return g_strdup("1");
|
||||
default:
|
||||
dfilter_string = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, fi->hfinfo->display, NULL);
|
||||
dfilter_string = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, fi->hfinfo->display);
|
||||
if (dfilter_string != NULL) {
|
||||
return dfilter_string;
|
||||
gchar* ret = g_strdup(dfilter_string);
|
||||
wmem_free(NULL, dfilter_string);
|
||||
return ret;
|
||||
} else {
|
||||
return get_field_hex_value(edt->pi.data_src, fi);
|
||||
}
|
||||
|
|
22
epan/proto.c
22
epan/proto.c
|
@ -5232,21 +5232,21 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence,
|
|||
break;
|
||||
|
||||
case FT_IEEE_11073_SFLOAT:
|
||||
str = fvalue_to_string_repr(&finfo->value, FTREPR_DISPLAY, hfinfo->display, NULL);
|
||||
str = fvalue_to_string_repr(NULL, &finfo->value, FTREPR_DISPLAY, hfinfo->display);
|
||||
g_snprintf(result+offset_r, size-offset_r,
|
||||
"%s: %s",
|
||||
hfinfo->name, str);
|
||||
g_free(str);
|
||||
wmem_free(NULL, str);
|
||||
offset_r = (int)strlen(result);
|
||||
break;
|
||||
|
||||
case FT_IEEE_11073_FLOAT:
|
||||
str = fvalue_to_string_repr(&finfo->value, FTREPR_DISPLAY, hfinfo->display, NULL);
|
||||
str = fvalue_to_string_repr(NULL, &finfo->value, FTREPR_DISPLAY, hfinfo->display);
|
||||
g_snprintf(result+offset_r, size-offset_r,
|
||||
"%s: %s",
|
||||
hfinfo->name, str);
|
||||
offset_r = (int)strlen(result);
|
||||
g_free(str);
|
||||
wmem_free(NULL, str);
|
||||
break;
|
||||
|
||||
case FT_IPXNET: /*XXX really No column custom ?*/
|
||||
|
@ -7322,18 +7322,18 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
|
|||
break;
|
||||
|
||||
case FT_IEEE_11073_SFLOAT:
|
||||
tmp = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, hfinfo->display, NULL);
|
||||
tmp = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, hfinfo->display);
|
||||
g_snprintf(label_str, ITEM_LABEL_LENGTH,
|
||||
"%s: %s",
|
||||
hfinfo->name, tmp);
|
||||
g_free(tmp);
|
||||
wmem_free(NULL, tmp);
|
||||
break;
|
||||
case FT_IEEE_11073_FLOAT:
|
||||
tmp = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, hfinfo->display, NULL);
|
||||
tmp = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, hfinfo->display);
|
||||
g_snprintf(label_str, ITEM_LABEL_LENGTH,
|
||||
"%s: %s",
|
||||
hfinfo->name, tmp);
|
||||
g_free(tmp);
|
||||
wmem_free(NULL, tmp);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -8832,16 +8832,16 @@ construct_match_selected_string(field_info *finfo, epan_dissect_t *edt,
|
|||
* 1 byte for trailing NUL.
|
||||
*/
|
||||
if (filter != NULL) {
|
||||
char* str;
|
||||
char* str;
|
||||
dfilter_len = fvalue_string_repr_len(&finfo->value,
|
||||
FTREPR_DFILTER, finfo->hfinfo->display);
|
||||
dfilter_len += abbrev_len + 4 + 1;
|
||||
*filter = (char *)wmem_alloc0(NULL, dfilter_len);
|
||||
|
||||
/* Create the string */
|
||||
str = fvalue_to_string_repr(&finfo->value, FTREPR_DFILTER, finfo->hfinfo->display, NULL);
|
||||
str = fvalue_to_string_repr(NULL, &finfo->value, FTREPR_DFILTER, finfo->hfinfo->display);
|
||||
g_snprintf(*filter, dfilter_len, "%s == %s", hfinfo->abbrev, str);
|
||||
g_free(str);
|
||||
wmem_free(NULL, str);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -161,12 +161,16 @@ WSLUA_METAMETHOD FieldInfo__call(lua_State* L) {
|
|||
}
|
||||
case FT_STRING:
|
||||
case FT_STRINGZ: {
|
||||
gchar* repr = fvalue_to_string_repr(&fi->ws_fi->value,FTREPR_DISPLAY,BASE_NONE,NULL);
|
||||
gchar* repr = fvalue_to_string_repr(NULL, &fi->ws_fi->value,FTREPR_DISPLAY,BASE_NONE);
|
||||
if (repr)
|
||||
lua_pushstring(L,repr);
|
||||
{
|
||||
lua_pushstring(L, repr);
|
||||
wmem_free(NULL, repr);
|
||||
}
|
||||
else
|
||||
{
|
||||
luaL_error(L,"field cannot be represented as string because it may contain invalid characters");
|
||||
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
case FT_NONE:
|
||||
|
@ -215,16 +219,16 @@ WSLUA_METAMETHOD FieldInfo__tostring(lua_State* L) {
|
|||
gchar* repr = NULL;
|
||||
|
||||
if (fi->ws_fi->hfinfo->type == FT_PROTOCOL || fi->ws_fi->hfinfo->type == FT_PCRE) {
|
||||
repr = fvalue_to_string_repr(&fi->ws_fi->value,FTREPR_DFILTER,BASE_NONE,NULL);
|
||||
repr = fvalue_to_string_repr(NULL, &fi->ws_fi->value,FTREPR_DFILTER,BASE_NONE);
|
||||
}
|
||||
else {
|
||||
repr = fvalue_to_string_repr(&fi->ws_fi->value,FTREPR_DISPLAY,fi->ws_fi->hfinfo->display,NULL);
|
||||
repr = fvalue_to_string_repr(NULL, &fi->ws_fi->value,FTREPR_DISPLAY,fi->ws_fi->hfinfo->display);
|
||||
}
|
||||
|
||||
if (repr) {
|
||||
lua_pushstring(L,repr);
|
||||
/* fvalue_to_string_repr() g_malloc's the string's buffer */
|
||||
g_free(repr);
|
||||
/* fvalue_to_string_repr() wmem_alloc's the string's buffer */
|
||||
wmem_free(NULL, repr);
|
||||
}
|
||||
else {
|
||||
lua_pushstring(L,"(unknown)");
|
||||
|
|
|
@ -313,11 +313,11 @@ extern AVP* new_avp_from_finfo(const gchar* name, field_info* finfo) {
|
|||
|
||||
new_avp_val->n = scs_subscribe(avp_strings, name);
|
||||
|
||||
repr = fvalue_to_string_repr(&finfo->value,FTREPR_DISPLAY,finfo->hfinfo->display,NULL);
|
||||
repr = fvalue_to_string_repr(NULL, &finfo->value,FTREPR_DISPLAY,finfo->hfinfo->display);
|
||||
|
||||
if (repr) {
|
||||
value = scs_subscribe(avp_strings, repr);
|
||||
g_free(repr);
|
||||
wmem_free(NULL, repr);
|
||||
#ifdef _AVP_DEBUGGING
|
||||
dbg_print (dbg_avp,2,dbg_fp,"new_avp_from_finfo: from string: %s",value);
|
||||
#endif
|
||||
|
|
|
@ -1189,9 +1189,8 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index)
|
|||
* e.g: ip.hdr_len
|
||||
*/
|
||||
fs_len = fvalue_string_repr_len(&finfo->value, FTREPR_DFILTER, finfo->hfinfo->display);
|
||||
fs_buf = fvalue_to_string_repr(&finfo->value,
|
||||
FTREPR_DFILTER, finfo->hfinfo->display,
|
||||
NULL);
|
||||
fs_buf = fvalue_to_string_repr(NULL, &finfo->value,
|
||||
FTREPR_DFILTER, finfo->hfinfo->display);
|
||||
fs_ptr = fs_buf;
|
||||
|
||||
/* String types are quoted. Remove them. */
|
||||
|
@ -1280,14 +1279,14 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index)
|
|||
}
|
||||
}
|
||||
printf(" %d=\"%s\"", cmd_line_index, label_s->str);
|
||||
g_free(fs_buf);
|
||||
wmem_free(NULL, fs_buf);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if(finfo->value.ftype->val_to_string_repr)
|
||||
{
|
||||
printf(" %d=\"%s\"", cmd_line_index, fs_ptr);
|
||||
g_free(fs_buf);
|
||||
wmem_free(NULL, fs_buf);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,11 +106,11 @@ diam_tree_to_csv(proto_node *node, gpointer data)
|
|||
ftype = fvalue_type_ftenum(&fi->value);
|
||||
if (ftype != FT_NONE && ftype != FT_PROTOCOL) {
|
||||
/* convert value to string */
|
||||
val_tmp = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, hfi->display, NULL);
|
||||
val_tmp = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, hfi->display);
|
||||
if (val_tmp)
|
||||
{
|
||||
val_str = g_strdup(val_tmp);
|
||||
g_free(val_tmp);
|
||||
wmem_free(NULL, val_tmp);
|
||||
} else
|
||||
val_str = g_strdup_printf("unsupported type: %s", ftype_name(ftype));
|
||||
|
||||
|
|
|
@ -1334,10 +1334,10 @@ tree_view_follow_link(field_info *fi)
|
|||
cf_goto_frame(&cfile, fi->value.value.uinteger);
|
||||
}
|
||||
if(FI_GET_FLAG(fi, FI_URL) && IS_FT_STRING(fi->hfinfo->type)) {
|
||||
url = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, fi->hfinfo->display, NULL);
|
||||
url = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, fi->hfinfo->display);
|
||||
if(url){
|
||||
browser_open_url(url);
|
||||
g_free(url);
|
||||
wmem_free(NULL, url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -582,11 +582,11 @@ void ProtoTree::itemDoubleClick(QTreeWidgetItem *item, int) {
|
|||
|
||||
if(FI_GET_FLAG(fi, FI_URL) && IS_FT_STRING(fi->hfinfo->type)) {
|
||||
gchar *url;
|
||||
url = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, fi->hfinfo->display, NULL);
|
||||
url = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, fi->hfinfo->display);
|
||||
if(url){
|
||||
// browser_open_url(url);
|
||||
QDesktopServices::openUrl(QUrl(url));
|
||||
g_free(url);
|
||||
wmem_free(NULL, url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue