From 2497482e34a108275f75cd8106e1841b35aab98e Mon Sep 17 00:00:00 2001 From: Jeff Morriss Date: Wed, 3 Sep 2014 21:57:02 -0400 Subject: [PATCH] Don't print non-printable characters in AX.25 addresses. Add a new routine to wsutil to make this easy: printable_char_or_period(). Bug: 10439 Change-Id: I0eb2bb6bc0676a1035c3d845b5e20276fa04de60 Reviewed-on: https://code.wireshark.org/review/3981 Petri-Dish: Alexis La Goutte Reviewed-by: Alexis La Goutte Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- epan/address_to_str.c | 9 +++++++-- wsutil/str_util.c | 10 +++++++++- wsutil/str_util.h | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/epan/address_to_str.c b/epan/address_to_str.c index 15dd8cd599..ac3be78b5a 100644 --- a/epan/address_to_str.c +++ b/epan/address_to_str.c @@ -54,6 +54,7 @@ #include "value_string.h" #include "addr_resolv.h" #include "wsutil/pint.h" +#include "wsutil/str_util.h" #include "atalk-utils.h" #include "sna-utils.h" #include "osi-utils.h" @@ -628,8 +629,12 @@ address_to_str_buf(const address *addr, gchar *buf, int buf_len) case AT_AX25: addrdata = (const guint8 *)addr->data; g_snprintf(buf, buf_len, "%c%c%c%c%c%c-%02d", - (addrdata[0] >> 1) & 0x7f, (addrdata[1] >> 1) & 0x7f, (addrdata[2] >> 1) & 0x7f, - (addrdata[3] >> 1) & 0x7f, (addrdata[4] >> 1) & 0x7f, (addrdata[5] >> 1) & 0x7f, + printable_char_or_period(addrdata[0] >> 1), + printable_char_or_period(addrdata[1] >> 1), + printable_char_or_period(addrdata[2] >> 1), + printable_char_or_period(addrdata[3] >> 1), + printable_char_or_period(addrdata[4] >> 1), + printable_char_or_period(addrdata[5] >> 1), (addrdata[6] >> 1) & 0x0f ); break; case AT_IEEE_802_15_4_SHORT: diff --git a/wsutil/str_util.c b/wsutil/str_util.c index c171edfa6e..83558c156d 100644 --- a/wsutil/str_util.c +++ b/wsutil/str_util.c @@ -123,7 +123,9 @@ isdigit_string(guchar *str) #endif /* Given a size, return its value in a human-readable format */ -gchar *format_size(gint64 size, format_size_flags_e flags) { +gchar * +format_size(gint64 size, format_size_flags_e flags) +{ GString *human_str = g_string_new(""); int power = 1000; int pfx_off = 0; @@ -178,3 +180,9 @@ gchar *format_size(gint64 size, format_size_flags_e flags) { g_string_free(human_str, FALSE); return g_strchomp(ret_val); } + +gchar +printable_char_or_period(gchar c) +{ + return g_ascii_isprint(c) ? c : '.'; +} diff --git a/wsutil/str_util.h b/wsutil/str_util.h index 971fa3542d..43a60dca9d 100644 --- a/wsutil/str_util.h +++ b/wsutil/str_util.h @@ -110,6 +110,8 @@ typedef enum { WS_DLL_PUBLIC gchar *format_size(gint64 size, format_size_flags_e flags); +WS_DLL_PUBLIC +gchar printable_char_or_period(gchar c); #ifdef __cplusplus }