From 597f020793bdbfa7fc3d9f6b86a596da61e4171f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Mon, 3 Oct 2022 22:03:07 +0100 Subject: [PATCH] epan: Mark tvb_get_const_stringz() as deprecated The function tvb_get_const_stringz() does not check for a string encoding and returns a pointer to a byte array. For this reason it should not be used. Prefer other functions that return a valid UTF-8 string from a source encoding or use tvb_get_ptr() to fetch a byte pointer. --- doc/README.dissector | 14 -------------- epan/tvbuff.h | 10 +++++++++- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/doc/README.dissector b/doc/README.dissector index cf1f0b7b78..6a28b63e4a 100644 --- a/doc/README.dissector +++ b/doc/README.dissector @@ -463,20 +463,6 @@ the string, including the terminating null. The buffer is allocated in the given wmem scope (see README.wmem for more information). -const guint8 *tvb_get_const_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp); - -Returns a null-terminated const buffer containing data from the -specified tvbuff, starting at the specified offset, and containing all -bytes from the tvbuff up to and including a terminating null character -in the tvbuff. "*lengthp" will be set to the length of the string, -including the terminating null. - -You do not need to free() this buffer; it will happen automatically once -the next packet is dissected. This function is slightly more efficient -than the others because it does not allocate memory and copy the string, -but it does not do any mapping to UTF-8 or checks for valid octet -sequences. - gint tvb_get_nstringz(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8* buffer); gint tvb_get_nstringz0(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8* buffer); diff --git a/epan/tvbuff.h b/epan/tvbuff.h index 1946e9a9df..dbc2e4c96f 100644 --- a/epan/tvbuff.h +++ b/epan/tvbuff.h @@ -771,8 +771,16 @@ WS_DLL_PUBLIC guint8 *tvb_get_stringz_enc(wmem_allocator_t *scope, * of the string, in whatever encoding they happen to be in, and, if * the string is not valid in that encoding, with invalid octet sequences * as they are in the packet. + * + * This function is deprecated because it does no validation of the string + * encoding. Do not use in new code. Prefer other APIs such as: + * tvb_get_stringz_enc() + * proto_tree_add_item_ret_string_and_length() + * tvb_strsize() and validate the pointed to memory region manually. */ -WS_DLL_PUBLIC const guint8 *tvb_get_const_stringz(tvbuff_t *tvb, +WS_DLL_PUBLIC +WS_DEPRECATED_X("Use APIs that return a valid UTF-8 string instead") +const guint8 *tvb_get_const_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp); /** Looks for a stringz (NUL-terminated string) in tvbuff and copies