Text   |  XML   |  ReML   |   Visible Warnings:

Useless Assignment  at netmon.c:279

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

netmon_open

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/netmon.c)expand/collapse
Show more  
 122  int netmon_open(wtap *wth, int *err, gchar **err_info)
 123  {
 124          int bytes_read;
 125          char magic[sizeof netmon_1_x_magic];
 126          struct netmon_hdr hdr;
 127          int file_type;
 128          static const int netmon_encap[] = {
 129                  WTAP_ENCAP_UNKNOWN,
 130                  WTAP_ENCAP_ETHERNET,
 131                  WTAP_ENCAP_TOKEN_RING,
 132                  WTAP_ENCAP_FDDI_BITSWAPPED,
 133
143
Show [ Lines 133 to 143 omitted. ]
 144          int frame_table_offset;
 145          guint32 frame_table_length;
 146          guint32 frame_table_size;
 147          guint32 *frame_table;
 148  #ifdef WORDS_BIGENDIAN 
 149          unsigned int i;
 150  #endif
 151   
 152          /* Read in the string that should be at the start of a Network 
 153           * Monitor file */
 154          errno = WTAP_ERR_CANT_READ;
 155          bytes_read = file_read(magic, 1, sizeof magic, wth->fh);
 156          if (bytes_read != sizeof magic) {
 157                  *err = file_error(wth->fh);
 158                  if (*err != 0)
 159                          return -1;
 160                  return 0;
 161          }
 162   
 163          if (memcmp(magic, netmon_1_x_magic, sizeof netmon_1_x_magic) != 0 
 164           && memcmp(magic, netmon_2_x_magic, sizeof netmon_1_x_magic) != 0) {
 165                  return 0;
 166          }
 167   
 168          /* Read the rest of the header. */
 169          errno = WTAP_ERR_CANT_READ;
 170          bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh);
 171          if (bytes_read != sizeof hdr) {
 172                  *err = file_error(wth->fh);
 173                  if (*err != 0)
 174                          return -1;
 175                  return 0;
 176          }
 177   
 178          switch (hdr.ver_major) {
 179   
 180          case 1:
 181                  file_type = WTAP_FILE_NETMON_1_x;
 182                  break;
 183   
 184          case 2:
 185                  file_type = WTAP_FILE_NETMON_2_x;
 186                  break;
 187   
 188          default:
 189                  *err = WTAP_ERR_UNSUPPORTED;
 190                  *err_info = g_strdup_printf("netmon: major version %u unsupported", hdr.ver_major);
 191                  return -1;
 192          }
 193   
 194          hdr.network = pletohs(&hdr.network);
 195          if (hdr.network >= NUM_NETMON_ENCAPS 
 196              || netmon_encap[hdr.network] == WTAP_ENCAP_UNKNOWN) {
 197                  *err = WTAP_ERR_UNSUPPORTED_ENCAP;
 198                  *err_info = g_strdup_printf("netmon: network type %u unknown or unsupported",
 199                      hdr.network);
 200                  return -1;
 201          }
 202   
 203          /* This is a netmon file */
 204          wth->file_type = file_type;
 205          wth->capture.netmon = g_malloc(sizeof(netmon_t));
 206          wth->subtype_read = netmon_read;
 207          wth->subtype_seek_read = netmon_seek_read;
 208          wth->subtype_sequential_close = netmon_sequential_close;
 209          wth->subtype_close = netmon_close;
 210          wth->file_encap = netmon_encap[hdr.network];
 211          wth->snapshot_length = 0;       /* not available in header */
 212          /*
 213           * Convert the time stamp to a "time_t" and a number of
 214           * milliseconds.
 215           */
 216          tm.tm_year = pletohs(&hdr.ts_year) - 1900;
 217          tm.tm_mon = pletohs(&hdr.ts_month) - 1;
 218          tm.tm_mday = pletohs(&hdr.ts_day);
 219          tm.tm_hour = pletohs(&hdr.ts_hour);
 220          tm.tm_min = pletohs(&hdr.ts_min);
 221          tm.tm_sec = pletohs(&hdr.ts_sec);
 222          tm.tm_isdst = -1;
 223          wth->capture.netmon->start_secs = mktime(&tm);
 224          /*
 225           * XXX - what if "secs" is -1?  Unlikely, but if the capture was 
 226           * done in a time zone that switches between standard and summer 
 227           * time sometime other than when we do, and thus the time was one
 228           * that doesn't exist here because a switch from standard to summer 
 229           * time zips over it, it could happen.
 230           *
 231           * On the other hand, if the capture was done in a different time 
 232           * zone, this won't work right anyway; unfortunately, the time
 233           * zone isn't stored in the capture file (why the hell didn't
 234           * they stuff a FILETIME, which is the number of 100-nanosecond
 235           * intervals since 1601-01-01 00:00:00 "UTC", there, instead 
 236           * of stuffing a SYSTEMTIME, which is time-zone-dependent, there?).
 237           */
 238          wth->capture.netmon->start_usecs = pletohs(&hdr.ts_msec)*1000;
 239   
 240          wth->capture.netmon->version_major = hdr.ver_major;
 241   
 242          /*
 243           * Get the offset of the frame index table.
 244           */
 245          frame_table_offset = pletohl(&hdr.frametableoffset);
 246   
 247          /*
 248           * It appears that some NetMon 2.x files don't have the
 249           * first packet starting exactly 128 bytes into the file.
 250           *
 251           * Furthermore, it also appears that there are "holes" in 
 252           * the file, i.e. frame N+1 doesn't always follow immediately 
 253           * after frame N.
 254           *
 255           * Therefore, we must read the frame table, and use the offsets
 256           * in it as the offsets of the frames.
 257           */
 258          frame_table_length = pletohl(&hdr.frametablelength);
 259          frame_table_size = frame_table_length / (guint32)sizeof (guint32);
 260          if ((frame_table_size * sizeof (guint32)) != frame_table_length) {
 261                  *err = WTAP_ERR_UNSUPPORTED;
 262                  *err_info = g_strdup_printf("netmon: frame table length is %u, which is not a multiple of the size of an entry",
 263                      frame_table_length);
 264                  g_free(wth->capture.netmon);
 265                  return -1;
 266          }
 267          if (frame_table_size == 0) {
 268                  *err = WTAP_ERR_UNSUPPORTED;
 269                  *err_info = g_strdup_printf("netmon: frame table length is %u, which means it's less than one entry in size",
 270                      frame_table_length);
 271                  g_free(wth->capture.netmon);
 272                  return -1;
 273          }
 274          if (file_seek(wth->fh, frame_table_offset, SEEK_SET, err) == -1) {
 275                  g_free(wth->capture.netmon);
 276                  return -1;
 277          }
 278          frame_table = g_malloc(frame_table_length);
 279          errno = WTAP_ERR_CANT_READ;
 280          bytes_read = file_read(frame_table, 1, frame_table_length, wth->fh);
 281          if ((guint32)bytes_read != frame_table_length) {
 282                  *err = file_error(wth->fh);
 283                  if (*err == 0)
 284                          *err = WTAP_ERR_SHORT_READ;
 285                  g_free(frame_table);
 286                  g_free(wth->capture.netmon);
 287                  return -1;
 288          }
 289          wth->capture.netmon->frame_table_size = frame_table_size;
 290          wth->capture.netmon->frame_table = frame_table;
 291   
 292  #ifdef WORDS_BIGENDIAN 
 293          /*
 294           * OK, now byte-swap the frame table.
 295           */
 296          for (i = 0; i < frame_table_size; i++)
 297                  frame_table[i] = pletohl(&frame_table[i]);
 298  #endif
 299   
 300          /* Set up to start reading at the first frame. */
 301          wth->capture.netmon->current_frame = 0;
 302          wth->tsprecision = WTAP_FILE_TSPREC_USEC;
 303   
 304          return 1;
 305  }
Show more  




Change Warning 1020.29840 : Useless Assignment

Because they are very similar, this warning shares annotations with warning 1020.29841.

Priority:
State:
Finding:
Owner:
Note: