Text   |  XML   |  ReML   |   Visible Warnings:

Format String  at proto.c:5630

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

construct_match_selected_string

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/proto.c)expand/collapse
Show more  
 5539  construct_match_selected_string(field_info *finfo, epan_dissect_t *edt,
 5540      char **filter)
 5541  {
 5542          header_field_info       *hfinfo;
 5543          int                     abbrev_len;
 5544          char                    *ptr;
 5545          int                     buf_len;
 5546          const char              *format;
 5547          int                     dfilter_len, i;
 5548          gint                    start, length, length_remaining;
 5549          guint8                  c;
 5550          gchar                   is_signed_num = FALSE;
 5551   
 5552          hfinfo = finfo->hfinfo;
 5553          DISSECTOR_ASSERT(hfinfo);
 5554          abbrev_len = (int) strlen(hfinfo->abbrev);
 5555   
 5556          if (hfinfo->strings && (hfinfo->display & BASE_STRUCTURE_RESET) == BASE_NONE) {
 5557                  const gchar *str = NULL;
 5558   
 5559                  switch(hfinfo->type) {
 5560   
 5561                  case FT_INT8:
 5562                  case FT_INT16:
 5563                  case FT_INT24:
 5564                  case FT_INT32:
 5565                          if (hfinfo->display & BASE_RANGE_STRING) {
 5566                                  str = match_strrval(fvalue_get_sinteger(&finfo->value), hfinfo->strings);
 5567                          } else {
 5568                                  str = match_strval(fvalue_get_sinteger(&finfo->value), hfinfo->strings);
 5569                          }
 5570                          break;
 5571   
 5572                  case FT_UINT8:
 5573                  case FT_UINT16:
 5574                  case FT_UINT24:
 5575                  case FT_UINT32:
 5576                          if (hfinfo->display & BASE_RANGE_STRING) {
 5577                                  str = match_strrval(fvalue_get_uinteger(&finfo->value), hfinfo->strings);
 5578                          } else {
 5579                                  str = match_strval(fvalue_get_uinteger(&finfo->value), hfinfo->strings);
 5580                          }
 5581                          break;
 5582   
 5583                  default:
 5584                          break;
 5585                  }
 5586   
 5587                  if (str != NULL && filter != NULL) {
 5588                          *filter = ep_strdup_printf("%s == \"%s\"", hfinfo->abbrev, str);
 5589                          return TRUE;
 5590                  }
 5591          }
 5592   
 5593          /*
 5594           * XXX - we can't use the "val_to_string_repr" and "string_repr_len"
 5595           * functions for FT_UINT and FT_INT types, as we choose the base in
 5596           * the string expression based on the display base of the field.
 5597           *
 5598           * Note that the base does matter, as this is also used for
 5599           * the protocolinfo tap.
 5600           *
 5601           * It might be nice to use them in "proto_item_fill_label()"
 5602           * as well, although, there, you'd have to deal with the base
 5603           * *and* with resolved values for addresses.
 5604           *
 5605           * Perhaps we need two different val_to_string routines, one 
 5606           * to generate items for display filters and one to generate
 5607           * strings for display, and pass to both of them the 
 5608           * "display" and "strings" values in the header_field_info
 5609           * structure for the field, so they can get the base and,
 5610           * if the field is Boolean or an enumerated integer type,
 5611           * the tables used to generate human-readable values.
 5612           */
 5613          switch(hfinfo->type) {
 5614   
 5615                  case FT_INT8:
 5616                  case FT_INT16:
 5617                  case FT_INT24:
 5618                  case FT_INT32:
 5619                          is_signed_num = TRUE;
 5620                  case FT_UINT8:
 5621                  case FT_UINT16:
 5622                  case FT_UINT24:
 5623                  case FT_UINT32:
 5624                  case FT_FRAMENUM:
 5625                          if (filter != NULL) {
 5626                                  format = hfinfo_numeric_format(hfinfo);
 5627                                  if(is_signed_num) {
 5628                                          *filter = ep_strdup_printf(format,
 5629                                                     hfinfo->abbrev,
 5630                                                     fvalue_get_sinteger(&finfo->value));
 5631                                  } else {
 5632                                          *filter = ep_strdup_printf(format,
 5633                                                     hfinfo->abbrev,
 5634                                                     fvalue_get_uinteger(&finfo->value));
 5635                                  }
 5636                          }
 5637                          break;
 5638   
 5639                  case FT_INT64:
 5640                  case FT_UINT64:
 5641                          if (filter != NULL) {
 5642                                  format = hfinfo_numeric_format(hfinfo);
 5643                                  *filter = ep_strdup_printf(format,
 5644                                      hfinfo->abbrev,
 5645                                      fvalue_get_integer64(&finfo->value));
 5646                          }
 5647                          break;
 5648   
 5649                  case FT_PROTOCOL:
 5650                          if (filter != NULL)
 5651                                  *filter = ep_strdup(finfo->hfinfo->abbrev);
 5652                          break;
 5653   
 5654                  case FT_NONE:
 5655                  case FT_PCRE:
 5656                          /*
 5657                           * If the length is 0, just match the name of the
 5658                           * field.
 5659                           *
 5660                           * (Also check for negative values, just in case,
 5661                           * as we'll cast it to an unsigned value later.)
 5662                           */
 5663                          length = finfo->length;
 5664                          if (length == 0) {
 5665                                  if (filter != NULL)
 5666                                          *filter = ep_strdup(finfo->hfinfo->abbrev);
 5667                                  break;
 5668                          }
 5669                          if (length < 0)
 5670                                  return FALSE;
 5671   
 5672                          /*
 5673                           * This doesn't have a value, so we'd match 
 5674                           * on the raw bytes at this address.
 5675                           *
 5676                           * Should we be allowed to access to the raw bytes?
 5677                           * If "edt" is NULL, the answer is "no".
 5678                           */
 5679                          if (edt == NULL)
 5680                                  return FALSE;
 5681   
 5682                          /*
 5683                           * Is this field part of the raw frame tvbuff?
 5684                           * If not, we can't use "frame[N:M]" to match
 5685                           * it.
 5686                           *
 5687                           * XXX - should this be frame-relative, or 
 5688                           * protocol-relative?
 5689                           *
 5690                           * XXX - does this fallback for non-registered
 5691                           * fields even make sense?
 5692                           */
 5693                          if (finfo->ds_tvb != edt->tvb)
 5694                                  return FALSE;   /* you lose */
 5695   
 5696                          /*
 5697                           * Don't go past the end of that tvbuff.
 5698                           */
 5699                          length_remaining = tvb_length_remaining(finfo->ds_tvb, finfo->start);
 5700                          if (length > length_remaining)
 5701                                  length = length_remaining;
 5702                          if (length <= 0)
 5703                                  return FALSE;
 5704   
 5705                          if (filter != NULL) {
 5706                                  start = finfo->start;
 5707                                  buf_len = 32 + length * 3;
 5708                                  *filter = ep_alloc0(buf_len);
 5709                                  ptr = *filter;
 5710   
 5711                                  ptr += g_snprintf(ptr, (gulong) (buf_len-(ptr-*filter)),
 5712                                      "frame[%d:%d] == ", finfo->start, length);
 5713                                  for (i=0;i<length; i++) {
 5714                                          c = tvb_get_guint8(finfo->ds_tvb, start);
 5715                                          start++;
 5716                                          if (i == 0 ) {
 5717                                                  ptr += g_snprintf(ptr, (gulong) (buf_len-(ptr-*filter)), "%02x", c);
 5718                                          }
 5719                                          else {
 5720                                                  ptr += g_snprintf(ptr, (gulong) (buf_len-(ptr-*filter)), ":%02x", c);
 5721                                          }
 5722                                  }
 5723                          }
 5724                          break;
 5725   
 5726                  /* By default, use the fvalue's "to_string_repr" method. */
 5727                  default:
 5728                          /* Figure out the string length needed.
 5729                           *      The ft_repr length.
 5730                           *      4 bytes for " == ".
 5731                           *      1 byte for trailing NUL.
 5732                           */
 5733                          if (filter != NULL) {
 5734                                  dfilter_len = fvalue_string_repr_len(&finfo->value,
 5735                                                  FTREPR_DFILTER);
 5736                                  dfilter_len += abbrev_len + 4 + 1;
 5737                                  *filter = ep_alloc0(dfilter_len);
 5738   
 5739                                  /* Create the string */
 5740                                  g_snprintf(*filter, dfilter_len, "%s == ",
 5741                                      hfinfo->abbrev);
 5742                                  fvalue_to_string_repr(&finfo->value,
 5743                                      FTREPR_DFILTER,
 5744                                      &(*filter)[abbrev_len + 4]);
 5745                          }
 5746                          break;
 5747          }
 5748   
 5749          return TRUE;
 5750  }
Show more  




Change Warning 12118.35833 : Format String

Priority:
State:
Finding:
Owner:
Note: