Text   |  XML   |  ReML   |   Visible Warnings:

Redundant Condition  at etherpeek.c:328

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

etherpeek_open

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/etherpeek.c)expand/collapse
Show more  
 159  int etherpeek_open(wtap *wth, int *err, gchar **err_info _U_)
 160  {
 161          etherpeek_header_t ep_hdr;
 162          struct timeval reference_time;
 163          int file_encap;
 164   
 165          /* EtherPeek files do not start with a magic value large enough 
 166           * to be unique; hence we use the following algorithm to determine
 167           * the type of an unknown file:
 168           *  - populate the master header and reject file if there is no match
 169           *  - populate the secondary header and check that the reserved space
 170           *      is zero, and check some other fields; this isn't perfect,
 171           *      and we may have to add more checks at some point.
 172           */
 173          g_assert(sizeof(ep_hdr.master) == ETHERPEEK_MASTER_HDR_SIZE);
 174          wtap_file_read_unknown_bytes(
 175                  &ep_hdr.master, sizeof(ep_hdr.master), wth->fh, err);
 176          wth->data_offset += sizeof(ep_hdr.master);
 177   
 178          /*
 179           * It appears that EtherHelp (a free application from WildPackets
 180           * that did blind capture, saving to a file, so that you could
 181           * give the resulting file to somebody with EtherPeek) saved 
 182           * captures in EtherPeek format except that it ORed the 0x80
 183           * bit on in the version number.
 184           *
 185           * We therefore strip off the 0x80 bit in the version number.
 186           * Perhaps there's some reason to care whether the capture 
 187           * came from EtherHelp; if we discover one, we should check 
 188           * that bit.
 189           */
 190          ep_hdr.master.version &= ~0x80;
 191   
 192          /* switch on the file version */
 193          switch (ep_hdr.master.version) {
 194   
 195          case 5:
 196          case 6:
 197          case 7:
 198                  /* get the secondary header */
 199                  g_assert(sizeof(ep_hdr.secondary.v567) ==
 200                          ETHERPEEK_V567_HDR_SIZE);
 201                  wtap_file_read_unknown_bytes(
 202                          &ep_hdr.secondary.v567,
 203                          sizeof(ep_hdr.secondary.v567), wth->fh, err);
 204                  wth->data_offset += sizeof(ep_hdr.secondary.v567);
 205   
 206                  if ((0 != ep_hdr.secondary.v567.reserved[0]) ||
 207                      (0 != ep_hdr.secondary.v567.reserved[1]) ||
 208                      (0 != ep_hdr.secondary.v567.reserved[2])) {
 209                          /* still unknown */
 210                          return 0;
 211                  }
 212   
 213                  /*
 214                   * Check the mediaType and physMedium fields.
 215                   * We assume it's not an EtherPeek/TokenPeek/AiroPeek
 216                   * file if these aren't values we know, rather than
 217                   * reporting them as invalid *Peek files, as, given 
 218                   * the lack of a magic number, we need all the checks 
 219                   * we can get.
 220                   */
 221                  ep_hdr.secondary.v567.mediaType =
 222                      g_ntohl(ep_hdr.secondary.v567.mediaType);
 223                  ep_hdr.secondary.v567.physMedium =
 224                      g_ntohl(ep_hdr.secondary.v567.physMedium);
 225   
 226                  switch (ep_hdr.secondary.v567.physMedium) {
 227   
 228                  case 0:
 229                          /*
 230                           * "Native" format, presumably meaning
 231                           * Ethernet or Token Ring.
 232                           */
 233                          switch (ep_hdr.secondary.v567.mediaType) {
 234   
 235                          case 0:
 236                                  file_encap = WTAP_ENCAP_ETHERNET;
 237                                  break;
 238   
 239                          case 1:
 240                                  file_encap = WTAP_ENCAP_TOKEN_RING;
 241                                  break;
 242   
 243                          default:
 244                                  /*
 245                                   * Assume this isn't a *Peek file.
 246                                   */
 247                                  return 0;
 248                          }
 249                          break;
 250   
 251                  case 1:
 252                          switch (ep_hdr.secondary.v567.mediaType) {
 253   
 254                          case 0:
 255                                  /*
 256                                   * 802.11, with a private header giving 
 257                                   * some radio information.  Presumably
 258                                   * this is from AiroPeek.
 259                                   *
 260                                   * We supply the private header as
 261                                   * the WTAP_ENCAP_IEEE_802_11_WITH_RADIO
 262                                   * pseudo-header, rather than as frame
 263                                   * data.
 264                                   */
 265                                  file_encap = WTAP_ENCAP_IEEE_802_11_WITH_RADIO;
 266                                  break;
 267   
 268                          default:
 269                                  /*
 270                                   * Assume this isn't a *Peek file.
 271                                   */
 272                                  return 0;
 273                          }
 274                          break;
 275   
 276                  default:
 277                          /*
 278                           * Assume this isn't a *Peek file.
 279                           */
 280                          return 0;
 281                  }
 282   
 283   
 284                  /*
 285                   * Assume this is a V5, V6 or V7 *Peek file, and byte
 286                   * swap the rest of the fields in the secondary header.
 287                   *
 288                   * XXX - we could check the file length if the file were
 289                   * uncompressed, but it might be compressed.
 290                   */
 291                  ep_hdr.secondary.v567.filelength =
 292                      g_ntohl(ep_hdr.secondary.v567.filelength);
 293                  ep_hdr.secondary.v567.numPackets =
 294                      g_ntohl(ep_hdr.secondary.v567.numPackets);
 295                  ep_hdr.secondary.v567.timeDate =
 296                      g_ntohl(ep_hdr.secondary.v567.timeDate);
 297                  ep_hdr.secondary.v567.timeStart =
 298                      g_ntohl(ep_hdr.secondary.v567.timeStart);
 299                  ep_hdr.secondary.v567.timeStop =
 300                      g_ntohl(ep_hdr.secondary.v567.timeStop);
 301                  ep_hdr.secondary.v567.appVers =
 302                      g_ntohl(ep_hdr.secondary.v567.appVers);
 303                  ep_hdr.secondary.v567.linkSpeed =
 304                      g_ntohl(ep_hdr.secondary.v567.linkSpeed);
 305   
 306                  /* Get the reference time as a "struct timeval" */
 307                  reference_time.tv_sec  =
 308                      ep_hdr.secondary.v567.timeDate - mac2unix;
 309                  reference_time.tv_usec = 0;
 310                  break;
 311   
 312          default:
 313                  /*
 314                   * Assume this isn't a *Peek file.
 315                   */
 316                  return 0;
 317          }
 318   
 319          /*
 320           * This is an EtherPeek (or TokenPeek or AiroPeek?) file.
 321           *
 322           * At this point we have recognised the file type and have populated
 323           * the whole ep_hdr structure in host byte order.
 324           */
 325          wth->capture.etherpeek = g_malloc(sizeof(etherpeek_t));
 326          wth->capture.etherpeek->reference_time = reference_time;
 327          wth->subtype_close = etherpeek_close;
 328          switch (ep_hdr.master.version) {
 329   
 330          case 5:
 331          case 6:
 332                  wth->file_type = WTAP_FILE_ETHERPEEK_V56;
 333                  /*
 334                   * XXX - can we get the file encapsulation from the
 335                   * header in the same way we do for V7 files?
 336                   */
 337                  wth->file_encap = WTAP_ENCAP_PER_PACKET;
 338                  wth->subtype_read = etherpeek_read_v56;
 339                  wth->subtype_seek_read = etherpeek_seek_read_v56;
 340                  break;
 341   
 342          case 7:
 343                  wth->file_type = WTAP_FILE_ETHERPEEK_V7;
 344                  wth->file_encap = file_encap;
 345                  wth->subtype_read = etherpeek_read_v7;
 346                  wth->subtype_seek_read = etherpeek_seek_read_v7;
 347                  break;
 348   
 349          default:
 350                  /* this is impossible */
 351                  g_assert_not_reached();
 352          }
 353   
 354          wth->snapshot_length   = 0; /* not available in header */
 355      wth->tsprecision = WTAP_FILE_TSPREC_USEC;
 356   
 357          return 1;
 358  }
Show more  




Change Warning 994.29704 : Redundant Condition

Priority:
State:
Finding:
Owner:
Note: