Wireshark-bugs: [Wireshark-bugs] [Bug 7810] New: Explicitly declare/cast 'unsigned <variable>' a

Date: Mon, 8 Oct 2012 09:25:12 -0700 (PDT)
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7810

           Summary: Explicitly declare/cast 'unsigned <variable>' as
                    'unsigned int <variable>'
           Product: Wireshark
           Version: 1.8.2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Minor
          Priority: Low
         Component: Wireshark
        AssignedTo: bugzilla-admin@xxxxxxxxxxxxx
        ReportedBy: wp02855@xxxxxxxxx


Created attachment 9304
  --> https://bugs.wireshark.org/bugzilla/attachment.cgi?id=9304
Patch files for wireshark 1.8.2 generated by diff -u

Build Information:
N/A
--
In reviewing variable declarations and casts used in Wireshark 1.8.2,
I found some instances where the declaration of 'unsigned <foo>' was
used, and in some places 'unsigned int <foo>' is used.  The patches
below are designed to explicitly define 'unsigned <foo>' as 
'unsigned int <foo>' so that consistency is maintained.

I know that in C the definition of 'unsigned <foo>' is the same
as 'unsigned int <foo>', but in the code, the bulk of the variable
declarations and casts are of the form 'unsigned int <foo>'.

In Wireshark 1.8.2/1.8.3 modifications are needed in files:

capture-pcap-util-unix.c

