diff options
author | João Valverde <j@v6e.pt> | 2022-10-17 18:30:51 +0100 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2022-10-18 19:51:38 +0100 |
commit | 4136b250c593da2ef8a4ef8444ce4b6ae23e30b3 (patch) | |
tree | 30de8ae4c6d07fc05c54c1fa2673e6d4bc738426 | |
parent | e4d5a440144969493f01c20f23f11b0f59f2a5bc (diff) |
epan: Rename tvb_get_nstringz0()
Rename tvb_get_nstringz0() to tvb_get_raw_bytes_as_stringz()
to reflect the fact that this function does not return
a string (UTF-8 internal text string).
Remove tvb_get_stringz() because it is unused and just seems
dangerous.
-rw-r--r-- | epan/dissectors/packet-megaco.c | 12 | ||||
-rw-r--r-- | epan/tvbuff.c | 33 | ||||
-rw-r--r-- | epan/tvbuff.h | 23 |
3 files changed, 14 insertions, 54 deletions
diff --git a/epan/dissectors/packet-megaco.c b/epan/dissectors/packet-megaco.c index 806f36bbe5..7e774dd403 100644 --- a/epan/dissectors/packet-megaco.c +++ b/epan/dissectors/packet-megaco.c @@ -640,7 +640,7 @@ dissect_megaco_text(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* d * * tvb_offset = tvb_find_guint8(tvb, tvb_offset, 5, 'M'); */ - if(!tvb_get_nstringz0(tvb,tvb_offset,sizeof(word),word)) return tvb_captured_length(tvb); + if(!tvb_get_raw_bytes_as_stringz(tvb,tvb_offset,sizeof(word),word)) return tvb_captured_length(tvb); /* Quick fix for MEGACO packet with Authentication Header, * marked as "AU" or "Authentication". @@ -1484,11 +1484,11 @@ nextcontext: expert_add_info_format(pinfo, sub_ti, &ei_megaco_parse_error, "Parse error: Invalid TermID length (%d)", tokenlen+1); return tvb_captured_length(tvb); } - bytelen = tvb_get_nstringz0(tvb,tvb_offset,tokenlen+1,TermID); + bytelen = tvb_get_raw_bytes_as_stringz(tvb,tvb_offset,tokenlen+1,TermID); TermID[0] = 'e'; term->buffer = get_utf_8_string(wmem_packet_scope(), TermID, bytelen); - term->len = strlen(term->buffer); + term->len = (int)strlen(term->buffer); term->str = (const char *)term->buffer; gcp_cmd_add_term(msg, trx, cmd, term, wild_term, pinfo, keep_persistent_data); @@ -2460,7 +2460,7 @@ dissect_megaco_servicechangedescriptor(tvbuff_t *tvb, packet_info* pinfo, proto_ if ( tvb_current_offset == -1) break; - tvb_get_nstringz0(tvb,tvb_current_offset,4,ServiceChangeReason_str); + tvb_get_raw_bytes_as_stringz(tvb,tvb_current_offset,4,ServiceChangeReason_str); reason_valid = ws_strtoi32(ServiceChangeReason_str, NULL, &reason); proto_item_append_text(item,"[ %s ]", val_to_str(reason, MEGACO_ServiceChangeReasons_vals,"Unknown (%u)")); if (!reason_valid) @@ -2919,7 +2919,7 @@ dissect_megaco_errordescriptor(tvbuff_t *tvb, packet_info* pinfo, proto_tree *me error_tree = proto_item_add_subtree(item, ett_megaco_error_descriptor); /* Get the error code */ - tvb_get_nstringz0(tvb,tvb_current_offset,4,error); + tvb_get_raw_bytes_as_stringz(tvb,tvb_current_offset,4,error); error_code_valid = ws_strtoi32(error, NULL, &error_code); item = proto_tree_add_uint(error_tree, hf_megaco_error_code, tvb, tvb_current_offset, 3, error_code); if (!error_code_valid) @@ -3275,7 +3275,7 @@ dissect_megaco_LocalControldescriptor(tvbuff_t *tvb, proto_tree *megaco_mediades break; case MEGACO_DS_DSCP: - tvb_get_nstringz0(tvb,tvb_current_offset,3,code_str); + tvb_get_raw_bytes_as_stringz(tvb,tvb_current_offset,3,code_str); item = proto_tree_add_uint(megaco_LocalControl_tree, hf_megaco_ds_dscp, tvb, tvb_help_offset, 1, (guint32) strtoul(code_str,NULL,16)); proto_item_set_len(item, tvb_offset-tvb_help_offset); diff --git a/epan/tvbuff.c b/epan/tvbuff.c index 8b2ae215ec..81502d2531 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -3751,7 +3751,7 @@ tvb_get_stringz_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, g * including the terminating-NUL. */ static gint -_tvb_get_nstringz(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8* buffer, gint *bytes_copied) +_tvb_get_raw_bytes_as_stringz(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8* buffer, gint *bytes_copied) { gint stringlen; guint abs_offset = 0; @@ -3818,41 +3818,14 @@ _tvb_get_nstringz(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8* return stringlen; } -/* Looks for a stringz (NUL-terminated string) in tvbuff and copies - * no more than bufsize number of bytes, including terminating NUL, to buffer. - * Returns length of string (not including terminating NUL), or -1 if the string was - * truncated in the buffer due to not having reached the terminating NUL. - * In this way, it acts like snprintf(). - * - * When processing a packet where the remaining number of bytes is less - * than bufsize, an exception is not thrown if the end of the packet - * is reached before the NUL is found. If no NUL is found before reaching - * the end of the short packet, -1 is still returned, and the string - * is truncated with a NUL, albeit not at buffer[bufsize - 1], but - * at the correct spot, terminating the string. - */ -gint -tvb_get_nstringz(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8 *buffer) -{ - gint bytes_copied; - - DISSECTOR_ASSERT(tvb && tvb->initialized); - - return _tvb_get_nstringz(tvb, offset, bufsize, buffer, &bytes_copied); -} - -/* Like tvb_get_nstringz(), but never returns -1. The string is guaranteed to - * have a terminating NUL. If the string was truncated when copied into buffer, - * a NUL is placed at the end of buffer to terminate it. - */ gint -tvb_get_nstringz0(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8* buffer) +tvb_get_raw_bytes_as_stringz(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8* buffer) { gint len, bytes_copied; DISSECTOR_ASSERT(tvb && tvb->initialized); - len = _tvb_get_nstringz(tvb, offset, bufsize, buffer, &bytes_copied); + len = _tvb_get_raw_bytes_as_stringz(tvb, offset, bufsize, buffer, &bytes_copied); if (len == -1) { buffer[bufsize - 1] = 0; diff --git a/epan/tvbuff.h b/epan/tvbuff.h index dfd57adaaa..4791183502 100644 --- a/epan/tvbuff.h +++ b/epan/tvbuff.h @@ -783,29 +783,16 @@ 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 +/** Looks for a NUL byte in tvbuff and copies * no more than bufsize number of bytes, including terminating NUL, to buffer. - * Returns length of string (not including terminating NUL), or -1 if the - * string was truncated in the buffer due to not having reached the terminating - * NUL. In this way, it acts like snprintf(). + * Returns number of bytes copied (not including terminating NUL). * * When processing a packet where the remaining number of bytes is less * than bufsize, an exception is not thrown if the end of the packet - * is reached before the NUL is found. If no NUL is found before reaching - * the end of the short packet, -1 is still returned, and the string - * is truncated with a NUL, albeit not at buffer[bufsize - 1], but - * at the correct spot, terminating the string. + * is reached before the NUL is found. The byte buffer is guaranteed to + * have a terminating NUL. */ -WS_DLL_PUBLIC gint tvb_get_nstringz(tvbuff_t *tvb, const gint offset, - const guint bufsize, guint8 *buffer); - -/** Like tvb_get_nstringz(), but never returns -1. The string is guaranteed to - * have a terminating NUL. If the string was truncated when copied into buffer, - * a NUL is placed at the end of buffer to terminate it. - * - * bufsize MUST be greater than 0. - */ -WS_DLL_PUBLIC gint tvb_get_nstringz0(tvbuff_t *tvb, const gint offset, +WS_DLL_PUBLIC gint tvb_get_raw_bytes_as_stringz(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8 *buffer); /* |