Text   |  XML   |  ReML   |   Visible Warnings:

Null Test After Dereference  at packet-radius.c:1489

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

dissect_radius

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-radius.c)expand/collapse
Show more  
 1298  dissect_radius(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 1299  {
 1300          proto_tree *radius_tree = NULL;
 1301          proto_tree *avptree = NULL;
 1302          proto_item *ti, *hidden_item;
 1303          proto_item *avptf;
 1304          guint avplength;
 1305          e_radiushdr rh;
 1306          radius_info_t *rad_info;
 1307           
 1308   
 1309          conversation_t* conversation;
 1310          radius_call_info_key radius_call_key;
 1311          radius_call_info_key *new_radius_call_key = NULL;
 1312          radius_call_t *radius_call = NULL;
 1313          nstime_t delta;
 1314          static address null_address = { AT_NONE, 0, NULL };
 1315           
 1316   
 1317          /* does this look like radius ? */
 1318          if(!is_radius(tvb)){
 1319                  return 0;
 1320          }
 1321           
 1322   
 1323          if (check_col(pinfo->cinfo, COL_PROTOCOL))
 1324                  col_set_str(pinfo->cinfo, COL_PROTOCOL, "RADIUS");
 1325          if (check_col(pinfo->cinfo, COL_INFO))
 1326                  col_clear(pinfo->cinfo, COL_INFO);
 1327   
 1328          rh.rh_code=tvb_get_guint8(tvb,0);
 1329          rh.rh_ident=tvb_get_guint8(tvb,1);
 1330          rh.rh_pktlength=tvb_get_ntohs(tvb,2);
 1331   
 1332   
 1333          /* Initialise stat info for passing to tap */
 1334          rad_info = ep_alloc(sizeof(radius_info_t));
 1335          rad_info->code = 0;
 1336          rad_info->ident = 0;
 1337          rad_info->req_time.secs = 0;
 1338          rad_info->req_time.nsecs = 0;
 1339          rad_info->is_duplicate = FALSE;
 1340          rad_info->request_available = FALSE;
 1341          rad_info->req_num = 0; /* frame number request seen */
 1342          rad_info->rspcode = 0;
 1343          /* tap stat info */
 1344          rad_info->code = rh.rh_code;
 1345          rad_info->ident = rh.rh_ident;
 1346          tap_queue_packet(radius_tap, pinfo, rad_info);
 1347   
 1348   
 1349          if (check_col(pinfo->cinfo, COL_INFO))
 1350          {
 1351                  col_add_fstr(pinfo->cinfo,COL_INFO,"%s(%d) (id=%d, l=%d)",
 1352                               val_to_str(rh.rh_code,radius_vals,"Unknown Packet"),
 1353                               rh.rh_code, rh.rh_ident, rh.rh_pktlength);
 1354          }
 1355   
 1356   
 1357          if (tree)
 1358          {
 1359                  /* Forces load of header fields, if not already done so */
 1360                  DISSECTOR_ASSERT(proto_registrar_get_byname("radius.code"));
 1361   
 1362                  ti = proto_tree_add_item(tree,proto_radius, tvb, 0, rh.rh_pktlength, FALSE);
 1363   
 1364                  radius_tree = proto_item_add_subtree(ti, ett_radius);
 1365   
 1366                  proto_tree_add_uint(radius_tree,hf_radius_code, tvb, 0, 1, rh.rh_code);
 1367   
 1368                  proto_tree_add_uint_format(radius_tree,hf_radius_id, tvb, 1, 1, rh.rh_ident,
 1369                                                                     "Packet identifier: 0x%01x (%d)", rh.rh_ident, rh.rh_ident);
 1370          }
 1371   
 1372          /*
 1373           * Make sure the length is sane.
 1374           */
 1375          if (rh.rh_pktlength < HDR_LENGTH)
 1376          {
 1377                  if (tree)
 1378                  {
 1379                          proto_tree_add_uint_format(radius_tree, hf_radius_length,
 1380                                                     tvb, 2, 2, rh.rh_pktlength,
 1381                                                     "Length: %u (bogus, < %u)",
 1382                                                     rh.rh_pktlength, HDR_LENGTH);
 1383                  }
 1384                  goto end_of_radius;
 1385          }
 1386          avplength = rh.rh_pktlength - HDR_LENGTH;
 1387          if (tree)
 1388          {
 1389                  proto_tree_add_uint(radius_tree, hf_radius_length, tvb,
 1390                                      2, 2, rh.rh_pktlength);
 1391   
 1392                  proto_tree_add_item(radius_tree, hf_radius_authenticator, tvb, 4,AUTHENTICATOR_LENGTH,FALSE);
 1393          }
 1394          tvb_memcpy(tvb,authenticator,4,AUTHENTICATOR_LENGTH);
 1395   
 1396          if (tree) {
 1397   
 1398                  /* Conversation support REQUEST/RESPONSES */
 1399                  switch (rh.rh_code)
 1400                  {
 1401                          case RADIUS_ACCESS_REQUEST:
 1402                          case RADIUS_ACCOUNTING_REQUEST:
 1403                          case RADIUS_ACCESS_PASSWORD_REQUEST:
 1404                          case RADIUS_ASCEND_ACCESS_EVENT_REQUEST:
 1405                          case RADIUS_DISCONNECT_REQUEST:
 1406                          case RADIUS_CHANGE_FILTER_REQUEST:
 1407                                  hidden_item = proto_tree_add_boolean(radius_tree, hf_radius_req, tvb, 0, 0, TRUE);
 1408                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1409                                  /* Keep track of the address and port whence the call came 
 1410                                   *  so that we can match up requests with replies.
 1411                                   *
 1412                                   * Because it is UDP and the reply can come from any IP
 1413                                   * and port (not necessarly the request dest), we only
 1414                                   * track the source IP and port of the request to match 
 1415                                   * the reply.
 1416                                   */
 1417   
 1418                                  /*
 1419                                   * XXX - can we just use NO_ADDR_B?  Unfortunately,
 1420                                   * you currently still have to pass a non-null
 1421                                   * pointer for the second address argument even 
 1422                                   * if you do that.
 1423                                   */
 1424                                  conversation = find_conversation(pinfo->fd->num, &pinfo->src,
 1425                                                                           &null_address, pinfo->ptype, pinfo->srcport,
 1426                                                                           pinfo->destport, 0);
 1427                                  if (conversation == NULL)
 1428                                  {
 1429                                          /* It's not part of any conversation - create a new one. */
 1430                                          conversation = conversation_new(pinfo->fd->num, &pinfo->src,
 1431                                                                          &null_address, pinfo->ptype, pinfo->srcport,
 1432                                                                          pinfo->destport, 0);
 1433                                  }
 1434   
 1435                                  /* Prepare the key data */
 1436                                  radius_call_key.code = rh.rh_code;
 1437                                  radius_call_key.ident = rh.rh_ident;
 1438                                  radius_call_key.conversation = conversation;
 1439                                  radius_call_key.req_time = pinfo->fd->abs_ts;
 1440   
 1441                                  /* Look up the request */
 1442                                  radius_call = g_hash_table_lookup(radius_calls, &radius_call_key);
 1443                                  if (radius_call != NULL)
 1444                                  {
 1445                                          /* We've seen a request with this ID, with the same 
 1446                                             destination, before - but was it *this* request? */
 1447                                          if (pinfo->fd->num != radius_call->req_num)
 1448                                          {
 1449                                                  /* No, so it's a duplicate request. Mark it as such. */
 1450                                                  rad_info->is_duplicate = TRUE;
 1451                                                  rad_info->req_num = radius_call->req_num;
 1452                                                  if (check_col(pinfo->cinfo, COL_INFO))
 1453                                                  {
 1454                                                          col_append_fstr(pinfo->cinfo, COL_INFO,
 1455                                                                          ", Duplicate Request ID:%u",
 1456                                                                          rh.rh_ident);
 1457                                                  }
 1458                                                  if (tree)
 1459                                                  {
 1460                                                          proto_item* item;
 1461                                                          hidden_item = proto_tree_add_uint(radius_tree, hf_radius_dup, tvb, 0,0, rh.rh_ident);
 1462                                                          PROTO_ITEM_SET_HIDDEN(hidden_item);
 1463                                                          item = proto_tree_add_uint(radius_tree, hf_radius_req_dup, tvb, 0,0, rh.rh_ident);
 1464                                                          PROTO_ITEM_SET_GENERATED(item);
 1465                                                  }
 1466                                          }
 1467                                  }
 1468                                  else 
 1469                                  {
 1470                                          /* Prepare the value data.
 1471                                             "req_num" and "rsp_num" are frame numbers;
 1472                                             frame numbers are 1-origin, so we use 0
 1473                                             to mean "we don't yet know in which frame 
 1474                                             the reply for this call appears". */
 1475                                          new_radius_call_key = g_mem_chunk_alloc(radius_call_info_key_chunk);
 1476                                          *new_radius_call_key = radius_call_key;
 1477                                          radius_call = g_mem_chunk_alloc(radius_call_info_value_chunk);
 1478                                          radius_call->req_num = pinfo->fd->num;
 1479                                          radius_call->rsp_num = 0;
 1480                                          radius_call->ident = rh.rh_ident;
 1481                                          radius_call->code = rh.rh_code;
 1482                                          radius_call->responded = FALSE;
 1483                                          radius_call->req_time=pinfo->fd->abs_ts;
 1484                                          radius_call->rspcode = 0;
 1485   
 1486                                          /* Store it */
 1487                                          g_hash_table_insert(radius_calls, new_radius_call_key, radius_call);
 1488                                  }
 1489                                  if (radius_call && radius_call->rsp_num)
 1490                                  {
 1491                                          proto_item* item = proto_tree_add_uint_format(radius_tree, hf_radius_rsp_frame,
 1492                                                                                        tvb, 0, 0, radius_call->rsp_num,
 1493                                                                                        "The response to this request is in frame %u",
 1494                                                                                        radius_call->rsp_num);
 1495                                          PROTO_ITEM_SET_GENERATED(item);
 1496                                  }
 1497                                  break;
 1498                          case RADIUS_ACCESS_ACCEPT:
 1499                          case RADIUS_ACCESS_REJECT:
 1500                          case RADIUS_ACCOUNTING_RESPONSE:
 1501                          case RADIUS_ACCESS_PASSWORD_ACK:
 1502                          case RADIUS_ACCESS_PASSWORD_REJECT:
 1503                          case RADIUS_ASCEND_ACCESS_EVENT_RESPONSE:
 1504                          case RADIUS_DISCONNECT_REQUEST_ACK:
 1505                          case RADIUS_DISCONNECT_REQUEST_NAK:
 1506                          case RADIUS_CHANGE_FILTER_REQUEST_ACK:
 1507                          case RADIUS_CHANGE_FILTER_REQUEST_NAK:
 1508                                  hidden_item = proto_tree_add_boolean(radius_tree, hf_radius_rsp, tvb, 0, 0, TRUE);
 1509                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1510                                  /* Check for RADIUS response.  A response must match a call that
 1511                                   * we've seen, and the response must be sent to the same 
 1512                                   * port and address that the call came from.
 1513                                   *
 1514                                   * Because it is UDP and the reply can come from any IP
 1515                                   * and port (not necessarly the request dest), we only
 1516                                   * track the source IP and port of the request to match 
 1517                                   * the reply.
 1518                                   */
 1519   
 1520                                  /* XXX - can we just use NO_ADDR_B?  Unfortunately,
 1521                                   * you currently still have to pass a non-null
 1522                                   * pointer for the second address argument even 
 1523                                   * if you do that.
 1524                                   */
 1525                                  conversation = find_conversation(pinfo->fd->num, &null_address,
 1526                                                                           &pinfo->dst, pinfo->ptype, pinfo->srcport,
 1527                                                                           pinfo->destport, 0);
 1528                                  if (conversation != NULL)
 1529                                  {
 1530                                          /* Look only for matching request, if 
 1531                                             matching conversation is available. */
 1532                                          /* Prepare the key data */
 1533                                          radius_call_key.code = rh.rh_code;
 1534                                          radius_call_key.ident = rh.rh_ident;
 1535                                          radius_call_key.conversation = conversation;
 1536                                          radius_call_key.req_time = pinfo->fd->abs_ts;
 1537   
 1538                                          radius_call = g_hash_table_lookup(radius_calls, &radius_call_key);
 1539                                          if (radius_call)
 1540                                          {
 1541                                                  /* Indicate the frame to which this is a reply. */
 1542                                                  if (radius_call->req_num)
 1543                                                  {
 1544                                                          proto_item* item;
 1545                                                          rad_info->request_available = TRUE;
 1546                                                          rad_info->req_num = radius_call->req_num;
 1547                                                          radius_call->responded = TRUE;
 1548   
 1549                                                          item = proto_tree_add_uint_format(radius_tree, hf_radius_req_frame,
 1550                                                                                            tvb, 0, 0, radius_call->req_num,
 1551                                                                                            "This is a response to a request in frame %u",
 1552                                                                                            radius_call->req_num);
 1553                                                          PROTO_ITEM_SET_GENERATED(item);
 1554                                                          nstime_delta(&delta, &pinfo->fd->abs_ts, &radius_call->req_time);
 1555                                                          item = proto_tree_add_time(radius_tree, hf_radius_time, tvb, 0, 0, &delta);
 1556                                                          PROTO_ITEM_SET_GENERATED(item);
 1557                                                  }
 1558   
 1559                                                  if (radius_call->rsp_num == 0)
 1560                                                  {
 1561                                                          /* We have not yet seen a response to that call, so 
 1562                                                             this must be the first response; remember its
 1563                                                             frame number. */
 1564                                                          radius_call->rsp_num = pinfo->fd->num;
 1565                                                  }
 1566                                                  else 
 1567                                                  {
 1568                                                          /* We have seen a response to this call - but was it 
 1569                                                             *this* response? (disregard provisional responses) */
 1570                                                          if ( (radius_call->rsp_num != pinfo->fd->num) && (radius_call->rspcode == rh.rh_code) )
 1571                                                          {
 1572                                                                  /* No, so it's a duplicate response. Mark it as such. */
 1573                                                                  rad_info->is_duplicate = TRUE;
 1574                                                                  if (check_col(pinfo->cinfo, COL_INFO))
 1575                                                                  {
 1576                                                                          col_append_fstr(pinfo->cinfo, COL_INFO,
 1577                                                                                          ", Duplicate Response ID:%u",
 1578                                                                                          rh.rh_ident);
 1579                                                                  }
 1580                                                                  if (tree)
 1581                                                                  {
 1582                                                                          proto_item* item;
 1583                                                                          hidden_item = proto_tree_add_uint(radius_tree, hf_radius_dup, tvb, 0,0, rh.rh_ident);
 1584                                                                          PROTO_ITEM_SET_HIDDEN(hidden_item);
 1585                                                                          item = proto_tree_add_uint(radius_tree, hf_radius_rsp_dup,
 1586                                                                                                     tvb, 0, 0, rh.rh_ident);
 1587                                                                          PROTO_ITEM_SET_GENERATED(item);
 1588                                                                  }
 1589                                                          }
 1590                                                  }
 1591                                                  /* Now store the response code (after comparison above) */
 1592                                                  radius_call->rspcode = rh.rh_code;
 1593                                                  rad_info->rspcode = rh.rh_code;
 1594                                          }
 1595                                  }
 1596                                  break;
 1597                          default:
 1598                                  break;
 1599                  }
 1600   
 1601                  if (radius_call)
 1602                  {
 1603                          rad_info->req_time.secs = radius_call->req_time.secs;
 1604                          rad_info->req_time.nsecs = radius_call->req_time.nsecs;
 1605                  }
 1606   
 1607                  if (avplength > 0) {
 1608                          /* list the attribute value pairs */
 1609                          avptf = proto_tree_add_text(radius_tree, tvb, HDR_LENGTH,
 1610                                                          avplength, "Attribute Value Pairs");
 1611                          avptree = proto_item_add_subtree(avptf, ett_radius_avp);
 1612   
 1613                          dissect_attribute_value_pairs(avptree, pinfo, tvb, HDR_LENGTH,
 1614                                                            avplength);
 1615                  }
 1616          }
 1617   
 1618  end_of_radius:
 1619          return tvb_length(tvb);
 1620  }
Show more  




Change Warning 2906.32365 : Null Test After Dereference

Priority:
State:
Finding:
Owner:
Note: