Text   |  XML   |  ReML   |   Visible Warnings:

Unreachable Control Flow  at packet-udp.c:484

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

dissect

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-udp.c)expand/collapse
Show more  
 304  dissect(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 ip_proto)
 305  {
 306    proto_tree *udp_tree = NULL;
 307    proto_item *ti, *hidden_item;
 308    guint      len;
 309    guint      reported_len;
 310    vec_t      cksum_vec[4];
 311    guint32    phdr[2];
 312    guint16    computed_cksum;
 313    int        offset = 0;
 314    e_udphdr *udph;
 315    proto_tree *checksum_tree;
 316    proto_item *item;
 317    conversation_t *conv = NULL;
 318    struct udp_analysis *udpd = NULL;
 319    proto_tree *process_tree;
 320   
 321    udph=ep_alloc(sizeof(e_udphdr));
 322    SET_ADDRESS(&udph->ip_src, pinfo->src.type, pinfo->src.len, pinfo->src.data);
 323    SET_ADDRESS(&udph->ip_dst, pinfo->dst.type, pinfo->dst.len, pinfo->dst.data);
 324   
 325    if (check_col(pinfo->cinfo, COL_PROTOCOL))
 326      col_set_str(pinfo->cinfo, COL_PROTOCOL, (ip_proto == IP_PROTO_UDP) ? "UDP" : "UDPlite");
 327    if (check_col(pinfo->cinfo, COL_INFO))
 328      col_clear(pinfo->cinfo, COL_INFO);
 329   
 330    udph->uh_sport=tvb_get_ntohs(tvb, offset);
 331    udph->uh_dport=tvb_get_ntohs(tvb, offset+2);
 332   
 333    if (check_col(pinfo->cinfo, COL_INFO))
 334      col_add_fstr(pinfo->cinfo, COL_INFO, "Source port: %s  Destination port: %s",
 335              get_udp_port(udph->uh_sport), get_udp_port(udph->uh_dport));
 336   
 337    if (tree) {
 338      if (udp_summary_in_tree) {
 339        if (ip_proto == IP_PROTO_UDP) {
 340          ti = proto_tree_add_protocol_format(tree, proto_udp, tvb, offset, 8,
 341          "User Datagram Protocol, Src Port: %s (%u), Dst Port: %s (%u)",
 342          get_udp_port(udph->uh_sport), udph->uh_sport, get_udp_port(udph->uh_dport), udph->uh_dport);
 343        } else {
 344          ti = proto_tree_add_protocol_format(tree, proto_udplite, tvb, offset, 8,
 345          "Lightweight User Datagram Protocol, Src Port: %s (%u), Dst Port: %s (%u)",
 346          get_udp_port(udph->uh_sport), udph->uh_sport, get_udp_port(udph->uh_dport), udph->uh_dport);
 347        }
 348      } else {
 349        ti = proto_tree_add_item(tree, (ip_proto == IP_PROTO_UDP) ? proto_udp : proto_udplite, tvb, offset, 8, FALSE);
 350      }
 351      udp_tree = proto_item_add_subtree(ti, ett_udp);
 352   
 353      proto_tree_add_uint_format(udp_tree, hf_udp_srcport, tvb, offset, 2, udph->uh_sport,
 354          "Source port: %s (%u)", get_udp_port(udph->uh_sport), udph->uh_sport);
 355      proto_tree_add_uint_format(udp_tree, hf_udp_dstport, tvb, offset + 2, 2, udph->uh_dport,
 356          "Destination port: %s (%u)", get_udp_port(udph->uh_dport), udph->uh_dport);
 357   
 358      hidden_item = proto_tree_add_uint(udp_tree, hf_udp_port, tvb, offset, 2, udph->uh_sport);
 359      PROTO_ITEM_SET_HIDDEN(hidden_item);
 360      hidden_item = proto_tree_add_uint(udp_tree, hf_udp_port, tvb, offset+2, 2, udph->uh_dport);
 361      PROTO_ITEM_SET_HIDDEN(hidden_item);
 362    }
 363   
 364    if (ip_proto == IP_PROTO_UDP) {
 365      udph->uh_ulen = udph->uh_sum_cov = tvb_get_ntohs(tvb, offset+4);
 366      if (udph->uh_ulen < 8) {
 367        /* Bogus length - it includes the header, so it must be >= 8. */
 368        /* XXX - should handle IPv6 UDP jumbograms (RFC 2675), where the length is zero */
 369        item = proto_tree_add_uint_format(udp_tree, hf_udp_length, tvb, offset + 4, 2,
 370            udph->uh_ulen, "Length: %u (bogus, must be >= 8)", udph->uh_ulen);
 371        expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Bad length value %u < 8", udph->uh_ulen);
 372        if (check_col(pinfo->cinfo, COL_INFO))
 373          col_append_fstr(pinfo->cinfo, COL_INFO, " [BAD UDP LENGTH %u < 8]", udph->uh_ulen);
 374        return;
 375      }
 376      if ((udph->uh_ulen > tvb_reported_length(tvb)) && ! pinfo->fragmented && ! pinfo->in_error_pkt) {
 377        /* Bogus length - it goes past the end of the IP payload */
 378        item = proto_tree_add_uint_format(udp_tree, hf_udp_length, tvb, offset + 4, 2,
 379            udph->uh_ulen, "Length: %u (bogus, payload length %u)", udph->uh_ulen, tvb_reported_length(tvb));
 380        expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Bad length value %u > IP payload length", udph->uh_ulen);
 381        if (check_col(pinfo->cinfo, COL_INFO))
 382          col_append_fstr(pinfo->cinfo, COL_INFO, " [BAD UDP LENGTH %u > IP PAYLOAD LENGTH]", udph->uh_ulen);
 383      } else {
 384        if (tree) {
 385          proto_tree_add_uint(udp_tree, hf_udp_length, tvb, offset + 4, 2, udph->uh_ulen);
 386          /* XXX - why is this here, given that this is UDP, not Lightweight UDP? */
 387          hidden_item = proto_tree_add_uint(udp_tree, hf_udplite_checksum_coverage, tvb, offset + 4,
 388                                            0, udph->uh_sum_cov);
 389          PROTO_ITEM_SET_HIDDEN(hidden_item);
 390        }
 391      }
 392    } else {
 393      udph->uh_ulen = pinfo->iplen - pinfo->iphdrlen;
 394      udph->uh_sum_cov = tvb_get_ntohs(tvb, offset+4);
 395      if (((udph->uh_sum_cov > 0) && (udph->uh_sum_cov < 8)) || (udph->uh_sum_cov > udph->uh_ulen)) {
 396        /* Bogus length - it includes the header, so it must be >= 8, and no larger then the IP payload size. */
 397        if (tree) {
 398          hidden_item = proto_tree_add_boolean(udp_tree, hf_udplite_checksum_coverage_bad, tvb, offset + 4, 2, TRUE);
 399          PROTO_ITEM_SET_HIDDEN(hidden_item);
 400          hidden_item = proto_tree_add_uint(udp_tree, hf_udp_length, tvb, offset + 4, 0, udph->uh_ulen);
 401          PROTO_ITEM_SET_HIDDEN(hidden_item);
 402        }
 403        item = proto_tree_add_uint_format(udp_tree, hf_udplite_checksum_coverage, tvb, offset + 4, 2,
 404            udph->uh_sum_cov, "Checksum coverage: %u (bogus, must be >= 8 and <= %u (ip.len-ip.hdr_len))",
 405            udph->uh_sum_cov, udph->uh_ulen);
 406        expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Bad checksum coverage length value %u < 8 or > %u",
 407                               udph->uh_sum_cov, udph->uh_ulen);
 408        if (check_col(pinfo->cinfo, COL_INFO))
 409          col_append_fstr(pinfo->cinfo, COL_INFO, " [BAD LIGHTWEIGHT UDP CHECKSUM COVERAGE LENGTH %u < 8 or > %u]",
 410                          udph->uh_sum_cov, udph->uh_ulen);
 411        if (!udplite_ignore_checksum_coverage)
 412          return;
 413      } else {
 414        if (tree) {
 415          hidden_item = proto_tree_add_uint(udp_tree, hf_udp_length, tvb, offset + 4, 0, udph->uh_ulen);
 416          PROTO_ITEM_SET_HIDDEN(hidden_item);
 417          proto_tree_add_uint(udp_tree, hf_udplite_checksum_coverage, tvb, offset + 4, 2, udph->uh_sum_cov);
 418        }
 419      }
 420    }
 421   
 422    udph->uh_sum_cov = (udph->uh_sum_cov) ? udph->uh_sum_cov : udph->uh_ulen;
 423    udph->uh_sum = tvb_get_ntohs(tvb, offset+6);
 424    reported_len = tvb_reported_length(tvb);
 425    len = tvb_length(tvb);
 426    if (udph->uh_sum == 0) {
 427      /* No checksum supplied in the packet. */
 428      if (ip_proto == IP_PROTO_UDP) {
 429        item = proto_tree_add_uint_format(udp_tree, hf_udp_checksum, tvb, offset + 6, 2, 0,
 430          "Checksum: 0x%04x (none)", 0);
 431   
 432        checksum_tree = proto_item_add_subtree(item, ett_udp_checksum);
 433        proto_tree_add_boolean(checksum_tree, hf_udp_checksum_good, tvb,
 434                               offset + 6, 2, FALSE);
 435        proto_tree_add_boolean(checksum_tree, hf_udp_checksum_bad, tvb,
 436                               offset + 6, 2, FALSE);
 437      } else {
 438        item = proto_tree_add_uint_format(udp_tree, hf_udp_checksum, tvb, offset + 6, 2, 0,
 439          "Checksum: 0x%04x (Illegal)", 0);
 440        expert_add_info_format(pinfo, item, PI_CHECKSUM, PI_ERROR, "Illegal Checksum value (0)");
 441        if (check_col(pinfo->cinfo, COL_INFO))
 442          col_append_fstr(pinfo->cinfo, COL_INFO, " [ILLEGAL CHECKSUM (0)]");
 443   
 444        checksum_tree = proto_item_add_subtree(item, ett_udp_checksum);
 445        item = proto_tree_add_boolean(checksum_tree, hf_udp_checksum_good, tvb,
 446                               offset + 6, 2, FALSE);
 447        PROTO_ITEM_SET_GENERATED(item);
 448        item = proto_tree_add_boolean(checksum_tree, hf_udp_checksum_bad, tvb,
 449                               offset + 6, 2, TRUE);
 450        PROTO_ITEM_SET_GENERATED(item);
 451      }
 452    } else if (!pinfo->fragmented && len >= reported_len &&
 453               len >= udph->uh_sum_cov && reported_len >= udph->uh_sum_cov &&
 454               udph->uh_sum_cov >=8) {
 455      /* The packet isn't part of a fragmented datagram and isn't
 456         truncated, so we can checksum it.
 457         XXX - make a bigger scatter-gather list once we do fragment 
 458         reassembly? */
 459   
 460      if (((ip_proto == IP_PROTO_UDP) && (udp_check_checksum)) ||
 461          ((ip_proto == IP_PROTO_UDPLITE) && (udplite_check_checksum))) {
 462        /* Set up the fields of the pseudo-header. */
 463        cksum_vec[0].ptr = pinfo->src.data;
 464        cksum_vec[0].len = pinfo->src.len;
 465        cksum_vec[1].ptr = pinfo->dst.data;
 466        cksum_vec[1].len = pinfo->dst.len;
 467        cksum_vec[2].ptr = (const guint8 *)&phdr;
 468        switch (pinfo->src.type) {
 469   
 470        case AT_IPv4:
 471          phdr[0] = g_htonl((ip_proto<<16) + reported_len);
 472          cksum_vec[2].len = 4;
 473          break;
 474   
 475        case AT_IPv6:
 476          phdr[0] = g_htonl(reported_len);
 477          phdr[1] = g_htonl(ip_proto);
 478          cksum_vec[2].len = 8;
 479          break;
 480   
 481        default:
 482          /* UDP runs only atop IPv4 and IPv6.... */
 483          DISSECTOR_ASSERT_NOT_REACHED();
 484          break;
 485        }
 486        cksum_vec[3].ptr = tvb_get_ptr(tvb, offset, udph->uh_sum_cov);
 487        cksum_vec[3].len = udph->uh_sum_cov;
 488        computed_cksum = in_cksum(&cksum_vec[0], 4);
 489        if (computed_cksum == 0) {
 490          item = proto_tree_add_uint_format(udp_tree, hf_udp_checksum, tvb,
 491            offset + 6, 2, udph->uh_sum, "Checksum: 0x%04x [correct]", udph->uh_sum);
 492   
 493          checksum_tree = proto_item_add_subtree(item, ett_udp_checksum);
 494          item = proto_tree_add_boolean(checksum_tree, hf_udp_checksum_good, tvb,
 495                                        offset + 6, 2, TRUE);
 496          PROTO_ITEM_SET_GENERATED(item);
 497          item = proto_tree_add_boolean(checksum_tree, hf_udp_checksum_bad, tvb,
 498                                        offset + 6, 2, FALSE);
 499          PROTO_ITEM_SET_GENERATED(item);
 500        } else {
 501          item = proto_tree_add_uint_format(udp_tree, hf_udp_checksum, tvb,
 502                                            offset + 6, 2, udph->uh_sum,
 503            "Checksum: 0x%04x [incorrect, should be 0x%04x (maybe caused by \"UDP checksum offload\"?)]", udph->uh_sum,
 504            in_cksum_shouldbe(udph->uh_sum, computed_cksum));
 505   
 506          checksum_tree = proto_item_add_subtree(item, ett_udp_checksum);
 507          item = proto_tree_add_boolean(checksum_tree, hf_udp_checksum_good, tvb,
 508                                        offset + 6, 2, FALSE);
 509          PROTO_ITEM_SET_GENERATED(item);
 510          item = proto_tree_add_boolean(checksum_tree, hf_udp_checksum_bad, tvb,
 511                                        offset + 6, 2, TRUE);
 512          PROTO_ITEM_SET_GENERATED(item);
 513          expert_add_info_format(pinfo, item, PI_CHECKSUM, PI_ERROR, "Bad checksum");
 514   
 515          if (check_col(pinfo->cinfo, COL_INFO))
 516            col_append_fstr(pinfo->cinfo, COL_INFO, " [UDP CHECKSUM INCORRECT]");
 517        }
 518      } else {
 519        item = proto_tree_add_uint_format(udp_tree, hf_udp_checksum, tvb,
 520          offset + 6, 2, udph->uh_sum, "Checksum: 0x%04x [validation disabled]", udph->uh_sum);
 521        checksum_tree = proto_item_add_subtree(item, ett_udp_checksum);
 522        item = proto_tree_add_boolean(checksum_tree, hf_udp_checksum_good, tvb,
 523                               offset + 6, 2, FALSE);
 524        PROTO_ITEM_SET_GENERATED(item);
 525        item = proto_tree_add_boolean(checksum_tree, hf_udp_checksum_bad, tvb,
 526                               offset + 6, 2, FALSE);
 527        PROTO_ITEM_SET_GENERATED(item);
 528      }
 529    } else {
 530      item = proto_tree_add_uint_format(udp_tree, hf_udp_checksum, tvb,
 531        offset + 6, 2, udph->uh_sum, "Checksum: 0x%04x [unchecked, not all data available]", udph->uh_sum);
 532   
 533      checksum_tree = proto_item_add_subtree(item, ett_udp_checksum);
 534      item = proto_tree_add_boolean(checksum_tree, hf_udp_checksum_good, tvb,
 535                               offset + 6, 2, FALSE);
 536      PROTO_ITEM_SET_GENERATED(item);
 537      item = proto_tree_add_boolean(checksum_tree, hf_udp_checksum_bad, tvb,
 538                               offset + 6, 2, FALSE);
 539      PROTO_ITEM_SET_GENERATED(item);
 540    }
 541   
 542    /* Skip over header */
 543    offset += 8;
 544   
 545    pinfo->ptype = PT_UDP;
 546    pinfo->srcport = udph->uh_sport;
 547    pinfo->destport = udph->uh_dport;
 548   
 549    tap_queue_packet(udp_tap, pinfo, udph);
 550     
 551    /* find(or create if needed) the conversation for this udp session */
 552    if (udp_process_info) {
 553      conv=get_udp_conversation(pinfo);
 554      udpd=get_udp_conversation_data(conv,pinfo);
 555    }
 556   
 557    if (udpd && (udpd->fwd || udpd->rev) && (udpd->fwd->command || udpd->rev->command)) {
 558      ti = proto_tree_add_text(udp_tree, tvb, offset, 0, "Process Information");
 559          PROTO_ITEM_SET_GENERATED(ti);
 560      process_tree = proto_item_add_subtree(ti, ett_udp_process_info);
 561          if (udpd->fwd->command) {
 562        proto_tree_add_uint_format_value(process_tree, hf_udp_proc_dst_uid, tvb, 0, 0,
 563                udpd->fwd->process_uid, "%u", udpd->fwd->process_uid);
 564        proto_tree_add_uint_format_value(process_tree, hf_udp_proc_dst_pid, tvb, 0, 0,
 565                udpd->fwd->process_pid, "%u", udpd->fwd->process_pid);
 566        proto_tree_add_string_format_value(process_tree, hf_udp_proc_dst_uname, tvb, 0, 0,
 567                udpd->fwd->username, "%s", udpd->fwd->username);
 568        proto_tree_add_string_format_value(process_tree, hf_udp_proc_dst_cmd, tvb, 0, 0,
 569                udpd->fwd->command, "%s", udpd->fwd->command);
 570      }
 571      if (udpd->rev->command) {
 572        proto_tree_add_uint_format_value(process_tree, hf_udp_proc_src_uid, tvb, 0, 0,
 573                udpd->rev->process_uid, "%u", udpd->rev->process_uid);
 574        proto_tree_add_uint_format_value(process_tree, hf_udp_proc_src_pid, tvb, 0, 0,
 575                udpd->rev->process_pid, "%u", udpd->rev->process_pid);
 576        proto_tree_add_string_format_value(process_tree, hf_udp_proc_src_uname, tvb, 0, 0,
 577                udpd->rev->username, "%s", udpd->rev->username);
 578        proto_tree_add_string_format_value(process_tree, hf_udp_proc_src_cmd, tvb, 0, 0,
 579                udpd->rev->command, "%s", udpd->rev->command);
 580      }
 581    }
 582   
 583    /*
 584     * Call sub-dissectors.
 585     *
 586     * XXX - should we do this if this is included in an error packet?
 587     * It might be nice to see the details of the packet that caused the
 588     * ICMP error, but it might not be nice to have the dissector update 
 589     * state based on it.
 590     * Also, we probably don't want to run UDP taps on those packets.
 591     *
 592     * We definitely don't want to do it for an error packet if there's
 593     * nothing left in the packet.
 594     */
 595    if (!pinfo->in_error_pkt || tvb_length_remaining(tvb, offset) > 0)
 596      decode_udp_ports(tvb, offset, pinfo, tree, udph->uh_sport, udph->uh_dport,
 597                       udph->uh_ulen);
 598  }
Show more  




Change Warning 3022.32239 : Unreachable Control Flow

Priority:
State:
Finding:
Owner:
Note: