diff options
author | Michael Mann <mmann78@netscape.net> | 2016-05-10 16:37:44 -0400 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2016-05-10 22:49:25 +0000 |
commit | 4d3df66af44b563a1c6d6fe03fcdf09f93877dba (patch) | |
tree | a9d9927c9c20bfdc0b304f439a024b34fd55eac3 /epan/ftypes | |
parent | 1dccd1ee072722fbe6d5e1a9d726a7e87d191f76 (diff) | |
download | wireshark-4d3df66af44b563a1c6d6fe03fcdf09f93877dba.tar.gz |
Give FvalueToStringRepr a length parameter.
This allows the conversion of a few straggler strcpy calls
in ftype library. Also provides a more accurate size value
instead of the many hard coded values the ftypes were using.
Change-Id: Ia6273980432e16ad3a6233816a6054d9fed5d2a4
Reviewed-on: https://code.wireshark.org/review/15344
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/ftypes')
-rw-r--r-- | epan/ftypes/ftype-bytes.c | 10 | ||||
-rw-r--r-- | epan/ftypes/ftype-double.c | 8 | ||||
-rw-r--r-- | epan/ftypes/ftype-guid.c | 10 | ||||
-rw-r--r-- | epan/ftypes/ftype-ieee-11073-float.c | 28 | ||||
-rw-r--r-- | epan/ftypes/ftype-integer.c | 28 | ||||
-rw-r--r-- | epan/ftypes/ftype-ipv4.c | 2 | ||||
-rw-r--r-- | epan/ftypes/ftype-ipv6.c | 2 | ||||
-rw-r--r-- | epan/ftypes/ftype-pcre.c | 4 | ||||
-rw-r--r-- | epan/ftypes/ftype-protocol.c | 2 | ||||
-rw-r--r-- | epan/ftypes/ftype-string.c | 4 | ||||
-rw-r--r-- | epan/ftypes/ftype-time.c | 8 | ||||
-rw-r--r-- | epan/ftypes/ftypes-int.h | 2 | ||||
-rw-r--r-- | epan/ftypes/ftypes.c | 2 |
13 files changed, 55 insertions, 55 deletions
diff --git a/epan/ftypes/ftype-bytes.c b/epan/ftypes/ftype-bytes.c index f5c1b74857..cd005a9341 100644 --- a/epan/ftypes/ftype-bytes.c +++ b/epan/ftypes/ftype-bytes.c @@ -95,7 +95,7 @@ oid_repr_len(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_) } static void -oid_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf) +oid_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size _U_) { char* oid_str = oid_encoded2string(NULL, fv->value.bytes->data,fv->value.bytes->len); /* @@ -116,7 +116,7 @@ rel_oid_repr_len(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_) } static void -rel_oid_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf) +rel_oid_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size _U_) { char* oid_str = rel_oid_encoded2string(NULL, fv->value.bytes->data,fv->value.bytes->len); /* @@ -132,13 +132,13 @@ rel_oid_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *b } static void -system_id_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display, char *buf) +system_id_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size) { - print_system_id_buf(fv->value.bytes->data,fv->value.bytes->len, buf, bytes_repr_len(fv, rtype, field_display)); + print_system_id_buf(fv->value.bytes->data,fv->value.bytes->len, buf, size); } static void -bytes_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display, char *buf) +bytes_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display, char *buf, unsigned int size _U_) { char separator; diff --git a/epan/ftypes/ftype-double.c b/epan/ftypes/ftype-double.c index 5a0812f1cb..68a75314db 100644 --- a/epan/ftypes/ftype-double.c +++ b/epan/ftypes/ftype-double.c @@ -95,9 +95,9 @@ float_val_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_) } static void -float_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf) +float_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size) { - g_snprintf(buf, DOUBLE_REPR_LENGTH, "%." G_STRINGIFY(FLT_DIG) "g", fv->value.floating); + g_snprintf(buf, size, "%." G_STRINGIFY(FLT_DIG) "g", fv->value.floating); } static int @@ -113,9 +113,9 @@ double_val_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_) } static void -double_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf) +double_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size) { - g_snprintf(buf, DOUBLE_REPR_LENGTH, "%." G_STRINGIFY(DBL_DIG) "g", fv->value.floating); + g_snprintf(buf, size, "%." G_STRINGIFY(DBL_DIG) "g", fv->value.floating); } static gboolean diff --git a/epan/ftypes/ftype-guid.c b/epan/ftypes/ftype-guid.c index f5731032ee..ac5d521d2a 100644 --- a/epan/ftypes/ftype-guid.c +++ b/epan/ftypes/ftype-guid.c @@ -61,15 +61,15 @@ get_guid(const char *s, e_guid_t *guid) } p = s; - strncpy(digits, p, 8); + g_strlcpy(digits, p, 8); digits[8] = '\0'; guid->data1 = (guint32)strtoul(digits, NULL, 16); p += 9; - strncpy(digits, p, 4); + g_strlcpy(digits, p, 4); digits[4] = '\0'; guid->data2 = (guint16)strtoul(digits, NULL, 16); p += 5; - strncpy(digits, p, 4); + g_strlcpy(digits, p, 4); digits[4] = '\0'; guid->data3 = (guint16)strtoul(digits, NULL, 16); p += 5; @@ -105,9 +105,9 @@ guid_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_) } static void -guid_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf) +guid_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size) { - guid_to_str_buf(&fv->value.guid, buf, GUID_STR_LEN); + guid_to_str_buf(&fv->value.guid, buf, size); } static gboolean diff --git a/epan/ftypes/ftype-ieee-11073-float.c b/epan/ftypes/ftype-ieee-11073-float.c index 2a976308cc..e8b652dfca 100644 --- a/epan/ftypes/ftype-ieee-11073-float.c +++ b/epan/ftypes/ftype-ieee-11073-float.c @@ -213,7 +213,7 @@ sfloat_ieee_11073_val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_ } static void -sfloat_ieee_11073_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf) +sfloat_ieee_11073_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size) { gint8 exponent; guint16 mantissa; @@ -225,19 +225,19 @@ sfloat_ieee_11073_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_displa if (fv->value.sfloat_ieee_11073 >= 0x07FE && fv->value.sfloat_ieee_11073 <= 0x0802) { switch (fv->value.sfloat_ieee_11073) { case SFLOAT_VALUE_INFINITY_PLUS: - g_snprintf(buf, 10, "+INFINITY"); + g_strlcpy(buf, "+INFINITY", size); break; case SFLOAT_VALUE_NAN: - g_snprintf(buf, 4, "NaN"); + g_strlcpy(buf, "NaN", size); break; case SFLOAT_VALUE_NRES: - g_snprintf(buf, 5, "NRes"); + g_strlcpy(buf, "NRes", size); break; case SFLOAT_VALUE_RFU: - g_snprintf(buf, 4, "RFU"); + g_strlcpy(buf, "RFU", size); break; case SFLOAT_VALUE_INFINITY_MINUS: - g_snprintf(buf, 10, "-INFINITY"); + g_strlcpy(buf, "-INFINITY", size); break; } } @@ -262,7 +262,7 @@ sfloat_ieee_11073_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_displa offset += 1; } - mantissa_digits = g_snprintf(mantissa_str, 5, "%u", mantissa); + mantissa_digits = g_snprintf(mantissa_str, size, "%u", mantissa); if (exponent == 0) { memcpy(buf + offset, mantissa_str, mantissa_digits); @@ -908,7 +908,7 @@ float_ieee_11073_val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_p } static void -float_ieee_11073_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf) +float_ieee_11073_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size) { gint8 exponent; guint32 mantissa; @@ -920,19 +920,19 @@ float_ieee_11073_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display if (fv->value.float_ieee_11073 >= 0x007FFFFE && fv->value.float_ieee_11073 <= 0x00800002) { switch (fv->value.float_ieee_11073) { case FLOAT_VALUE_INFINITY_PLUS: - g_snprintf(buf, 10, "+INFINITY"); + g_strlcpy(buf, "+INFINITY", size); break; case FLOAT_VALUE_NAN: - g_snprintf(buf, 4, "NaN"); + g_strlcpy(buf, "NaN", size); break; case FLOAT_VALUE_NRES: - g_snprintf(buf, 5, "NRes"); + g_strlcpy(buf, "NRes", size); break; case FLOAT_VALUE_RFU: - g_snprintf(buf, 4, "RFU"); + g_strlcpy(buf, "RFU", size); break; case FLOAT_VALUE_INFINITY_MINUS: - g_snprintf(buf, 10, "-INFINITY"); + g_strlcpy(buf, "-INFINITY", size); break; } } @@ -956,7 +956,7 @@ float_ieee_11073_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display offset += 1; } - mantissa_digits = g_snprintf(mantissa_str, 9, "%u", mantissa); + mantissa_digits = g_snprintf(mantissa_str, size, "%u", mantissa); if (exponent == 0) { memcpy(buf + offset, mantissa_str, mantissa_digits); diff --git a/epan/ftypes/ftype-integer.c b/epan/ftypes/ftype-integer.c index 2df16a6cd3..c7aae0403b 100644 --- a/epan/ftypes/ftype-integer.c +++ b/epan/ftypes/ftype-integer.c @@ -230,7 +230,7 @@ integer_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_) } static void -integer_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf) +integer_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size) { guint32 val; @@ -240,7 +240,7 @@ integer_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *b } else val = fv->value.sinteger; - guint32_to_str_buf(val, buf, 11); + guint32_to_str_buf(val, buf, size); } static int @@ -250,7 +250,7 @@ uinteger_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_) } static void -uinteger_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display, char *buf) +uinteger_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display, char *buf, unsigned int size) { if ((field_display == BASE_HEX) || (field_display == BASE_HEX_DEC)) { @@ -263,7 +263,7 @@ uinteger_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display, char *buf) } else { - guint32_to_str_buf(fv->value.uinteger, buf, 11); + guint32_to_str_buf(fv->value.uinteger, buf, size); } } @@ -300,9 +300,9 @@ ipxnet_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_) } static void -ipxnet_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char *buf) +ipxnet_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char *buf, unsigned int size) { - uinteger_to_repr(fv, rtype, BASE_HEX, buf); + uinteger_to_repr(fv, rtype, BASE_HEX, buf, size); } static gboolean @@ -567,7 +567,7 @@ integer64_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_) } static void -integer64_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf) +integer64_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size) { guint64 val; @@ -577,7 +577,7 @@ integer64_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char } else val = fv->value.sinteger64; - guint64_to_str_buf(val, buf, 20); + guint64_to_str_buf(val, buf, size); } static int @@ -587,7 +587,7 @@ uinteger64_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_) } static void -uinteger64_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display, char *buf) +uinteger64_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display, char *buf, unsigned int size) { if ((field_display == BASE_HEX) || (field_display == BASE_HEX_DEC)) { @@ -600,7 +600,7 @@ uinteger64_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display, char *bu } else { - guint64_to_str_buf(fv->value.uinteger64, buf, 21); + guint64_to_str_buf(fv->value.uinteger64, buf, size); } } @@ -685,7 +685,7 @@ boolean_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_) } static void -boolean_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf) +boolean_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size _U_) { *buf++ = (fv->value.uinteger64) ? '1' : '0'; *buf = '\0'; @@ -758,11 +758,11 @@ eui64_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U static int eui64_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_) { - return 8*3-1; /* XX:XX:XX:XX:XX:XX:XX:XX */ + return EUI64_STR_LEN; /* XX:XX:XX:XX:XX:XX:XX:XX */ } static void -eui64_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf) +eui64_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size) { union { guint64 value; @@ -772,7 +772,7 @@ eui64_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf /* Copy and convert the address from host to network byte order. */ eui64.value = GUINT64_TO_BE(fv->value.integer64); - g_snprintf(buf, EUI64_STR_LEN, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", + g_snprintf(buf, size, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", eui64.bytes[0], eui64.bytes[1], eui64.bytes[2], eui64.bytes[3], eui64.bytes[4], eui64.bytes[5], eui64.bytes[6], eui64.bytes[7]); } diff --git a/epan/ftypes/ftype-ipv4.c b/epan/ftypes/ftype-ipv4.c index 12b1ec00fe..188a0981ac 100644 --- a/epan/ftypes/ftype-ipv4.c +++ b/epan/ftypes/ftype-ipv4.c @@ -117,7 +117,7 @@ val_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_) } static void -val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf) +val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size _U_) { ipv4_addr_and_mask_str_buf(&fv->value.ipv4, buf); } diff --git a/epan/ftypes/ftype-ipv6.c b/epan/ftypes/ftype-ipv6.c index 9540fb25ca..39b45578fc 100644 --- a/epan/ftypes/ftype-ipv6.c +++ b/epan/ftypes/ftype-ipv6.c @@ -100,7 +100,7 @@ ipv6_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_) } static void -ipv6_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf) +ipv6_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size _U_) { ip6_to_str_buf(&(fv->value.ipv6.addr), buf); } diff --git a/epan/ftypes/ftype-pcre.c b/epan/ftypes/ftype-pcre.c index e0ed16ab84..efde63ef9c 100644 --- a/epan/ftypes/ftype-pcre.c +++ b/epan/ftypes/ftype-pcre.c @@ -125,10 +125,10 @@ gregex_repr_len(fvalue_t *fv, ftrepr_t rtype, int field_display _U_) } static void -gregex_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char *buf) +gregex_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char *buf, unsigned int size) { g_assert(rtype == FTREPR_DFILTER); - strcpy(buf, g_regex_get_pattern(fv->value.re)); + g_strlcpy(buf, g_regex_get_pattern(fv->value.re), size); } /* BEHOLD - value contains the string representation of the regular expression, diff --git a/epan/ftypes/ftype-protocol.c b/epan/ftypes/ftype-protocol.c index 35c449a701..49bf4fb9ff 100644 --- a/epan/ftypes/ftype-protocol.c +++ b/epan/ftypes/ftype-protocol.c @@ -142,7 +142,7 @@ val_repr_len(fvalue_t *fv, ftrepr_t rtype, int field_display _U_) } static void -val_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char * volatile buf) +val_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char * volatile buf, unsigned int size _U_) { guint length; diff --git a/epan/ftypes/ftype-string.c b/epan/ftypes/ftype-string.c index f952d01453..49f21bdd8b 100644 --- a/epan/ftypes/ftype-string.c +++ b/epan/ftypes/ftype-string.c @@ -66,11 +66,11 @@ string_repr_len(fvalue_t *fv, ftrepr_t rtype, int field_display _U_) } static void -string_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char *buf) +string_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char *buf, unsigned int size) { switch (rtype) { case FTREPR_DISPLAY: - strcpy(buf, fv->value.string); + g_strlcpy(buf, fv->value.string, size); return; case FTREPR_DFILTER: diff --git a/epan/ftypes/ftype-time.c b/epan/ftypes/ftype-time.c index c36bf14d5c..f9d057bd44 100644 --- a/epan/ftypes/ftype-time.c +++ b/epan/ftypes/ftype-time.c @@ -339,7 +339,7 @@ absolute_val_repr_len(fvalue_t *fv, ftrepr_t rtype, int field_display _U_) } static void -absolute_val_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char *buf) +absolute_val_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char *buf, unsigned int size) { gchar *rep = abs_time_to_str(NULL, &fv->value.time, ABSOLUTE_TIME_LOCAL, rtype == FTREPR_DISPLAY); @@ -347,7 +347,7 @@ absolute_val_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char * *buf++ = '\"'; } - strcpy(buf, rep); + g_strlcpy(buf, rep, size); if (rtype == FTREPR_DFILTER) { buf += strlen(rep); @@ -371,11 +371,11 @@ relative_val_repr_len(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_) } static void -relative_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf) +relative_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size) { gchar *rep; rep = rel_time_to_secs_str(NULL, &fv->value.time); - strcpy(buf, rep); + g_strlcpy(buf, rep, size); wmem_free(NULL, rep); } diff --git a/epan/ftypes/ftypes-int.h b/epan/ftypes/ftypes-int.h index fc35fee8f1..0a4da87183 100644 --- a/epan/ftypes/ftypes-int.h +++ b/epan/ftypes/ftypes-int.h @@ -51,7 +51,7 @@ typedef void (*FvalueFreeFunc)(fvalue_t*); typedef gboolean (*FvalueFromUnparsed)(fvalue_t*, const char*, gboolean, gchar **); typedef gboolean (*FvalueFromString)(fvalue_t*, const char*, gchar **); -typedef void (*FvalueToStringRepr)(fvalue_t*, ftrepr_t, int field_display, char*volatile); +typedef void (*FvalueToStringRepr)(fvalue_t*, ftrepr_t, int field_display, char*volatile, unsigned int); typedef int (*FvalueStringReprLen)(fvalue_t*, ftrepr_t, int field_display); typedef void (*FvalueSetByteArrayFunc)(fvalue_t*, GByteArray *); diff --git a/epan/ftypes/ftypes.c b/epan/ftypes/ftypes.c index 6f57620ad1..4ad8f317be 100644 --- a/epan/ftypes/ftypes.c +++ b/epan/ftypes/ftypes.c @@ -392,7 +392,7 @@ fvalue_to_string_repr(wmem_allocator_t *scope, fvalue_t *fv, ftrepr_t rtype, int return NULL; } - fv->ftype->val_to_string_repr(fv, rtype, field_display, buf); + fv->ftype->val_to_string_repr(fv, rtype, field_display, buf, (unsigned int)len+1); return buf; } |