--- capture-pcap-util-unix.c.orig       2012-10-07 18:35:58.509881535 -0700
+++ capture-pcap-util-unix.c    2012-10-07 18:36:22.430415853 -0700
@@ -153,7 +153,7 @@
                                goto fail;
                        }
                } else {
-                       if ((unsigned) ifc.ifc_len < sizeof(struct ifreq)) {
+                       if ((unsigned int) ifc.ifc_len < sizeof(struct ifreq))
{
                                if (err_str != NULL) {
                                        *err_str = g_strdup(
                                            "Can't get list of interfaces:
SIOCGIFCONF ioctl gave too small return buffer");

editcap.c

--- editcap.c.orig      2012-10-07 18:38:08.699641612 -0700
+++ editcap.c   2012-10-07 18:38:41.204076462 -0700
@@ -824,7 +824,7 @@
   int choplen = 0;                      /* No chop                */
   wtap_dumper *pdh = NULL;
   int count = 1;
-  unsigned duplicate_count = 0;
+  unsigned int duplicate_count = 0;
   gint64 data_offset;
   struct wtap_pkthdr snap_phdr;
   const struct wtap_pkthdr *phdr;

mpeg-pes/packet-mpeg-pes-template.c

--- packet-mpeg-pes-template.c.orig     2012-10-07 18:46:17.238266085 -0700
+++ packet-mpeg-pes-template.c  2012-10-07 18:47:41.104129525 -0700
@@ -169,7 +169,7 @@
                (bytes >> 33 & 0x0007) << 30 |
                (bytes >> 17 & 0x7fff) << 15 |
                (bytes >>  1 & 0x7fff) << 0;
-       unsigned rem = (unsigned)(ts % TSHZ);
+       unsigned int rem = (unsigned int)(ts % TSHZ);
        nst->secs = (time_t)(ts / TSHZ);
        nst->nsecs = (int)(G_GINT64_CONSTANT(1000000000) * rem / TSHZ);
        return ts;
@@ -185,9 +185,9 @@
                (bytes >> 43 & 0x0007) << 30 |
                (bytes >> 27 & 0x7fff) << 15 |
                (bytes >> 11 & 0x7fff) << 0;
-       unsigned ext = (unsigned)((bytes >> 1) & 0x1ff);
+       unsigned int ext = (unsigned int)((bytes >> 1) & 0x1ff);
        guint64 cr = 300 * ts + ext;
-       unsigned rem = (unsigned)(cr % SCRHZ);
+       unsigned int rem = (unsigned int)(cr % SCRHZ);
        nst->secs = (time_t)(cr / SCRHZ);
        nst->nsecs = (int)(G_GINT64_CONSTANT(1000000000) * rem / SCRHZ);
        return cr;
@@ -195,7 +195,7 @@

 static int
 dissect_mpeg_pes_header_data(tvbuff_t *tvb, packet_info *pinfo,
-               proto_tree *root, unsigned flags)
+               proto_tree *root, unsigned int flags)
 {
        proto_item *item = proto_tree_add_item(root, hf_mpeg_pes_header_data,
tvb,
                        0, -1, ENC_NA);
@@ -238,7 +238,7 @@
                offset += 6;
        }
        if (flags & ES_RATE_FLAG) {
-               unsigned es_rate = (tvb_get_ntohs(tvb, offset) >> 1 & 0x3fff) *
50;
+               unsigned int es_rate = (tvb_get_ntohs(tvb, offset) >> 1 &
0x3fff) * 50;
                proto_tree_add_uint(tree, hf_mpeg_pes_es_rate, tvb,
                                offset, 3, es_rate);
                offset += 3;
@@ -332,7 +332,7 @@
                        offset += 2;
                }
                if (flags2 & PSTD_BUFFER_FLAG) {
-                       unsigned pstd = tvb_get_ntohs(tvb, offset);
+                       unsigned int pstd = tvb_get_ntohs(tvb, offset);
                        proto_tree_add_uint(tree, hf_mpeg_pes_pstd_buffer, tvb,
                                        offset, 2, (pstd & 0x2000 ? 1024 : 128)
* (pstd & 0x1ff));
                        offset += 2;
@@ -350,7 +350,7 @@
 dissect_mpeg_pes_pack_header(tvbuff_t *tvb, gint offset,
                packet_info *pinfo, proto_tree *root)
 {
-       unsigned program_mux_rate, stuffing_length;
+       unsigned int program_mux_rate, stuffing_length;

        proto_item *item = proto_tree_add_item(root, hf_mpeg_pes_pack_header,
tvb,
                        offset / 8, 10, ENC_NA);
@@ -471,7 +471,7 @@
                                        offset / 8, 8, ENC_NA);
                }
        } else if (stream == STREAM_SYSTEM || stream == STREAM_PRIVATE2) {
-               unsigned data_length = tvb_get_ntohs(tvb, offset / 8);
+               unsigned int data_length = tvb_get_ntohs(tvb, offset / 8);
                proto_tree_add_item(tree, hf_mpeg_pes_length, tvb,
                                offset / 8, 2, ENC_BIG_ENDIAN);
                offset += 2 * 8;
@@ -479,7 +479,7 @@
                proto_tree_add_item(tree, hf_mpeg_pes_data, tvb,
                                offset / 8, data_length, ENC_NA);
        } else if (stream == STREAM_PADDING) {
-               unsigned padding_length = tvb_get_ntohs(tvb, offset / 8);
+               unsigned int padding_length = tvb_get_ntohs(tvb, offset / 8);
                proto_tree_add_item(tree, hf_mpeg_pes_length, tvb,
                                offset / 8, 2, ENC_BIG_ENDIAN);
                offset += 2 * 8;
@@ -534,7 +534,7 @@
                                proto_tree_add_item(tree, hf_mpeg_pes_data, es,
                                                0, -1, ENC_NA);
                } else {
-                       unsigned data_length = tvb_get_ntohs(tvb, offset / 8);
+                       unsigned int data_length = tvb_get_ntohs(tvb, offset /
8);
                        proto_tree_add_item(tree, hf_mpeg_pes_length, tvb,
                                        offset / 8, 2, ENC_BIG_ENDIAN);
                        offset += 2 * 8;

snmp/packet-snmp-template.c:

--- packet-snmp-template.c.orig 2012-10-07 18:49:17.821348972 -0700
+++ packet-snmp-template.c      2012-10-07 18:50:06.437482742 -0700
@@ -756,8 +756,8 @@
                        case BER_CLASS_UNI|(BER_UNI_TAG_INTEGER<<4):
                        {
                                gint64 val=0;
-                               unsigned int_val_offset = value_offset;
-                               unsigned i;
+                               unsigned int int_val_offset = value_offset;
+                               unsigned int i;

                                max_len = 4; min_len = 1;
                                if (value_len > (guint)max_len || value_len <
(guint)min_len) {
@@ -2004,7 +2004,7 @@
 {
        snmp_ue_assoc_t* ue = (snmp_ue_assoc_t*)p;
        GString* es = g_string_new("");
-       unsigned i;
+       unsigned int i;

        *err = NULL;

spnego/packet-spnego-template.c:

--- packet-spnego-template.c.orig       2012-10-07 18:51:28.306140869 -0700
+++ packet-spnego-template.c    2012-10-07 18:52:17.338318607 -0700
@@ -380,7 +380,7 @@

 static int
 arcfour_mic_cksum(guint8 *key_data, int key_length,
-                 unsigned usage,
+                 unsigned int usage,
                  guint8 sgn_cksum[8],
                  const void *v1, size_t l1,
                  const void *v2, size_t l2,

The attached tarball contains all of the patch files listed above.

odie:/usr/local/src/patchfiles/wireshark-1.8.2 # tar tvf unsigned.tar.gz 
-rw-r--r-- root/root       453 2012-10-07 18:37 capture-pcap-util-unix.c.patch
-rw-r--r-- root/root       402 2012-10-07 18:38 editcap.c.patch
-rw-r--r-- root/root      3252 2012-10-07 18:48
packet-mpeg-pes-template.c.patch
-rw-r--r-- root/root       614 2012-10-07 18:50 packet-snmp-template.c.patch
-rw-r--r-- root/root       358 2012-10-07 18:57 packet-spnego-template.c.patch

Bill Parker

-- 
Configure bugmail: https://bugs.wireshark.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.