Text   |  XML   |  ReML   |   Visible Warnings:

Null Test After Dereference  at packet-rtps2.c:8632

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

dissect_rtps

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-rtps2.c)expand/collapse
Show more  
 8151  static gboolean dissect_rtps(tvbuff_t *tvb,  
 8152                          packet_info *pinfo,  
 8153                          proto_tree *tree) {
 8154    proto_item       *ti = NULL;
 8155    proto_tree       *rtps_tree = NULL;
 8156    gint             offset = 0;
 8157    proto_tree       *rtps_submessage_tree = NULL;
 8158    guint8           submessageId;
 8159    guint8           flags;
 8160    gboolean         little_endian;
 8161    gboolean         is_ping = FALSE;
 8162    gint             next_submsg, octets_to_next_header;
 8163    guint16          vendor_id = RTPS_VENDOR_UNKNOWN;
 8164    char             info_summary_text[MAX_SUMMARY_SIZE];
 8165   
 8166    info_summary_text[0] = '\0';
 8167         
 8168    /* Check 'RTPS' signature:  
 8169     * A header is invalid if it has less than 16 octets 
 8170     */
 8171    if (!tvb_bytes_exist(tvb, offset, 16)) return FALSE;
 8172   
 8173    /* Check packet signature */
 8174    if ( (tvb_get_guint8(tvb,offset) != 'R') ||
 8175         (tvb_get_guint8(tvb,offset+1) != 'T') ||
 8176         (tvb_get_guint8(tvb,offset+2) != 'P') ||
 8177         (tvb_get_guint8(tvb,offset+3) != 'S') ||
 8178         (tvb_get_guint8(tvb,offset+4) != 2) ) {
 8179      return FALSE;
 8180    }
 8181   
 8182    /* --- Make entries in Protocol column ---*/
 8183    if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
 8184      col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTPS2");
 8185    }
 8186   
 8187    if (check_col(pinfo->cinfo, COL_INFO)) {
 8188      col_clear(pinfo->cinfo, COL_INFO);
 8189    }
 8190   
 8191    /* Check if is NDDSPING */
 8192    {
 8193      guint8 nddsPing[8];
 8194      tvb_memcpy(tvb, nddsPing, offset+8, 8);
 8195      is_ping = (nddsPing[0] == 'N' &&
 8196                 nddsPing[1] == 'D' &&
 8197                 nddsPing[2] == 'D' &&
 8198                 nddsPing[3] == 'S' &&
 8199                 nddsPing[4] == 'P' &&
 8200                 nddsPing[5] == 'I' &&
 8201                 nddsPing[6] == 'N' &&
 8202                 nddsPing[7] == 'G');
 8203    }
 8204   
 8205    if (tree) {
 8206      /* create display subtree for the protocol */
 8207      ti = proto_tree_add_item(tree, proto_rtps, tvb, 0, -1, FALSE);
 8208      rtps_tree = proto_item_add_subtree(ti, ett_rtps);
 8209   
 8210      /*  Protocol Version */
 8211      rtps_util_add_protocol_version(rtps_tree, tvb, offset+4);
 8212   
 8213      /*  Vendor Id  */
 8214      vendor_id = NEXT_guint16(tvb, offset+6, FALSE);
 8215      rtps_util_add_vendor_id(rtps_tree, tvb, offset+6, NULL, 0);
 8216   
 8217      /* If is not PING, the next 12 bytes are the GUID prefix */
 8218      if (!is_ping) {
 8219        rtps_util_add_guid_prefix(rtps_tree,  
 8220                          tvb,
 8221                          offset+8,
 8222                          hf_rtps_guid_prefix,
 8223                          hf_rtps_host_id,
 8224                          hf_rtps_app_id,
 8225                          hf_rtps_sm_counter,
 8226                          NULL,
 8227                          NULL,
 8228                          0);
 8229      }
 8230    }
 8231   
 8232    if (is_ping) {
 8233      g_strlcpy(info_summary_text, "PING", MAX_SUMMARY_SIZE);
 8234    }
 8235   
 8236    /* Extract the domain id and participant index for the default mapping */
 8237    if (tree) {
 8238      int domain_id;
 8239      int participant_idx = -1;
 8240      int nature;
 8241      int Doffset;
 8242      proto_item *ti;
 8243      proto_tree *mapping_tree;
 8244   
 8245      /* For a complete description of these rules, see RTPS documentation 
 8246   
 8247         RTPS 1.2 mapping:
 8248          domain_id = ((pinfo->destport - PORT_BASE)/10) % 100;
 8249          participant_idx = (pinfo->destport - PORT_BASE) / 1000;
 8250
8267
Show [ Lines 8250 to 8267 omitted. ]
 8268              user_multicast_port_offset = 1 
 8269              user_unicast_port_offset = 11 
 8270               
 8271   
 8272         To obtain the individual components from the port number, the reverse formulas are:
 8273              domain_id = (port - port_base) / 250        (valid both multicast / unicast)
 8274              Doffset = (port - port_Base - (domain_id * 250));
 8275              participant_idx = (Doffset - 10) / 2;
 8276   
 8277       */  
 8278      domain_id = (pinfo->destport - PORT_BASE) / 250;
 8279      Doffset = (pinfo->destport - PORT_BASE - domain_id * 250);
 8280      if (Doffset == 0) {
 8281        nature = PORT_METATRAFFIC_MULTICAST;
 8282      } else if (Doffset == 1) {
 8283        nature = PORT_USERTRAFFIC_MULTICAST;
 8284      } else {
 8285        participant_idx = (Doffset - 10) / 2;
 8286        if ( (Doffset - 10) % 2 == 0) {
 8287          nature = PORT_METATRAFFIC_UNICAST;
 8288        } else {
 8289          nature = PORT_USERTRAFFIC_UNICAST;
 8290        }
 8291      }
 8292   
 8293      if (nature == PORT_METATRAFFIC_UNICAST || nature == PORT_USERTRAFFIC_UNICAST) {
 8294        ti = proto_tree_add_text(rtps_tree,
 8295                          tvb,
 8296                          0,
 8297                          4,
 8298                          "Default port mapping: %s, domainId=%d, "
 8299                          "participantIdx=%d",
 8300                          val_to_str(nature, nature_type_vals, "%02x"),
 8301                          domain_id,
 8302                          participant_idx);
 8303      } else {
 8304        /* Multicast doesn't print the participant index */
 8305        ti = proto_tree_add_text(rtps_tree,
 8306                          tvb,
 8307                          0,
 8308                          4,
 8309                          "Default port mapping: %s, domainId=%d",
 8310                          val_to_str(nature, nature_type_vals, "%02x"),
 8311                          domain_id);
 8312      }
 8313   
 8314      /* Build the searchable protocol tree */
 8315      mapping_tree = proto_item_add_subtree(ti, ett_rtps_default_mapping);
 8316      proto_tree_add_uint(mapping_tree,
 8317                          hf_rtps_domain_id,
 8318                          tvb,
 8319                          0,
 8320                          4,
 8321                          domain_id);
 8322      if (nature == PORT_METATRAFFIC_UNICAST || nature == PORT_USERTRAFFIC_UNICAST) {
 8323        proto_tree_add_uint(mapping_tree,
 8324                          hf_rtps_participant_idx,
 8325                          tvb,
 8326                          0,
 8327                          4,
 8328                          participant_idx);
 8329      }
 8330      proto_tree_add_uint(mapping_tree,
 8331                          hf_rtps_nature_type,
 8332                          tvb,
 8333                          0,
 8334                          4,
 8335                          nature);
 8336    }
 8337   
 8338    /* offset behind RTPS's Header (need to be set in case tree=NULL)*/
 8339    offset=20;
 8340   
 8341    while (tvb_reported_length_remaining(tvb, offset) > 0) {
 8342      submessageId = tvb_get_guint8(tvb, offset);
 8343   
 8344      /* Creates the subtree 'Submessage: XXXX' */
 8345      if (rtps_tree) {
 8346        if (submessageId & 0x80) {
 8347          ti = proto_tree_add_text(rtps_tree,  
 8348                  tvb,  
 8349                  offset,  
 8350                  -1,  
 8351                  "Submessage: %s",
 8352                  val_to_str(submessageId, submessage_id_vals,
 8353                          "Vendor-specific (0x%02x)"));
 8354        } else {
 8355          ti = proto_tree_add_text(rtps_tree,  
 8356                  tvb,  
 8357                  offset,  
 8358                  -1,  
 8359                  "Submessage: %s",
 8360                  val_to_str(submessageId, submessage_id_vals,
 8361                          "Unknown (0x%02x)"));
 8362        }
 8363        rtps_submessage_tree = proto_item_add_subtree(ti, ett_rtps_submessage);
 8364   
 8365        /* Decode the submessage ID */
 8366        if (submessageId & 0x80) {
 8367          proto_tree_add_uint_format(rtps_submessage_tree,  
 8368                  hf_rtps_sm_id,
 8369                  tvb,  
 8370                  offset,  
 8371                  1,  
 8372                  submessageId,
 8373                  "submessageId: Vendor-specific (0x%02x)",
 8374                        submessageId);
 8375        } else {
 8376          proto_tree_add_uint(rtps_submessage_tree, hf_rtps_sm_id,
 8377                            tvb, offset, 1, submessageId);
 8378        }
 8379      } /* tree is present */
 8380   
 8381      /* Gets the flags */
 8382      flags = tvb_get_guint8(tvb, offset + 1);
 8383   
 8384      /* Gets the E (Little endian) flag */
 8385      little_endian = ((flags & FLAG_E) != 0);
 8386       
 8387      /* octet-to-next-header */
 8388      octets_to_next_header  = NEXT_guint16(tvb, offset + 2, little_endian);
 8389      next_submsg = offset + octets_to_next_header + 4;
 8390   
 8391      /* Set length of this item */
 8392      if (ti != NULL) {
 8393        proto_item_set_len(ti, octets_to_next_header + 4);
 8394      }  
 8395   
 8396      /* Now decode each single submessage 
 8397       *
 8398       * Note: if tree==NULL, it's true we don't care too much about the 
 8399       *      details, but we are still calling the individual submessage
 8400       *      dissectors in order to correctly compose the INFO list.  
 8401       * The offset passed to the dissectors points to the start of the  
 8402       * submessage (at the ID byte).
 8403       */
 8404      switch (submessageId) {
 8405        case SUBMESSAGE_PAD:
 8406          dissect_PAD(tvb,  
 8407                          offset,  
 8408                          flags,  
 8409                          little_endian,  
 8410                          octets_to_next_header,
 8411                          rtps_submessage_tree,
 8412                          info_summary_text,
 8413                          vendor_id);
 8414          break;
 8415   
 8416        case SUBMESSAGE_DATA:
 8417          dissect_DATA(tvb,  
 8418                          offset,  
 8419                          flags,  
 8420                          little_endian,  
 8421                          octets_to_next_header,
 8422                          rtps_submessage_tree,
 8423                          info_summary_text,
 8424                          vendor_id);
 8425          break;
 8426   
 8427        case SUBMESSAGE_DATA_FRAG:
 8428          dissect_DATA_FRAG(tvb,  
 8429                          offset,  
 8430                          flags,  
 8431                          little_endian,  
 8432                          octets_to_next_header,
 8433                          rtps_submessage_tree,
 8434                          info_summary_text,
 8435                          vendor_id);
 8436          break;
 8437   
 8438        case SUBMESSAGE_NOKEY_DATA:
 8439          dissect_NOKEY_DATA(tvb,  
 8440                          offset,  
 8441                          flags,  
 8442                          little_endian,  
 8443                          octets_to_next_header,
 8444                          rtps_submessage_tree,
 8445                          info_summary_text,
 8446                          vendor_id);
 8447          break;
 8448   
 8449        case SUBMESSAGE_NOKEY_DATA_FRAG:
 8450          dissect_NOKEY_DATA_FRAG(tvb,  
 8451                          offset,  
 8452                          flags,  
 8453                          little_endian,  
 8454                          octets_to_next_header,
 8455                          rtps_submessage_tree,
 8456                          info_summary_text,
 8457                          vendor_id);
 8458          break;
 8459   
 8460        case SUBMESSAGE_NACK_FRAG:
 8461          dissect_NACK_FRAG(tvb,  
 8462                          offset,  
 8463                          flags,  
 8464                          little_endian,  
 8465                          octets_to_next_header,
 8466                          rtps_submessage_tree,
 8467                          info_summary_text,
 8468                          vendor_id);
 8469          break;
 8470   
 8471   
 8472        case SUBMESSAGE_ACKNACK_BATCH:
 8473        case SUBMESSAGE_ACKNACK:
 8474          dissect_ACKNACK(tvb,  
 8475                          offset,  
 8476                          flags,  
 8477                          little_endian,  
 8478                          octets_to_next_header,
 8479                          rtps_submessage_tree,
 8480                          info_summary_text,
 8481                          vendor_id);
 8482          break;
 8483   
 8484        case SUBMESSAGE_HEARTBEAT:
 8485          dissect_HEARTBEAT(tvb,  
 8486                          offset,  
 8487                          flags,  
 8488                          little_endian,  
 8489                          octets_to_next_header,
 8490                          rtps_submessage_tree,
 8491                          info_summary_text,
 8492                          vendor_id);
 8493          break;
 8494   
 8495        case SUBMESSAGE_HEARTBEAT_BATCH:
 8496          dissect_HEARTBEAT_BATCH(tvb,  
 8497                          offset,  
 8498                          flags,  
 8499                          little_endian,  
 8500                          octets_to_next_header,
 8501                          rtps_submessage_tree,
 8502                          info_summary_text,
 8503                          vendor_id);
 8504          break;
 8505   
 8506        case SUBMESSAGE_HEARTBEAT_FRAG:
 8507          dissect_HEARTBEAT_FRAG(tvb,  
 8508                          offset,  
 8509                          flags,  
 8510                          little_endian,  
 8511                          octets_to_next_header,
 8512                          rtps_submessage_tree,
 8513                          info_summary_text,
 8514                          vendor_id);
 8515          break;
 8516   
 8517        case SUBMESSAGE_GAP:
 8518          dissect_GAP(tvb,  
 8519                          offset,  
 8520                          flags,  
 8521                          little_endian,  
 8522                          octets_to_next_header,
 8523                          rtps_submessage_tree,
 8524                          info_summary_text,
 8525                          vendor_id);
 8526          break;
 8527   
 8528        case SUBMESSAGE_INFO_TS:
 8529          dissect_INFO_TS(tvb,  
 8530                          offset,  
 8531                          flags,  
 8532                          little_endian,  
 8533                          octets_to_next_header,
 8534                          rtps_submessage_tree,
 8535                          info_summary_text,
 8536                          vendor_id);
 8537          break;
 8538   
 8539        case SUBMESSAGE_INFO_SRC:
 8540          dissect_INFO_SRC(tvb,  
 8541                          offset,  
 8542                          flags,  
 8543                          little_endian,  
 8544                          octets_to_next_header,
 8545                          rtps_submessage_tree,
 8546                          info_summary_text,
 8547                          vendor_id);
 8548          break;
 8549   
 8550        case SUBMESSAGE_INFO_REPLY_IP4:
 8551          dissect_INFO_REPLY_IP4(tvb,  
 8552                          offset,  
 8553                          flags,  
 8554                          little_endian,  
 8555                          octets_to_next_header,
 8556                          rtps_submessage_tree,
 8557                          info_summary_text,
 8558                          vendor_id);
 8559          break;
 8560   
 8561        case SUBMESSAGE_INFO_DST:
 8562          dissect_INFO_DST(tvb,  
 8563                          offset,  
 8564                          flags,  
 8565                          little_endian,  
 8566                          octets_to_next_header,
 8567                          rtps_submessage_tree,
 8568                          info_summary_text,
 8569                          vendor_id);
 8570          break;
 8571   
 8572        case SUBMESSAGE_INFO_REPLY:
 8573          dissect_INFO_REPLY(tvb,  
 8574                          offset,  
 8575                          flags,  
 8576                          little_endian,  
 8577                          octets_to_next_header,
 8578                          rtps_submessage_tree,
 8579                          info_summary_text,
 8580                          vendor_id);
 8581          break;
 8582   
 8583        case SUBMESSAGE_RTPS_DATA:
 8584          dissect_RTPS_DATA(tvb,  
 8585                          offset,  
 8586                          flags,  
 8587                          little_endian,  
 8588                          octets_to_next_header,
 8589                          rtps_submessage_tree,
 8590                          info_summary_text,
 8591                          vendor_id);
 8592          break;
 8593           
 8594        case SUBMESSAGE_RTPS_DATA_FRAG:
 8595          dissect_RTPS_DATA_FRAG(tvb,  
 8596                          offset,  
 8597                          flags,  
 8598                          little_endian,  
 8599                          octets_to_next_header,
 8600                          rtps_submessage_tree,
 8601                          info_summary_text,
 8602                          vendor_id);
 8603          break;
 8604   
 8605        case SUBMESSAGE_RTPS_DATA_BATCH:
 8606          dissect_RTPS_DATA_BATCH(tvb,  
 8607                          offset,  
 8608                          flags,  
 8609                          little_endian,  
 8610                          octets_to_next_header,
 8611                          rtps_submessage_tree,
 8612                          info_summary_text,
 8613                          vendor_id);
 8614          break;
 8615   
 8616   
 8617        default:
 8618          if (rtps_submessage_tree != NULL) {
 8619            proto_tree_add_uint(rtps_submessage_tree, hf_rtps_sm_flags,
 8620                            tvb, offset + 1, 1, flags);
 8621            proto_tree_add_uint(rtps_submessage_tree,  
 8622                            hf_rtps_sm_octets_to_next_header,
 8623                            tvb, offset + 2, 2, next_submsg);
 8624          }
 8625      }
 8626   
 8627       /* next submessage's offset */
 8628       offset = next_submsg;
 8629    }
 8630   
 8631    /* Compose the content of the 'summary' column */
 8632    if ((pinfo != NULL) && (pinfo->cinfo != NULL) && (check_col(pinfo->cinfo, COL_INFO))) {
 8633      col_add_str(pinfo->cinfo, COL_INFO, info_summary_text);
 8634    }
 8635    return TRUE;
 8636   
 8637  }  /* dissect_rtps(...) */
Show more  




Change Warning 2930.35021 : Null Test After Dereference

Priority:
State:
Finding:
Owner:
Note: