From 1a2aa0e901e38d8abcd0368c500f8990f866783b Mon Sep 17 00:00:00 2001 From: Martin Boye Petersen Date: Tue, 30 Oct 2018 11:54:33 +0100 Subject: [PATCH] to_str: Fixed incorrect order of checks in bytestring_to_str. Issue revealed by commit 281dd22da96daa105580bf25f064ddfdc99a719d. The commit that revealed the issue allowed bytestring_to_str to be called when len was 0 and *ad was NULL causing a dissector bug to be reported. Change-Id: I01c2c04154e0514dc2702b5c1c43ed5074d0ac11 Reviewed-on: https://code.wireshark.org/review/30421 Reviewed-by: Anders Broman Petri-Dish: Anders Broman Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu --- epan/to_str.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/epan/to_str.c b/epan/to_str.c index dd8ada4d8a..b6ac76ce92 100644 --- a/epan/to_str.c +++ b/epan/to_str.c @@ -188,14 +188,14 @@ bytestring_to_str(wmem_allocator_t *scope, const guint8 *ad, const guint32 len, gchar *buf_ptr; int truncated = 0; - if (!punct) - return bytes_to_str(scope, ad, len); + if (len == 0) + return wmem_strdup(scope, ""); if (!ad) REPORT_DISSECTOR_BUG("Null pointer passed to bytestring_to_str()"); - if (len == 0) - return wmem_strdup(scope, ""); + if (!punct) + return bytes_to_str(scope, ad, len); buf=(gchar *)wmem_alloc(scope, MAX_BYTE_STR_LEN+3+1); if (buflen > MAX_BYTE_STR_LEN/3) { /* bd_len > 16 */