Text   |  XML   |  ReML   |   Visible Warnings:

Useless Assignment  at packet-dcm.c:5517

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

dissect_dcm_tag

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-dcm.c)expand/collapse
Show more  
 5471  dissect_dcm_tag(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
 5472                  dcm_state_pdv_t *pdv, guint32 offset, guint32 endpos,
 5473                  gboolean is_first_tag, gchar **tag_description,
 5474                  gboolean *end_of_seq_or_item)
 5475  {
 5476      /* Decode one tag. If it is a sequence or item start create a subtree.
 5477         Returns new offset.
 5478      */
 5479   
 5480      proto_tree *tag_ptree = NULL;       /* Tree for decoded tag details */
 5481      proto_tree *seq_ptree = NULL;       /* Possible subtree for sequences and items */
 5482   
 5483      proto_item *tag_pitem = NULL;
 5484      dcm_tag_t  *tag_def   = NULL;
 5485   
 5486      gchar   *vr = NULL;
 5487      gchar   *tag_value = NULL;          /* Tag Value converted to a string      */
 5488      gchar   *tag_summary;
 5489   
 5490      guint32 vl = 0;
 5491      guint16 vl_1 = 0;
 5492      guint16 vl_2 = 0;
 5493   
 5494      guint32 offset_tag   = 0;           /* Remember offsets for tree, since the tree    */
 5495      guint32 offset_vr    = 0;           /* header is created pretty late                */
 5496      guint32 offset_vl    = 0;
 5497   
 5498      guint32 vl_max = 0;                 /* Max Value Length to Parse */
 5499   
 5500      guint16 grp = 0;
 5501      guint16 elm = 0;
 5502   
 5503      guint32 len_decoded_remaing = 0;
 5504   
 5505      gboolean is_little_endian = FALSE;
 5506      gboolean is_implicit = FALSE;
 5507      gboolean is_vl_long = FALSE;            /* True for 4 Bytes length fields */
 5508   
 5509      gboolean is_sequence = FALSE;           /* True for Sequence Tags */
 5510      gboolean is_item = FALSE;               /* True for Sequence Item Tags */
 5511   
 5512      *tag_description = NULL;                /* Reset description. It's ep_ memory, so not really bad*/
 5513   
 5514      tag_value = ep_alloc0(MAX_BUF_LEN);
 5515   
 5516      /* Decode the syntax a little more */
 5517      if (pdv->syntax == DCM_EBE) is_little_endian = FALSE;
 5518      else                        is_little_endian = TRUE;
 5519   
 5520      if (pdv->syntax == DCM_ILE) is_implicit = TRUE;
 5521      else                        is_implicit = FALSE;
 5522   
 5523      offset_tag = offset;
 5524   
 5525   
 5526      if (pdv->prev && is_first_tag) {
 5527          len_decoded_remaing = pdv->prev->open_tag.len_decoded;
 5528      }
 5529   
 5530   
 5531      /* Since we may have a fragmented header, check for every attribute,
 5532         whether we have already decoded left-overs from the previous PDV.
 5533         Since we have implicit & explicit syntax, copying the open tag to 
 5534         a buffer without decoding, would have caused tvb_get_xxtohs()
 5535         implemnetations on the copy.
 5536   
 5537         An alternative approach would have been to resemble the PDVs first.
 5538   
 5539         The attemtps to reassemblye without named sources (to be implemented)
 5540         were very sensitive to missing packets. In such a case, no packet
 5541         of a PDV chain was decoded, not even the start.
 5542   
 5543         So for the time being, use this rather cumbersome approach.
 5544   
 5545         For every two bytes (PDV length are always a factor of 2)
 5546         check whether we have enough data in the buffer and store the value
 5547         accordingly. In the next frame check, whether we have decoded this yet.
 5548      */
 5549   
 5550      /* Group */
 5551      if (len_decoded_remaing >= 2) {
 5552          grp = pdv->prev->open_tag.grp;
 5553          len_decoded_remaing -= 2;
 5554      }
 5555      else {
 5556   
 5557          if (dcm_tag_is_open(pdv, offset_tag, offset, endpos, 2)) return endpos; /* Exit if needed */
 5558   
 5559          if (is_little_endian)   grp = tvb_get_letohs(tvb, offset);
 5560          else                    grp = tvb_get_ntohs (tvb, offset);
 5561          offset += 2;
 5562          pdv->open_tag.grp = grp;
 5563      }
 5564   
 5565      /* Element */
 5566      if (len_decoded_remaing >= 2) {
 5567          elm = pdv->prev->open_tag.elm;
 5568          len_decoded_remaing -= 2;
 5569      }
 5570      else {
 5571   
 5572          if (dcm_tag_is_open(pdv, offset_tag, offset, endpos, 2)) return endpos;    /* Exit if needed */
 5573   
 5574          if (is_little_endian)   elm = tvb_get_letohs(tvb, offset);
 5575          else                    elm = tvb_get_ntohs (tvb, offset);
 5576          offset += 2;
 5577          pdv->open_tag.elm = elm;
 5578      }
 5579   
 5580      /* Find the best matching tag */
 5581      tag_def = dcm_tag_lookup(grp, elm);
 5582   
 5583      /* Value Representation */
 5584      offset_vr = offset;
 5585      if ((grp == 0xFFFE) && (elm == 0xE000 || elm == 0xE00D || elm == 0xE0DD))  {
 5586          /* Item start, Item Delimitation or Sequence Delimitation */
 5587          vr = "UL";
 5588          is_vl_long = TRUE;                          /* These tags always have a 4 byte lentgh field */
 5589      }
 5590      else if (is_implicit) {
 5591          /* Get VR from tag definition */
 5592          vr = ep_strdup(tag_def->vr);
 5593          is_vl_long = TRUE;                          /* Implict always has 4 byte lentgh field */
 5594      }
 5595      else {
 5596   
 5597          if (len_decoded_remaing >= 2) {
 5598              vr = ep_strdup(pdv->prev->open_tag.vr);
 5599              len_decoded_remaing -= 2;
 5600          }
 5601          else {
 5602   
 5603              /* Controlled exit, if VR does not fit. */
 5604              if (dcm_tag_is_open(pdv, offset_tag, offset_vr, endpos, 2)) return endpos;
 5605   
 5606              vr = (gchar *)tvb_get_ephemeral_string(tvb, offset, 2);
 5607              offset += 2;
 5608   
 5609              g_free(pdv->open_tag.vr);
 5610              pdv->open_tag.vr = g_strdup(vr);        /* needs to survive withing a session */
 5611          }
 5612   
 5613   
 5614          if ((strcmp(vr, "OB") == 0) || (strcmp(vr, "OW") == 0) || (strcmp(vr, "OF") == 0) ||
 5615              (strcmp(vr, "SQ") == 0) || (strcmp(vr, "UT") == 0) || (strcmp(vr, "UN") == 0)) {
 5616              /* 4 bytes specials: OB, OW, OF, SQ, UT or UN */
 5617              is_vl_long = TRUE;
 5618   
 5619              /* Skip 2 Bytes */
 5620              if (len_decoded_remaing >= 2) {
 5621                  len_decoded_remaing -= 2;
 5622              }
 5623              else {
 5624                  if (dcm_tag_is_open(pdv, offset_tag, offset_vr, endpos, 2)) return endpos;
 5625                  offset += 2;
 5626              }
 5627          }
 5628          else {
 5629              is_vl_long = FALSE;
 5630          }
 5631      }
 5632   
 5633   
 5634      /* Value Length. This is rather cumbersume code to get a 4 byte length, but in the 
 5635         fragmented case, we have 2*2 bytes. So always use that pattern 
 5636      */
 5637   
 5638      offset_vl = offset;
 5639      if (len_decoded_remaing >= 2) {
 5640          vl_1 = pdv->prev->open_tag.vl_1;
 5641          len_decoded_remaing -= 2;
 5642      }
 5643      else {
 5644   
 5645          if (dcm_tag_is_open(pdv, offset_tag, offset_vl, endpos, 2)) return endpos;
 5646          if (is_little_endian)   vl_1 = tvb_get_letohs(tvb, offset);
 5647          else                    vl_1 = tvb_get_ntohs(tvb, offset);
 5648          offset += 2;
 5649          pdv->open_tag.vl_1 = vl_1;
 5650      }
 5651   
 5652      if (is_vl_long) {
 5653   
 5654          if (len_decoded_remaing >= 2) {
 5655              vl_2 = pdv->prev->open_tag.vl_2;
 5656              len_decoded_remaing -= 2;
 5657          }
 5658          else {
 5659   
 5660              if (dcm_tag_is_open(pdv, offset_tag, offset_vl+2, endpos, 2)) return endpos;
 5661              if (is_little_endian)       vl_2 = tvb_get_letohs(tvb, offset);
 5662              else                        vl_2 = tvb_get_ntohs(tvb, offset);
 5663              offset += 2;
 5664              pdv->open_tag.vl_2 = vl_2;
 5665          }
 5666   
 5667          if (is_little_endian)   vl = (vl_2 << 16) + vl_1;
 5668          else                    vl = (vl_1 << 16) + vl_2;
 5669      }
 5670      else {
 5671          vl = vl_1;
 5672      }
 5673   
 5674      /* Now we have most of the information, excpet for sequences and items with undefined 
 5675         length :-/. But, whether we know the length or not, we now need to create the tree 
 5676         item and subtree, before we can loop into sequences and items
 5677   
 5678         Display the information we collected so far. Don't wait until the value is parsed,
 5679         because that parsing might cause an exception. If that happens within a sequence,
 5680         the sequence tag would not show up with the value 
 5681      */
 5682   
 5683      tag_summary = dcm_tag_summary(grp, elm, vl, (gchar *)tag_def->description, vr, tag_def->is_retired, is_implicit);
 5684   
 5685      if (vl == 0xFFFFFFFF) {
 5686          /* 'Just' mark header as the length of the item */
 5687          tag_pitem = proto_tree_add_text(tree, tvb, offset_tag, offset - offset_tag, "%s", tag_summary);
 5688          vl_max = 0;         /* We don't know who long this sequence/item is */
 5689      }
 5690      else if (offset + vl <= endpos) {
 5691          /* Show real length of item */
 5692          tag_pitem = proto_tree_add_text(tree, tvb, offset_tag, offset + vl - offset_tag, "%s", tag_summary);
 5693          vl_max = vl;
 5694      }
 5695      else {
 5696          /* Value is longer than what we have in the PDV, -> we do have a OPEN tag */
 5697          tag_pitem = proto_tree_add_text(tree, tvb, offset_tag, endpos - offset_tag, "%s", tag_summary);
 5698          vl_max = endpos - offset;
 5699      }
 5700   
 5701      is_sequence = (strcmp(vr, "SQ") == 0);
 5702      is_item = ((grp == 0xFFFE) && (elm == 0xE000));
 5703   
 5704   
 5705      /* If you are going to touch the following 25 lines, make sure you reserve a few hours to go 
 5706         through both display options and check for proper tree display :-)
 5707      */
 5708      if (is_sequence | is_item) {
 5709   
 5710          if (global_dcm_seq_subtree) {
 5711              /* Use different ett_ for Sequences & Items, so that fold/unfold state makes sense */
 5712              seq_ptree = proto_item_add_subtree(tag_pitem, (is_sequence ? ett_dcm_data_seq : ett_dcm_data_item));
 5713              if (global_dcm_tag_subtree)     tag_ptree = seq_ptree;
 5714              else                            tag_ptree = NULL;
 5715          }
 5716          else {
 5717              seq_ptree = tree;
 5718              if (global_dcm_tag_subtree) {
 5719                  tag_ptree = proto_item_add_subtree(tag_pitem, ett_dcm_data_tag);
 5720              }
 5721              else {
 5722                  tag_ptree = NULL;
 5723              }
 5724          }
 5725      }
 5726      else {
 5727          /* For tags */
 5728          if (global_dcm_tag_subtree) {
 5729              tag_ptree = proto_item_add_subtree(tag_pitem, ett_dcm_data_tag);
 5730          }
 5731          else {
 5732              tag_ptree = NULL;
 5733          }
 5734      }
 5735   
 5736      /*  ---------------------------------------------------------------
 5737          Tag details as separate items 
 5738          ---------------------------------------------------------------
 5739      */
 5740   
 5741      proto_tree_add_uint_format(tag_ptree, hf_dcm_tag, tvb, offset_tag, 4,
 5742          (grp << 16) | elm, "Tag:    %04x,%04x (%s)", grp, elm, tag_def->description);
 5743   
 5744      /* Add VR to tag detail, excpet for dicom items */
 5745      if (!is_item)  {
 5746          if (is_implicit) {
 5747              /* Select header, since no VR is present in implicit syntax */
 5748              proto_tree_add_string_format(tag_ptree, hf_dcm_tag_vr, tvb, offset_tag, 4, vr, "%-8.8s%s", "VR:", vr);
 5749          }
 5750          else {
 5751              proto_tree_add_string_format(tag_ptree, hf_dcm_tag_vr, tvb, offset_vr,  2, vr, "%-8.8s%s", "VR:", vr);
 5752          }
 5753      }
 5754   
 5755      /* Add length to tag detail */
 5756      proto_tree_add_uint_format(tag_ptree, hf_dcm_tag_vl, tvb, offset_vl, (is_vl_long ? 4 : 2), vl, "%-8.8s%u", "Length:", vl);
 5757   
 5758   
 5759      /*  ---------------------------------------------------------------
 5760          Finally the Tag Value
 5761          ---------------------------------------------------------------
 5762      */
 5763      if ((is_sequence || is_item) && (vl > 0)) {
 5764          /* Sequence or Item Start */
 5765   
 5766          guint32 endpos_item = 0;
 5767          gboolean end_of_seq_or_item = FALSE;
 5768          gboolean is_first_desc = TRUE;
 5769   
 5770          gchar *item_description = NULL;     /* Will be allocated as ep_ memory in dissect_dcm_tag() */
 5771   
 5772          if (vl == 0xFFFFFFFF) {
 5773              /* Undefined length */
 5774   
 5775              while ((!end_of_seq_or_item) && (!pdv->open_tag.is_header_fragmented) && (offset < endpos)) {
 5776   
 5777                  offset = dissect_dcm_tag(tvb, pinfo, seq_ptree, pdv, offset, endpos, FALSE,
 5778                      &item_description, &end_of_seq_or_item);
 5779   
 5780                  if (item_description && global_dcm_seq_subtree) {
 5781                      proto_item_append_text(tag_pitem, (is_first_desc ? " %s" : ", %s"), item_description);
 5782                      is_first_desc = FALSE;
 5783                  }
 5784              }
 5785          }
 5786          else {
 5787              /* Defined length */
 5788              endpos_item = offset + vl_max;
 5789   
 5790              while (offset < endpos_item) {
 5791   
 5792                  offset = dissect_dcm_tag(tvb, pinfo, seq_ptree, pdv, offset, endpos_item, FALSE,
 5793                      &item_description, &end_of_seq_or_item);
 5794   
 5795                  if (item_description && global_dcm_seq_subtree) {
 5796                      proto_item_append_text(tag_pitem, (is_first_desc ? " %s" : ", %s"), item_description);
 5797                      is_first_desc = FALSE;
 5798                  }
 5799              }
 5800          }
 5801      }
 5802      else if ((grp == 0xFFFE) && (elm == 0xE00D)) {
 5803          /* Item delimitation for items with undefined length */
 5804          *end_of_seq_or_item = TRUE;
 5805      }
 5806      else if ((grp == 0xFFFE) && (elm == 0xE0DD)) {
 5807          /* Sequence delimitation for sequences with undefined length */
 5808          *end_of_seq_or_item = TRUE;
 5809      }
 5810      else if (vl == 0) {
 5811          /* No value */
 5812          tag_value = "<Empty>";
 5813      }
 5814      else if (vl > vl_max) {
 5815          /* Tag is longer than the PDV/PDU. Don't perform any decoding */
 5816   
 5817          const guint8* valb;
 5818          gchar *tag_desc;
 5819   
 5820          valb = tvb_get_ptr(tvb, offset, vl_max);
 5821          proto_tree_add_bytes_format(tag_ptree, hf_dcm_tag_value_byte, tvb, offset, vl_max,
 5822              valb, "%-8.8sBytes %d - %d [start]", "Value:", 1, vl_max);
 5823   
 5824          g_snprintf(tag_value, MAX_BUF_LEN, "<Bytes %d - %d, start>", 1, vl_max);
 5825          offset += vl_max;
 5826   
 5827          /*  Save the needed data for reuse, and subsequent packets 
 5828              This will leak a little within the session.
 5829   
 5830              But since we may have tags being closed and reopen in the same PDV
 5831              we will always need to store this 
 5832          */
 5833   
 5834          tag_desc = dcm_tag_summary(grp, elm, vl, (gchar *)tag_def->description, vr, tag_def->is_retired, is_implicit);
 5835   
 5836          if (pdv->open_tag.desc == NULL) {
 5837              pdv->open_tag.is_value_fragmented = TRUE;
 5838              pdv->open_tag.desc = tag_desc;
 5839              pdv->open_tag.len_total = vl;
 5840              pdv->open_tag.len_remaining = vl - vl_max;
 5841          }
 5842      }
 5843      else {
 5844          /* Regular value. Identify the type, decode and display */
 5845   
 5846          offset = dissect_dcm_tag_value(tvb, pinfo, tag_ptree, pdv, offset, grp, elm, vl, vl_max, vr, &tag_value);
 5847   
 5848          /* -------------------------------------------------------------
 5849             We have decoded the value. Now store those tags of interest
 5850             -------------------------------------------------------------
 5851          */
 5852   
 5853          /* Store SOP Class and Instance UID in first PDV of this object */
 5854          if (grp == 0x0008 && elm == 0x0016) {
 5855              dcm_state_pdv_get_obj_start(pdv)->sop_class_uid = se_strdup(tag_value);
 5856          }
 5857          else if (grp == 0x0008 && elm == 0x0018) {
 5858              dcm_state_pdv_get_obj_start(pdv)->sop_instance_uid = se_strdup(tag_value);
 5859          }
 5860          else if (grp == 0x0000 && elm == 0x0100) {
 5861              /* This is the command tag -> overwrite existing PDV description */
 5862              pdv->desc = se_strdup(tag_value);
 5863          }
 5864      }
 5865   
 5866   
 5867      /* -------------------------------------------------------------------
 5868         Adde the value to the already constructued item 
 5869         -------------------------------------------------------------------
 5870      */
 5871   
 5872      proto_item_append_text(tag_pitem, " %s", tag_value);
 5873   
 5874      if (tag_def->add_to_summary) {
 5875          *tag_description = ep_alloc0(MAX_BUF_LEN);
 5876          g_snprintf(*tag_description, MAX_BUF_LEN, "%s", g_strstrip(tag_value));
 5877      }
 5878   
 5879      return offset;
 5880  }
Show more  




Change Warning 2187.31698 : Useless Assignment

Priority:
State:
Finding:
Owner:
Note: