Text   |  XML   |  ReML   |   Visible Warnings:

Null Test After Dereference  at packet-ldss.c:749

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

dissect_ldss_transfer

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-ldss.c)expand/collapse
Show more  
 457  dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 458  {
 459          conversation_t *transfer_conv;
 460          ldss_transfer_info_t *transfer_info;
 461          struct tcpinfo *transfer_tcpinfo;
 462   
 463          proto_tree      *ti, *line_tree = NULL, *ldss_tree = NULL;
 464   
 465          nstime_t broadcast_response_time;
 466   
 467          /* Look for the transfer conversation; this was created during
 468           * earlier broadcast dissection (see prepate_ldss_transfer_conv) */
 469          transfer_conv = find_conversation (pinfo->fd->num, &pinfo->src, &pinfo->dst,
 470                                             PT_TCP, pinfo->srcport, pinfo->destport, 0);
 471          transfer_info = conversation_get_proto_data(transfer_conv, proto_ldss);
 472          transfer_tcpinfo = pinfo->private_data;
 473   
 474          /* For a pull, the first packet in the TCP connection is the file request.
 475           * First packet is identified by relative seq/ack numbers of 1.
 476           * File request only appears on a pull (triggered by an offer - see above
 477           * about broadcasts) */
 478          if (transfer_tcpinfo->seq == 1 &&
 479              transfer_tcpinfo->lastackseq == 1 &&
 480              transfer_info->broadcast->message_id == MESSAGE_ID_WILLSEND) {
 481                  /* LDSS pull transfers look a lot like HTTP.
 482                   * Sample request:
 483                   * md5:01234567890123...
 484                   * Size: 2550 
 485                   * Start: 0 
 486                   * Compression: 0 
 487                   * (remote end sends the file identified by the digest) */
 488                  guint offset = 0;
 489                  gboolean already_dissected = TRUE;
 490   
 491                  if (check_col(pinfo->cinfo, COL_INFO)) {
 492                          col_add_str(pinfo->cinfo, COL_INFO, "LDSS File Transfer (Requesting file - pull)");
 493                  }
 494   
 495                  if (highest_num_seen == 0 ||
 496                      highest_num_seen < pinfo->fd->num) {
 497   
 498                          already_dissected = FALSE;
 499                          transfer_info->req = se_alloc0(sizeof(ldss_file_request_t));
 500                          transfer_info->req->file = se_alloc0(sizeof(ldss_file_t));
 501                          highest_num_seen = pinfo->fd->num;
 502                  }
 503           
 504                  if (tree) {
 505                          ti = proto_tree_add_item(tree, proto_ldss,
 506                                                   tvb, 0, tvb_reported_length(tvb), FALSE);
 507                          ldss_tree = proto_item_add_subtree(ti, ett_ldss_transfer);
 508                  }
 509   
 510                  /* Populate digest data into the file struct in the request */
 511                  transfer_info->file = transfer_info->req->file;
 512   
 513                  /* Grab each line from the packet, there should be 4 but lets
 514                   * not walk off the end looking for more. */
 515                  while (offset < tvb_reported_length(tvb)) {
 516                          gint next_offset;
 517                          const guint8 *line;
 518                          int linelen;
 519                          gboolean is_digest_line;
 520                          guint digest_type_len;
 521   
 522                          linelen = tvb_find_line_end(tvb, offset,
 523                                                      tvb_ensure_length_remaining(tvb, offset), &next_offset,
 524                                                      FALSE);
 525   
 526                          /* Include new-line in line */
 527                          line = tvb_memdup(tvb, offset, linelen+1); /* XXX - memory leak? */
 528   
 529                          if (tree) {
 530                                  ti = proto_tree_add_text(ldss_tree, tvb, offset, linelen,
 531                                                           "%s",
 532                                                           tvb_format_text(tvb, offset, next_offset-offset));
 533                                  line_tree = proto_item_add_subtree(ti, ett_ldss_transfer_req);
 534                          }
 535   
 536                          /* Reduce code duplication processing digest lines.
 537                           * There are too many locals to pass to a function - the signature
 538                           * looked pretty ugly when I tried! */
 539                          is_digest_line = FALSE;
 540                           
 541                          if (strncmp(line,"md5:",4)==0) {
 542                                  is_digest_line = TRUE;
 543                                  digest_type_len = 4;
 544                                  transfer_info->file->digest_type = DIGEST_TYPE_MD5;
 545                          }
 546                          else if (strncmp(line, "sha1:", 5)==0) {
 547                                  is_digest_line = TRUE;
 548                                  digest_type_len = 5;
 549                                  transfer_info->file->digest_type = DIGEST_TYPE_SHA1;
 550                          }
 551                          else if (strncmp(line, "sha256:", 7)==0) {
 552                                  is_digest_line = TRUE;
 553                                  digest_type_len = 7;
 554                                  transfer_info->file->digest_type = DIGEST_TYPE_SHA256;
 555                          }
 556                          else if (strncmp(line, "unknown:", 8)==0) {
 557                                  is_digest_line = TRUE;
 558                                  digest_type_len = 8;
 559                                  transfer_info->file->digest_type = DIGEST_TYPE_UNKNOWN;
 560                          }
 561                          else if (strncmp(line, "Size: ", 6)==0) {
 562                                  /* Sample size line:
 563                                   * Size: 2550\n */
 564                                  transfer_info->req->size = g_ascii_strtoull(line+6, NULL, 10);
 565                                  if (tree) {
 566                                          ti = proto_tree_add_uint64(line_tree, hf_ldss_size,
 567                                                                     tvb, offset+6, linelen-6, transfer_info->req->size);
 568                                          PROTO_ITEM_SET_GENERATED(ti);
 569                                  }
 570                          }
 571                          else if (strncmp(line, "Start: ", 7)==0) {
 572                                  /* Sample offset line:
 573                                   * Start: 0\n */
 574                                  transfer_info->req->offset = g_ascii_strtoull(line+7, NULL, 10);
 575                                  if (tree) {
 576                                          ti = proto_tree_add_uint64(line_tree, hf_ldss_offset,
 577                                                                     tvb, offset+7, linelen-7, transfer_info->req->offset);
 578                                          PROTO_ITEM_SET_GENERATED(ti);
 579                                  }
 580                          }
 581                          else if (strncmp(line, "Compression: ", 13)==0) {
 582                                  /* Sample compression line:
 583                                   * Compression: 0\n */
 584                                  transfer_info->req->compression = (gint8)strtol(line+13, NULL, 10); /* XXX - bad cast */
 585                                  if (tree) {
 586                                          ti = proto_tree_add_uint(line_tree, hf_ldss_compression,
 587                                                                   tvb, offset+13, linelen-13, transfer_info->req->compression);
 588                                          PROTO_ITEM_SET_GENERATED(ti);
 589                                  }
 590                          }
 591                          else {
 592                                  if (tree) {
 593                                          ti = proto_tree_add_text(line_tree, tvb, offset, linelen,
 594                                                                   "Unrecognized line ignored");
 595                                          PROTO_ITEM_SET_GENERATED(ti);
 596                                  }
 597                          }
 598                           
 599                          if (is_digest_line) {
 600                                  /* Sample digest-type/digest line:
 601                                   * md5:0123456789ABCDEF\n */
 602                                  if (!already_dissected) {
 603                                          GByteArray *digest_bytes;
 604   
 605                                          digest_bytes = g_byte_array_new();
 606                                          hex_str_to_bytes(
 607                                                  tvb_get_ptr(tvb, offset+digest_type_len, linelen-digest_type_len),
 608                                                  digest_bytes, FALSE);
 609   
 610                                          /* Ensure the digest is zero-padded */
 611                                          transfer_info->file->digest = se_alloc0(DIGEST_LEN);
 612                                          memcpy(transfer_info->file->digest, digest_bytes->data, digest_bytes->len);
 613   
 614                                          g_byte_array_free(digest_bytes, TRUE);
 615                                  }
 616                                  if (tree) {
 617                                          proto_item *ti = NULL;
 618   
 619                                          ti = proto_tree_add_uint(line_tree, hf_ldss_digest_type,
 620                                                                   tvb, offset, digest_type_len, transfer_info->file->digest_type);
 621                                          PROTO_ITEM_SET_GENERATED(ti);
 622                                          ti = proto_tree_add_bytes(line_tree, hf_ldss_digest,
 623                                                                    tvb, offset+digest_type_len, linelen-digest_type_len,
 624                                                                    transfer_info->file->digest);
 625                                          PROTO_ITEM_SET_GENERATED(ti);
 626                                  }
 627                          }
 628   
 629                          offset = next_offset;
 630                  }
 631   
 632                  /* Link forwards to the response for this pull. */
 633                  if (tree && transfer_info->resp_num != 0) {
 634                          ti = proto_tree_add_uint(ldss_tree, hf_ldss_response_in,
 635                                                   tvb, 0, 0, transfer_info->resp_num);
 636                          PROTO_ITEM_SET_GENERATED(ti);
 637                  }
 638   
 639                  transfer_info->req->num = pinfo->fd->num;
 640                  transfer_info->req->ts = pinfo->fd->abs_ts;
 641          }
 642          /* Remaining packets are the file response */
 643          else {
 644                  guint64 size;
 645                  guint64 offset;
 646                  guint8 compression;
 647   
 648                  /* size, digest, compression come from the file request for a pull but
 649                   * they come from the broadcast for a push. Pushes don't bother 
 650                   * with a file request - they just send the data. We have to get file 
 651                   * info from the offer broadcast which triggered this transfer.
 652                   * If we cannot find the file request, default to the broadcast. */
 653                  if (transfer_info->broadcast->message_id == MESSAGE_ID_WILLSEND &&
 654                      transfer_info->req != NULL) {
 655                          transfer_info->file = transfer_info->req->file;
 656                          size = transfer_info->req->size;
 657                          offset = transfer_info->req->offset;
 658                          compression = transfer_info->req->compression;
 659                  }
 660                  else {
 661                          transfer_info->file = transfer_info->broadcast->file;
 662                          size = transfer_info->broadcast->size;
 663                          offset = transfer_info->broadcast->offset;
 664                          compression = transfer_info->broadcast->compression;
 665                  }
 666   
 667                  /* Remaining data in this TCP connection is all file data.
 668                   * Always desegment if the size is 0 (ie. unknown)
 669                   */
 670                  if (pinfo->can_desegment) {
 671                          if (size == 0 || tvb_length(tvb) < size) {
 672                                  pinfo->desegment_offset = 0;
 673                                  pinfo->desegment_len = DESEGMENT_UNTIL_FIN;
 674                                  return 0;
 675                          }
 676                  }
 677   
 678                  /* OK. Now we have the whole file that was transferred. */
 679                  transfer_info->resp_num = pinfo->fd->num;
 680                  transfer_info->resp_ts = pinfo->fd->abs_ts;
 681   
 682                  if (check_col(pinfo->cinfo, COL_INFO)) {
 683                          col_add_fstr(pinfo->cinfo, COL_INFO, "LDSS File Transfer (Sending file - %s)",
 684                                       transfer_info->broadcast->message_id == MESSAGE_ID_WILLSEND 
 685                                       ? "pull"
 686                                       : "push");
 687                  }
 688   
 689                  if (tree) {
 690                          ti = proto_tree_add_item(tree, proto_ldss,
 691                                                   tvb, 0, tvb_reported_length(tvb), FALSE);
 692                          ldss_tree = proto_item_add_subtree(ti, ett_ldss_transfer);
 693                          ti = proto_tree_add_bytes_format(ldss_tree, hf_ldss_file_data,
 694                                                           tvb, 0, tvb_length(tvb),
 695                                                           tvb_get_ptr (tvb, 0, tvb_length(tvb)),
 696                                                           compression == COMPRESSION_GZIP 
 697                                                           ? "Gzip compressed data: %d bytes"
 698                                                           : "File data: %d bytes",
 699                                                           tvb_length(tvb));
 700  #ifdef HAVE_LIBZ 
 701                          /* Be nice and uncompress the file data. */
 702                          if (compression == COMPRESSION_GZIP) {
 703                                  tvbuff_t *uncomp_tvb = NULL;
 704                                  uncomp_tvb = tvb_uncompress(tvb, 0, tvb_length(tvb));
 705                                  if (uncomp_tvb != NULL) {
 706                                          ti = proto_tree_add_bytes_format_value(ldss_tree, hf_ldss_file_data,
 707                                                                                 uncomp_tvb, 0, tvb_length(uncomp_tvb),
 708                                                                                 tvb_get_ptr (uncomp_tvb, 0, tvb_length(uncomp_tvb)),
 709                                                                                 "Uncompressed data: %d bytes",
 710                                                                                 tvb_length(uncomp_tvb));
 711                                  }
 712                          }
 713  #endif
 714                          ti = proto_tree_add_uint(ldss_tree, hf_ldss_digest_type,
 715                                                   tvb, 0, 0, transfer_info->file->digest_type);
 716                          PROTO_ITEM_SET_GENERATED(ti);
 717                          if (transfer_info->file->digest != NULL) {
 718                                  /* This is ugly. You can't add bytes of nonzero length and have 
 719                                   * filtering work correctly unless you give a valid location in
 720                                   * the packet. This hack pretends the first 32 bytes of the packet
 721                                   * are the digest, which they aren't: they're actually the first 32
 722                                   * bytes of the file that was sent. */
 723                                  ti = proto_tree_add_bytes(ldss_tree, hf_ldss_digest,
 724                                                            tvb, 0, DIGEST_LEN, transfer_info->file->digest);
 725                          }
 726                          PROTO_ITEM_SET_GENERATED(ti);
 727                          ti = proto_tree_add_uint64(ldss_tree, hf_ldss_size,
 728                                                     tvb, 0, 0, size);
 729                          PROTO_ITEM_SET_GENERATED(ti);
 730                          ti = proto_tree_add_uint64(ldss_tree, hf_ldss_offset,
 731                                                     tvb, 0, 0, offset);
 732                          PROTO_ITEM_SET_GENERATED(ti);
 733                          ti = proto_tree_add_uint(ldss_tree, hf_ldss_compression,
 734                                                   tvb, 0, 0, compression);
 735                          PROTO_ITEM_SET_GENERATED(ti);
 736                          /* Link to the request for a pull. */
 737                          if (transfer_info->broadcast->message_id == MESSAGE_ID_WILLSEND &&
 738                              transfer_info->req != NULL &&
 739                              transfer_info->req->num != 0) {
 740                                  ti = proto_tree_add_uint(ldss_tree, hf_ldss_response_to,
 741                                                           tvb, 0, 0, transfer_info->req->num);
 742                                  PROTO_ITEM_SET_GENERATED(ti);
 743                          }
 744                  }
 745          }
 746   
 747          /* Print the pull response time */
 748          if (transfer_info->broadcast->message_id == MESSAGE_ID_WILLSEND &&
 749              transfer_info->req != NULL &&
 750              transfer_info->resp_num != 0) {
 751                  nstime_t pull_response_time;
 752                  nstime_delta(&pull_response_time, &transfer_info->resp_ts,
 753                               &transfer_info->req->ts);
 754                  ti = proto_tree_add_time(ldss_tree, hf_ldss_transfer_response_time,
 755                                           tvb, 0, 0, &pull_response_time);
 756                  PROTO_ITEM_SET_GENERATED(ti);
 757          }
 758   
 759          /* Link the transfer back to the initiating broadcast. Response time is 
 760           * calculated as the time from broadcast to completed transfer. */      
 761          ti = proto_tree_add_uint(ldss_tree, hf_ldss_initiated_by,
 762                                   tvb, 0, 0, transfer_info->broadcast->num);
 763          PROTO_ITEM_SET_GENERATED(ti);
 764   
 765          if (transfer_info->resp_num != 0) {
 766                  nstime_delta(&broadcast_response_time, &transfer_info->resp_ts,
 767                               &transfer_info->broadcast->ts);
 768                  ti = proto_tree_add_time(ldss_tree, hf_ldss_transfer_completed_in,
 769                                           tvb, 0, 0, &broadcast_response_time);
 770                  PROTO_ITEM_SET_GENERATED(ti);
 771          }
 772   
 773          /* This conv got its addr2/port2 set by the TCP dissector because a TCP
 774           * connection was established. Make a new one to handle future connections
 775           * to the addr/port mentioned in the broadcast, because that socket is
 776           * still open. */
 777          if (transfer_tcpinfo->seq == 1 &&
 778              transfer_tcpinfo->lastackseq == 1) {
 779   
 780                  prepare_ldss_transfer_conv(transfer_info->broadcast);
 781          }
 782   
 783          return tvb_length(tvb);
 784  }
Show more  




Change Warning 12371.32203 : Null Test After Dereference

Because they are very similar, this warning shares annotations with warning 12371.32204.

Priority:
State:
Finding:
Owner:
Note: