aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/asn1
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2018-10-20 17:46:34 -0400
committerAnders Broman <a.broman58@gmail.com>2018-10-21 07:55:40 +0000
commit7a4e9325718e13e5d977677032f211c93e91aba9 (patch)
tree202cbefec4c9a64ff6de997bf6554d36d5e35ec6 /epan/dissectors/asn1
parent7ce9081fdcf48085611d2de6db0964dffd9ae700 (diff)
Add tvb_ascii_isprint API
This allows dissectors to check if a portion of the tvb is an ascii string while hiding the use of tvb_get_ptr. Change-Id: Iaec7559dcfdefb8a5ae23e099ced45e90e611f8f Reviewed-on: https://code.wireshark.org/review/30291 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/dissectors/asn1')
-rw-r--r--epan/dissectors/asn1/dap/dap.cnf8
-rw-r--r--epan/dissectors/asn1/ldap/ldap.cnf9
-rw-r--r--epan/dissectors/asn1/ldap/packet-ldap-template.c21
-rw-r--r--epan/dissectors/asn1/s1ap/s1ap.cnf18
4 files changed, 9 insertions, 47 deletions
diff --git a/epan/dissectors/asn1/dap/dap.cnf b/epan/dissectors/asn1/dap/dap.cnf
index c20d57af02..d4e7a98e75 100644
--- a/epan/dissectors/asn1/dap/dap.cnf
+++ b/epan/dissectors/asn1/dap/dap.cnf
@@ -290,13 +290,9 @@ OPERATION.&ResultType
%(DEFAULT_BODY)s
if(out_tvb) {
- len = tvb_reported_length(out_tvb);
/* now see if we can add a string representation */
- for(i=0; i<len; i++)
- if(!g_ascii_isprint(tvb_get_guint8(out_tvb, i)))
- break;
-
- if(i == len) {
+ len = tvb_reported_length(out_tvb);
+ if(tvb_ascii_isprint(out_tvb, 0, len)) {
if(actx->created_item) {
proto_item_append_text(actx->created_item," (");
diff --git a/epan/dissectors/asn1/ldap/ldap.cnf b/epan/dissectors/asn1/ldap/ldap.cnf
index 624c311208..67a2d4a7ba 100644
--- a/epan/dissectors/asn1/ldap/ldap.cnf
+++ b/epan/dissectors/asn1/ldap/ldap.cnf
@@ -450,7 +450,6 @@ ldap_conv_info_t *ldap_info;
tvbuff_t *next_tvb = NULL;
gchar *string;
- guint32 i, len;
int old_offset = offset;
gint *hf_id;
@@ -470,13 +469,7 @@ ldap_conv_info_t *ldap_info;
/* do the default thing */
%(DEFAULT_BODY)s
- len = tvb_reported_length_remaining(next_tvb, 0);
-
- for(i = 0; i < len; i++)
- if(!g_ascii_isprint(tvb_get_guint8(next_tvb, i)))
- break;
-
- if(i == len) {
+ if(tvb_ascii_isprint(next_tvb, 0, tvb_reported_length(next_tvb))) {
string = tvb_get_string_enc(wmem_packet_scope(), next_tvb, 0, tvb_reported_length_remaining(next_tvb, 0), ENC_ASCII|ENC_NA);
proto_item_set_text(actx->created_item, "AttributeValue: %%s", string);
}
diff --git a/epan/dissectors/asn1/ldap/packet-ldap-template.c b/epan/dissectors/asn1/ldap/packet-ldap-template.c
index 7bdcb2bd96..01132effdb 100644
--- a/epan/dissectors/asn1/ldap/packet-ldap-template.c
+++ b/epan/dissectors/asn1/ldap/packet-ldap-template.c
@@ -633,8 +633,7 @@ dissect_ldap_AssertionValue(gboolean implicit_tag, tvbuff_t *tvb, int offset, as
gint8 ber_class;
gboolean pc, ind, is_ascii;
gint32 tag;
- guint32 len, i;
- const guchar *str;
+ guint32 len;
if(!implicit_tag){
offset=get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
@@ -711,25 +710,13 @@ dissect_ldap_AssertionValue(gboolean implicit_tag, tvbuff_t *tvb, int offset, as
* -- I don't think there are full schemas available that describe the
* interesting cases i.e. AD -- ronnie
*/
- str=tvb_get_ptr(tvb, offset, len);
- is_ascii=TRUE;
- for(i=0;i<len;i++){
- if(!g_ascii_isprint(str[i])){
- is_ascii=FALSE;
- break;
- }
- }
+ is_ascii=tvb_ascii_isprint(tvb, offset, len);
/* convert the string into a printable string */
if(is_ascii){
- ldapvalue_string=wmem_strndup(wmem_packet_scope(), str, len);
+ ldapvalue_string= tvb_get_string_enc(wmem_packet_scope(), tvb, offset, len, ENC_ASCII);
} else {
- ldapvalue_string=(char*)wmem_alloc(wmem_packet_scope(), 3*len);
- for(i=0;i<len;i++){
- g_snprintf(ldapvalue_string+i*3,3,"%02x",str[i]&0xff);
- ldapvalue_string[3*i+2]=':';
- }
- ldapvalue_string[3*len-1]=0;
+ ldapvalue_string= tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, len, ':');
}
proto_tree_add_string(tree, hf_index, tvb, offset, len, ldapvalue_string);
diff --git a/epan/dissectors/asn1/s1ap/s1ap.cnf b/epan/dissectors/asn1/s1ap/s1ap.cnf
index c22f71ba79..f0585435ad 100644
--- a/epan/dissectors/asn1/s1ap/s1ap.cnf
+++ b/epan/dissectors/asn1/s1ap/s1ap.cnf
@@ -243,7 +243,6 @@ MAX_VAL = asn1_param_get_integer(%(ACTX)s,"upperBound")
#.FN_BODY ENBname VAL_PTR = parameter_tvb
tvbuff_t *parameter_tvb=NULL;
int length;
- int p_offset;
gboolean is_ascii;
%(DEFAULT_BODY)s
@@ -253,20 +252,13 @@ MAX_VAL = asn1_param_get_integer(%(ACTX)s,"upperBound")
length = tvb_reported_length(parameter_tvb);
- is_ascii = TRUE;
- for (p_offset=0; p_offset < length; p_offset++){
- if(!g_ascii_isprint(tvb_get_guint8(parameter_tvb, p_offset ))){
- is_ascii = FALSE;
- break;
- }
- }
+ is_ascii = tvb_ascii_isprint(parameter_tvb, 0, length);
if (is_ascii)
proto_item_append_text(actx->created_item," (%%s)",tvb_format_text(parameter_tvb, 0, length));
#.FN_BODY MMEname VAL_PTR = parameter_tvb
tvbuff_t *parameter_tvb=NULL;
int length;
- int p_offset;
gboolean is_ascii;
%(DEFAULT_BODY)s
@@ -276,13 +268,7 @@ MAX_VAL = asn1_param_get_integer(%(ACTX)s,"upperBound")
length = tvb_reported_length(parameter_tvb);
- is_ascii = TRUE;
- for (p_offset=0; p_offset < length; p_offset++){
- if(!g_ascii_isprint(tvb_get_guint8(parameter_tvb, p_offset ))){
- is_ascii = FALSE;
- break;
- }
- }
+ is_ascii = tvb_ascii_isprint(parameter_tvb, 0, length);
if (is_ascii)
proto_item_append_text(actx->created_item," (%%s)",tvb_format_text(parameter_tvb, 0, length));