Text   |  XML   |  ReML   |   Visible Warnings:

Null Test After Dereference  at packet-mgcp.c:1769

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

dissect_mgcp_firstline

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-mgcp.c)expand/collapse
Show more  
 1413  static void dissect_mgcp_firstline(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 1414  {
 1415          gint tvb_current_offset,tvb_previous_offset,tvb_len,tvb_current_len;
 1416          gint tokennum, tokenlen;
 1417          proto_item* hidden_item;
 1418          char *transid = NULL;
 1419          char *code = NULL;
 1420          char *endpointId = NULL;
 1421          mgcp_type_t mgcp_type = MGCP_OTHERS;
 1422          conversation_t* conversation;
 1423          mgcp_call_info_key mgcp_call_key;
 1424          mgcp_call_info_key *new_mgcp_call_key = NULL;
 1425          mgcp_call_t *mgcp_call = NULL;
 1426          nstime_t delta;
 1427          gint rspcode = 0;
 1428          const gchar *verb_description = "";
 1429          char code_with_verb[64] = "";  /* To fit "<4-letter-code> (<longest-verb>)" */
 1430   
 1431          static address null_address = { AT_NONE, 0, NULL };
 1432          tvb_previous_offset = 0;
 1433          tvb_len = tvb_length(tvb);
 1434          tvb_current_len = tvb_len;
 1435          tvb_current_offset = tvb_previous_offset;
 1436          mi->is_duplicate = FALSE;
 1437          mi->request_available = FALSE;
 1438   
 1439          if (tree)
 1440          {
 1441                  tokennum = 0;
 1442   
 1443                  do 
 1444                  {
 1445                          tvb_current_len = tvb_length_remaining(tvb,tvb_previous_offset);
 1446                          tvb_current_offset = tvb_find_guint8(tvb, tvb_previous_offset, tvb_current_len, ' ');
 1447                          if (tvb_current_offset == -1)
 1448                          {
 1449                                  tvb_current_offset = tvb_len;
 1450                                  tokenlen = tvb_current_len;
 1451                          }
 1452                          else 
 1453                          {
 1454                                  tokenlen = tvb_current_offset - tvb_previous_offset;
 1455                          }
 1456                          if (tokennum == 0)
 1457                          {
 1458                                  if (tokenlen > 4)
 1459                                          THROW(ReportedBoundsError);
 1460                                  code = tvb_format_text(tvb,tvb_previous_offset,tokenlen);
 1461                                  g_strlcpy(mi->code,code,5);
 1462                                  if (is_mgcp_verb(tvb,tvb_previous_offset,tvb_current_len,&verb_description))
 1463                                  {
 1464                                          mgcp_type = MGCP_REQUEST;
 1465                                          if (verb_description != NULL)
 1466                                          {
 1467                                                  /* Can show verb along with code if known */
 1468                                                  g_snprintf(code_with_verb, 64, "%s (%s)", code, verb_description);
 1469                                          }
 1470   
 1471                                          proto_tree_add_string_format(tree, hf_mgcp_req_verb, tvb,
 1472                                                                       tvb_previous_offset, tokenlen,
 1473                                                                       code, "%s",
 1474                                                                       strlen(code_with_verb) ? code_with_verb : code);
 1475                                  }
 1476                                  else 
 1477                                  if (is_mgcp_rspcode(tvb,tvb_previous_offset,tvb_current_len))
 1478                                  {
 1479                                          mgcp_type = MGCP_RESPONSE;
 1480                                          rspcode = atoi(code);
 1481                                          mi->rspcode = rspcode;
 1482                                          proto_tree_add_uint(tree,hf_mgcp_rsp_rspcode, tvb,
 1483                                                              tvb_previous_offset, tokenlen, rspcode);
 1484                                  }
 1485                                  else 
 1486                                  {
 1487                                          break;
 1488                                  }
 1489                          }
 1490                          if (tokennum == 1)
 1491                          {
 1492                                  transid = tvb_format_text(tvb,tvb_previous_offset,tokenlen);
 1493                                  /* XXX - what if this isn't a valid text string? */
 1494                                  mi->transid = atol(transid);
 1495                                  proto_tree_add_string(tree, hf_mgcp_transid, tvb,
 1496                                                        tvb_previous_offset, tokenlen, transid);
 1497                          }
 1498                          if (tokennum == 2)
 1499                          {
 1500                                  if (mgcp_type == MGCP_REQUEST)
 1501                                  {
 1502                                          endpointId = tvb_format_text(tvb, tvb_previous_offset,tokenlen);
 1503                                          mi->endpointId = ep_strdup(endpointId);
 1504                                          proto_tree_add_string(tree,hf_mgcp_req_endpoint, tvb,
 1505                                                                tvb_previous_offset, tokenlen, endpointId);
 1506                                  }
 1507                                  else 
 1508                                  if (mgcp_type == MGCP_RESPONSE)
 1509                                  {
 1510                                          if (tvb_current_offset < tvb_len)
 1511                                          {
 1512                                                  tokenlen = tvb_find_line_end(tvb, tvb_previous_offset,
 1513                                                                               -1, &tvb_current_offset, FALSE);
 1514                                          }
 1515                                          else 
 1516                                          {
 1517                                                  tokenlen = tvb_current_len;
 1518                                          }
 1519                                          proto_tree_add_string(tree, hf_mgcp_rsp_rspstring, tvb,
 1520                                                                tvb_previous_offset, tokenlen,
 1521                                                                tvb_format_text(tvb, tvb_previous_offset,
 1522                                                                tokenlen));
 1523                                          break;
 1524                                  }
 1525                          }
 1526         
 1527                          if ((tokennum == 3 && mgcp_type == MGCP_REQUEST))
 1528                          {
 1529                                  if (tvb_current_offset < tvb_len )
 1530                                  {
 1531                                          tokenlen = tvb_find_line_end(tvb, tvb_previous_offset,
 1532                                                                       -1, &tvb_current_offset,FALSE);
 1533                                  }
 1534                                  else 
 1535                                  {
 1536                                          tokenlen = tvb_current_len;
 1537                                  }
 1538                                  proto_tree_add_string(tree,hf_mgcp_version, tvb,
 1539                                                        tvb_previous_offset, tokenlen,
 1540                                                        tvb_format_text(tvb,tvb_previous_offset,
 1541                                                        tokenlen));
 1542                                  break;
 1543                          }
 1544                          if (tvb_current_offset < tvb_len)
 1545                          {
 1546                                  tvb_previous_offset = tvb_skip_wsp(tvb, tvb_current_offset,
 1547                                                                     tvb_current_len);
 1548                          }
 1549                          tokennum++;
 1550                  } while (tvb_current_offset < tvb_len && tvb_previous_offset < tvb_len && tokennum <= 3);
 1551   
 1552                  switch (mgcp_type)
 1553                  {
 1554                          case MGCP_RESPONSE:
 1555                                  hidden_item = proto_tree_add_boolean(tree, hf_mgcp_rsp, tvb, 0, 0, TRUE);
 1556                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1557                                  /* Check for MGCP response.  A response must match a call that
 1558                                     we've seen, and the response must be sent to the same 
 1559                                     port and address that the call came from, and must
 1560                                     come from the port to which the call was sent.
 1561   
 1562                                     If the transport is connection-oriented (we check, for 
 1563                                     now, only for "pinfo->ptype" of PT_TCP), we take
 1564                                     into  the address from which the call was sent 
 1565                                     and the address to which the call was sent, because 
 1566                                     the addresses of the two endpoints should be the same 
 1567                                     for all calls and replies.
 1568   
 1569                                     If the transport is connectionless, we don't worry 
 1570                                     about the address to which the call was sent and from
 1571                                     which the reply was sent, because there's no 
 1572                                     guarantee that the reply will come from the address
 1573                                     to which the call was sent. */
 1574                                  if (pinfo->ptype == PT_TCP)
 1575                                  {
 1576                                          conversation = find_conversation(pinfo->fd->num, &pinfo->src,
 1577                                                                           &pinfo->dst, pinfo->ptype, pinfo->srcport,
 1578                                                                           pinfo->destport, 0);
 1579                                  }
 1580                                  else 
 1581                                  {
 1582                                          /* XXX - can we just use NO_ADDR_B?  Unfortunately,
 1583                                           * you currently still have to pass a non-null
 1584                                           * pointer for the second address argument even 
 1585                                           * if you do that.
 1586                                           */
 1587                                          conversation = find_conversation(pinfo->fd->num, &null_address,
 1588                                                                           &pinfo->dst, pinfo->ptype, pinfo->srcport,
 1589                                                                           pinfo->destport, 0);
 1590                                  }
 1591                                  if (conversation != NULL)
 1592                                  {
 1593                                          /* Look only for matching request, if 
 1594                                             matching conversation is available. */
 1595                                          mgcp_call_key.transid = mi->transid;
 1596                                          mgcp_call_key.conversation = conversation;
 1597                                          mgcp_call = g_hash_table_lookup(mgcp_calls, &mgcp_call_key);
 1598                                          if (mgcp_call)
 1599                                          {
 1600                                                  /* Indicate the frame to which this is a reply. */
 1601                                                  if (mgcp_call->req_num)
 1602                                                  {
 1603                                                          proto_item* item;
 1604                                                          mi->request_available = TRUE;
 1605                                                          mgcp_call->responded = TRUE;
 1606                                                          mi->req_num = mgcp_call->req_num;
 1607                                                          g_strlcpy(mi->code,mgcp_call->code,5);
 1608                                                          item = proto_tree_add_uint_format(tree, hf_mgcp_req_frame,
 1609                                                                                            tvb, 0, 0, mgcp_call->req_num,
 1610                                                                                            "This is a response to a request in frame %u",
 1611                                                                                            mgcp_call->req_num);
 1612                                                          PROTO_ITEM_SET_GENERATED(item);
 1613                                                          nstime_delta(&delta, &pinfo->fd->abs_ts, &mgcp_call->req_time);
 1614                                                          item = proto_tree_add_time(tree, hf_mgcp_time, tvb, 0, 0, &delta);
 1615                                                          PROTO_ITEM_SET_GENERATED(item);
 1616                                                  }
 1617   
 1618                                                  if (mgcp_call->rsp_num == 0)
 1619                                                  {
 1620                                                          /* We have not yet seen a response to that call, so 
 1621                                                             this must be the first response; remember its
 1622                                                             frame number. */
 1623                                                          mgcp_call->rsp_num = pinfo->fd->num;
 1624                                                  }
 1625                                                  else 
 1626                                                  {
 1627                                                          /* We have seen a response to this call - but was it 
 1628                                                             *this* response? (disregard provisional responses) */
 1629                                                          if ((mgcp_call->rsp_num != pinfo->fd->num) &&
 1630                                                              (mi->rspcode >= 200) &&
 1631                                                              (mi->rspcode == mgcp_call->rspcode))
 1632                                                          {
 1633                                                                  /* No, so it's a duplicate response. Mark it as such. */
 1634                                                                  mi->is_duplicate = TRUE;
 1635                                                                  if (check_col(pinfo->cinfo, COL_INFO))
 1636                                                                  {
 1637                                                                          col_append_fstr(pinfo->cinfo, COL_INFO,
 1638                                                                                          ", Duplicate Response %u",
 1639                                                                                          mi->transid);
 1640                                                                  }
 1641                                                                  if (tree)
 1642                                                                  {
 1643                                                                          proto_item* item;
 1644                                                                          item = proto_tree_add_uint(tree, hf_mgcp_dup, tvb, 0,0, mi->transid);
 1645                                                                          PROTO_ITEM_SET_HIDDEN(item);
 1646                                                                          item = proto_tree_add_uint(tree, hf_mgcp_rsp_dup,
 1647                                                                                                     tvb, 0, 0, mi->transid);
 1648                                                                          PROTO_ITEM_SET_GENERATED(item);
 1649                                                                          item = proto_tree_add_uint(tree, hf_mgcp_rsp_dup_frame,
 1650                                                                                                     tvb, 0, 0, mgcp_call->rsp_num);
 1651                                                                          PROTO_ITEM_SET_GENERATED(item);
 1652                                                                  }
 1653                                                          }
 1654                                                  }
 1655                                                  /* Now store the response code (after comparison above) */
 1656                                                  mgcp_call->rspcode = mi->rspcode;
 1657                                          }
 1658                                  }
 1659                                  break;
 1660                          case MGCP_REQUEST:
 1661                                  hidden_item = proto_tree_add_boolean(tree, hf_mgcp_req, tvb, 0, 0, TRUE);
 1662                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1663                                  /* Keep track of the address and port whence the call came,
 1664                                   * and the port to which the call is being sent, so that
 1665                                   * we can match up calls with replies.
 1666                                   *
 1667                                   * If the transport is connection-oriented (we check, for 
 1668                                   * now, only for "pinfo->ptype" of PT_TCP), we take
 1669                                   * into  the address from which the call was sent
 1670                                   * and the address to which the call was sent, because 
 1671                                   * the addresses of the two endpoints should be the same
 1672                                   * for all calls and replies.
 1673                                   *
 1674                                   * If the transport is connectionless, we don't worry 
 1675                                   * about the address to which the call was sent and from 
 1676                                   * which the reply was sent, because there's no 
 1677                                   * guarantee that the reply will come from the address 
 1678                                   * to which the call was sent.
 1679                                   */
 1680                                  if (pinfo->ptype == PT_TCP)
 1681                                  {
 1682                                          conversation = find_conversation(pinfo->fd->num, &pinfo->src,
 1683                                                                           &pinfo->dst, pinfo->ptype, pinfo->srcport,
 1684                                                                           pinfo->destport, 0);
 1685                                  }
 1686                                  else 
 1687                                  {
 1688                                          /*
 1689                                           * XXX - can we just use NO_ADDR_B?  Unfortunately,
 1690                                           * you currently still have to pass a non-null
 1691                                           * pointer for the second address argument even 
 1692                                           * if you do that.
 1693                                           */
 1694                                          conversation = find_conversation(pinfo->fd->num, &pinfo->src,
 1695                                                                           &null_address, pinfo->ptype, pinfo->srcport,
 1696                                                                           pinfo->destport, 0);
 1697                                  }
 1698                                  if (conversation == NULL)
 1699                                  {
 1700                                          /* It's not part of any conversation - create a new one. */
 1701                                          if (pinfo->ptype == PT_TCP)
 1702                                          {
 1703                                                  conversation = conversation_new(pinfo->fd->num, &pinfo->src,
 1704                                                                                  &pinfo->dst, pinfo->ptype, pinfo->srcport,
 1705                                                                                  pinfo->destport, 0);
 1706                                          }
 1707                                          else 
 1708                                          {
 1709                                                  conversation = conversation_new(pinfo->fd->num, &pinfo->src,
 1710                                                                                  &null_address, pinfo->ptype, pinfo->srcport,
 1711                                                                                  pinfo->destport, 0);
 1712                                          }
 1713                                  }
 1714   
 1715                                  /* Prepare the key data */
 1716                                  mgcp_call_key.transid = mi->transid;
 1717                                  mgcp_call_key.conversation = conversation;
 1718   
 1719                                  /* Look up the request */
 1720                                  mgcp_call = g_hash_table_lookup(mgcp_calls, &mgcp_call_key);
 1721                                  if (mgcp_call != NULL)
 1722                                  {
 1723                                          /* We've seen a request with this TRANSID, with the same 
 1724                                             source and destination, before - but was it 
 1725                                             *this* request? */
 1726                                          if (pinfo->fd->num != mgcp_call->req_num)
 1727                                          {
 1728                                                  /* No, so it's a duplicate request. Mark it as such. */
 1729                                                  mi->is_duplicate = TRUE;
 1730                                                  mi->req_num = mgcp_call->req_num;
 1731                                                  if (check_col(pinfo->cinfo, COL_INFO))
 1732                                                  {
 1733                                                          col_append_fstr(pinfo->cinfo, COL_INFO,
 1734                                                                          ", Duplicate Request %u",
 1735                                                                          mi->transid);
 1736                                                  }
 1737                                                  if (tree)
 1738                                                  {
 1739                                                          proto_item* item;
 1740                                                          item = proto_tree_add_uint(tree, hf_mgcp_dup, tvb, 0,0, mi->transid);
 1741                                                          PROTO_ITEM_SET_HIDDEN(item);
 1742                                                          item = proto_tree_add_uint(tree, hf_mgcp_req_dup, tvb, 0,0, mi->transid);
 1743                                                          PROTO_ITEM_SET_GENERATED(item);
 1744                                                          item = proto_tree_add_uint(tree, hf_mgcp_req_dup_frame, tvb, 0,0, mi->req_num);
 1745                                                          PROTO_ITEM_SET_GENERATED(item);
 1746                                                  }
 1747                                          }
 1748                                  }
 1749                                  else 
 1750                                  {
 1751                                          /* Prepare the value data.
 1752                                             "req_num" and "rsp_num" are frame numbers;
 1753                                             frame numbers are 1-origin, so we use 0
 1754                                             to mean "we don't yet know in which frame 
 1755                                             the reply for this call appears". */
 1756                                          new_mgcp_call_key = g_mem_chunk_alloc(mgcp_call_info_key_chunk);
 1757                                          *new_mgcp_call_key = mgcp_call_key;
 1758                                          mgcp_call = g_mem_chunk_alloc(mgcp_call_info_value_chunk);
 1759                                          mgcp_call->req_num = pinfo->fd->num;
 1760                                          mgcp_call->rsp_num = 0;
 1761                                          mgcp_call->transid = mi->transid;
 1762                                          mgcp_call->responded = FALSE;
 1763                                          mgcp_call->req_time=pinfo->fd->abs_ts;
 1764                                          g_strlcpy(mgcp_call->code,mi->code,5);
 1765   
 1766                                          /* Store it */
 1767                                          g_hash_table_insert(mgcp_calls, new_mgcp_call_key, mgcp_call);
 1768                                  }
 1769                                  if (mgcp_call && mgcp_call->rsp_num)
 1770                                  {
 1771                                          proto_item* item = proto_tree_add_uint_format(tree, hf_mgcp_rsp_frame,
 1772                                                                                        tvb, 0, 0, mgcp_call->rsp_num,
 1773                                                                                        "The response to this request is in frame %u",
 1774                                                                                        mgcp_call->rsp_num);
 1775                                          PROTO_ITEM_SET_GENERATED(item);
 1776                                  }
 1777                                  break;
 1778                          default:
 1779                                  break;
 1780                  }
 1781   
 1782                  mi->mgcp_type = mgcp_type;
 1783                  if (mgcp_call)
 1784                  {
 1785                          mi->req_time.secs=mgcp_call->req_time.secs;
 1786                          mi->req_time.nsecs=mgcp_call->req_time.nsecs;
 1787                  }
 1788          }
 1789   
 1790          tap_queue_packet(mgcp_tap, pinfo, mi);
 1791  }
Show more  




Change Warning 2740.31478 : Null Test After Dereference

Priority:
State:
Finding:
Owner:
Note: