Text   |  XML   |  ReML   |   Visible Warnings:

Null Test After Dereference  at packet-tcp.c:996

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

tcp_analyze_sequence_number

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-tcp.c)expand/collapse
Show more  
 597  tcp_analyze_sequence_number(packet_info *pinfo, guint32 seq, guint32 ack, guint32 seglen, guint8 flags, guint32 window, struct tcp_analysis *tcpd)
 598  {
 599          tcp_unacked_t *ual=NULL;
 600          int ackcount;
 601   
 602  #ifdef REMOVED 
 603  printf("analyze_sequence numbers   frame:%u  direction:%s\n",pinfo->fd->num,direction>=0?"FWD":"REW");
 604  printf("FWD list lastflags:0x%04x base_seq:0x%08x:\n",tcpd->fwd->lastsegmentflags,tcpd->fwd->base_seq);for(ual=tcpd->fwd->segments;ual;ual=ual->next)printf("Frame:%d Seq:%d Nextseq:%d\n",ual->frame,ual->seq,ual->nextseq);
 605  printf("REV list lastflags:0x%04x base_seq:0x%08x:\n",tcpd->rev->lastsegmentflags,tcpd->rev->base_seq);for(ual=tcpd->rev->segments;ual;ual=ual->next)printf("Frame:%d Seq:%d Nextseq:%d\n",ual->frame,ual->seq,ual->nextseq);
 606  #endif
 607   
 608          if (!tcpd) {
 609                  return;
 610          }
 611   
 612          /* if this is the first segment for this list we need to store the
 613           * base_seq 
 614           *
 615           * Start relative seq and ack numbers at 1 if this
 616           * is not a SYN packet. This makes the relative
 617           * seq/ack numbers to be displayed correctly in the 
 618           * event that the SYN or SYN/ACK packet is not seen
 619           * (this solves bug 1542)
 620           */
 621          if(tcpd->fwd->base_seq==0){
 622                  tcpd->fwd->base_seq = (flags & TH_SYN) ? seq : seq-1;
 623          }
 624   
 625          /* Only store reverse sequence if this isn't the SYN
 626           * There's no guarantee that the ACK field of a SYN 
 627           * contains zeros; get the ISN from the first segment 
 628           * with the ACK bit set instead (usually the SYN/ACK).
 629           */
 630          if( (tcpd->rev->base_seq==0) && (flags & TH_ACK) ){
 631                  tcpd->rev->base_seq = (flags & TH_SYN) ? ack : ack-1;
 632          }
 633   
 634   
 635          /* ZERO WINDOW PROBE 
 636           * it is a zero window probe if 
 637           *  the sequnece number is the next expected one 
 638           *  the window in the other direction is 0 
 639           *  the segment is exactly 1 byte 
 640           */
 641  /*QQQ tested*/
 642          if( seglen==1
 643          &&  seq==tcpd->fwd->nextseq
 644          &&  tcpd->rev->window==0 ){
 645                  if(!tcpd->ta){
 646                          tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 647                  }
 648                  tcpd->ta->flags|=TCP_A_ZERO_WINDOW_PROBE;
 649                  goto finished_fwd;
 650          }
 651   
 652   
 653          /* ZERO WINDOW
 654           * a zero window packet has window == 0   but none of the SYN/FIN/RST set 
 655           */
 656  /*QQQ tested*/
 657          if( window==0
 658          && (flags&(TH_RST|TH_FIN|TH_SYN))==0 ){
 659                  if(!tcpd->ta){
 660                          tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 661                  }
 662                  tcpd->ta->flags|=TCP_A_ZERO_WINDOW;
 663          }
 664   
 665   
 666          /* LOST PACKET
 667           * If this segment is beyond the last seen nextseq we must 
 668           * have missed some previous segment 
 669           *
 670           * We only check for this if we have actually seen segments prior to this
 671           * one.
 672           * RST packets are not checked for this.
 673           */
 674          if( tcpd->fwd->nextseq
 675          &&  GT_SEQ(seq, tcpd->fwd->nextseq)
 676          &&  (flags&(TH_RST))==0 ){
 677                  if(!tcpd->ta){
 678                          tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 679                  }
 680                  tcpd->ta->flags|=TCP_A_LOST_PACKET;
 681          }
 682   
 683   
 684          /* KEEP ALIVE
 685           * a keepalive contains 0 or 1 bytes of data and starts one byte prior
 686           * to what should be the next sequence number.
 687           * SYN/FIN/RST segments are never keepalives
 688           */
 689  /*QQQ tested */
 690          if( (seglen==0||seglen==1)
 691          &&  seq==(tcpd->fwd->nextseq-1)
 692          &&  (flags&(TH_SYN|TH_FIN|TH_RST))==0 ){
 693                  if(!tcpd->ta){
 694                          tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 695                  }
 696                  tcpd->ta->flags|=TCP_A_KEEP_ALIVE;
 697          }
 698   
 699          /* WINDOW UPDATE
 700           * A window update is a 0 byte segment with the same SEQ/ACK numbers as
 701           * the previous seen segment and with a new window value
 702           */
 703          if( seglen==0
 704          &&  window
 705          &&  window!=tcpd->fwd->window
 706          &&  seq==tcpd->fwd->nextseq
 707          &&  ack==tcpd->fwd->lastack
 708          &&  (flags&(TH_SYN|TH_FIN|TH_RST))==0 ){
 709                  if(!tcpd->ta){
 710                          tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 711                  }
 712                  tcpd->ta->flags|=TCP_A_WINDOW_UPDATE;
 713          }
 714   
 715   
 716          /* WINDOW FULL
 717           * If we know the window scaling
 718           * and if this segment contains data ang goes all the way to the 
 719           * edge of the advertized window 
 720           * then we mark it as WINDOW FULL 
 721           * SYN/RST/FIN packets are never WINDOW FULL 
 722           */
 723  /*QQQ tested*/
 724          if( seglen>0
 725          &&  tcpd->fwd->win_scale!=-1
 726          &&  tcpd->rev->win_scale!=-1
 727          &&  (seq+seglen)==(tcpd->rev->lastack+(tcpd->rev->window<<tcpd->rev->win_scale))
 728          &&  (flags&(TH_SYN|TH_FIN|TH_RST))==0 ){
 729                  if(!tcpd->ta){
 730                          tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 731                  }
 732                  tcpd->ta->flags|=TCP_A_WINDOW_FULL;
 733          }
 734   
 735   
 736          /* KEEP ALIVE ACK 
 737           * It is a keepalive ack if it repeats the previous ACK and if 
 738           * the last segment in the reverse direction was a keepalive
 739           */
 740  /*QQQ tested*/
 741          if( seglen==0
 742          &&  window
 743          &&  window==tcpd->fwd->window
 744          &&  seq==tcpd->fwd->nextseq
 745          &&  ack==tcpd->fwd->lastack
 746          && (tcpd->rev->lastsegmentflags&TCP_A_KEEP_ALIVE)
 747          &&  (flags&(TH_SYN|TH_FIN|TH_RST))==0 ){
 748                  if(!tcpd->ta){
 749                          tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 750                  }
 751                  tcpd->ta->flags|=TCP_A_KEEP_ALIVE_ACK;
 752                  goto finished_fwd;
 753          }
 754   
 755   
 756          /* ZERO WINDOW PROBE ACK
 757           * It is a zerowindowprobe ack if it repeats the previous ACK and if 
 758           * the last segment in the reverse direction was a zerowindowprobe
 759           * It also repeats the previous zero window indication
 760           */
 761  /*QQQ tested*/
 762          if( seglen==0
 763          &&  window==0
 764          &&  window==tcpd->fwd->window
 765          &&  seq==tcpd->fwd->nextseq
 766          &&  ack==tcpd->fwd->lastack
 767          && (tcpd->rev->lastsegmentflags&TCP_A_ZERO_WINDOW_PROBE)
 768          &&  (flags&(TH_SYN|TH_FIN|TH_RST))==0 ){
 769                  if(!tcpd->ta){
 770                          tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 771                  }
 772                  tcpd->ta->flags|=TCP_A_ZERO_WINDOW_PROBE_ACK;
 773                  goto finished_fwd;
 774          }
 775   
 776   
 777          /* DUPLICATE ACK
 778           * It is a duplicate ack if window/seq/ack is the same as the previous
 779           * segment and if the segment length is 0
 780           */
 781          if( seglen==0
 782          &&  window
 783          &&  window==tcpd->fwd->window
 784          &&  seq==tcpd->fwd->nextseq
 785          &&  ack==tcpd->fwd->lastack
 786          &&  (flags&(TH_SYN|TH_FIN|TH_RST))==0 ){
 787                  tcpd->fwd->dupacknum++;
 788                  if(!tcpd->ta){
 789                          tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 790                  }
 791                  tcpd->ta->flags|=TCP_A_DUPLICATE_ACK;
 792                  tcpd->ta->dupack_num=tcpd->fwd->dupacknum;
 793                  tcpd->ta->dupack_frame=tcpd->fwd->lastnondupack;
 794          }
 795   
 796   
 797   
 798  finished_fwd:
 799          /* If this was NOT a dupack we must reset the dupack counters */
 800          if( (!tcpd->ta) || !(tcpd->ta->flags&TCP_A_DUPLICATE_ACK) ){
 801                  tcpd->fwd->lastnondupack=pinfo->fd->num;
 802                  tcpd->fwd->dupacknum=0;
 803          }
 804   
 805   
 806          /* ACKED LOST PACKET 
 807           * If this segment acks beyond the nextseqnum in the other direction 
 808           * then that means we have missed packets going in the
 809           * other direction
 810           *
 811           * We only check this if we have actually seen some seq numbers
 812           * in the other direction.
 813           */
 814          if( tcpd->rev->nextseq
 815          &&  GT_SEQ(ack, tcpd->rev->nextseq )
 816          &&  (flags&(TH_ACK))!=0 ){
 817  /*QQQ tested*/
 818                  if(!tcpd->ta){
 819                          tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 820                  }
 821                  tcpd->ta->flags|=TCP_A_ACK_LOST_PACKET;
 822                  /* update nextseq in the other direction so we dont get
 823                   * this indication again.
 824                   */
 825                  tcpd->rev->nextseq=ack;
 826          }
 827   
 828   
 829          /* RETRANSMISSION/FAST RETRANSMISSION/OUT-OF-ORDER
 830           * If the segments contains data and if it does not advance 
 831           * sequence number it must be either of these three.
 832           * Only test for this if we know what the seq number should be 
 833           * (tcpd->fwd->nextseq)
 834           *
 835           * Note that a simple KeepAlive is not a retransmission 
 836           */
 837          if( seglen>0
 838          &&  tcpd->fwd->nextseq
 839          &&  (LT_SEQ(seq, tcpd->fwd->nextseq)) ){
 840                  guint64 t;
 841   
 842                  if(tcpd->ta && (tcpd->ta->flags&TCP_A_KEEP_ALIVE) ){
 843                          goto finished_checking_retransmission_type;
 844                  }
 845   
 846                  /* If there were >=2 duplicate ACKs in the reverse direction
 847                   * (there might be duplicate acks missing from the trace)
 848                   * and if this sequence number matches those ACKs
 849                   * and if the packet occurs within 20ms of the last
 850                   * duplicate ack
 851                   * then this is a fast retransmission
 852                   */
 853                  t=(pinfo->fd->abs_ts.secs-tcpd->rev->lastacktime.secs)*1000000000;
 854                  t=t+(pinfo->fd->abs_ts.nsecs)-tcpd->rev->lastacktime.nsecs;
 855                  if( tcpd->rev->dupacknum>=2
 856                  &&  tcpd->rev->lastack==seq
 857                  &&  t<20000000 ){
 858                          if(!tcpd->ta){
 859                                  tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 860                          }
 861                          tcpd->ta->flags|=TCP_A_FAST_RETRANSMISSION;
 862                          goto finished_checking_retransmission_type;
 863                  }
 864   
 865                  /* If the segment came <3ms since the segment with the highest
 866                   * seen sequence number, then it is an OUT-OF-ORDER segment.
 867                   *   (3ms is an arbitrary number)
 868                   */
 869                  t=(pinfo->fd->abs_ts.secs-tcpd->fwd->nextseqtime.secs)*1000000000;
 870                  t=t+(pinfo->fd->abs_ts.nsecs)-tcpd->fwd->nextseqtime.nsecs;
 871                  if( t<3000000 ){
 872                          if(!tcpd->ta){
 873                                  tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 874                          }
 875                          tcpd->ta->flags|=TCP_A_OUT_OF_ORDER;
 876                          goto finished_checking_retransmission_type;
 877                  }
 878   
 879                  /* Then it has to be a generic retransmission */
 880                  if(!tcpd->ta){
 881                          tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 882                  }
 883                  tcpd->ta->flags|=TCP_A_RETRANSMISSION;
 884                  nstime_delta(&tcpd->ta->rto_ts, &pinfo->fd->abs_ts, &tcpd->fwd->nextseqtime);
 885                  tcpd->ta->rto_frame=tcpd->fwd->nextseqframe;
 886          }
 887  finished_checking_retransmission_type:
 888   
 889   
 890          /* add this new sequence number to the fwd list */
 891          TCP_UNACKED_NEW(ual);
 892          ual->next=tcpd->fwd->segments;
 893          tcpd->fwd->segments=ual;
 894          ual->frame=pinfo->fd->num;
 895          ual->seq=seq;
 896          ual->ts=pinfo->fd->abs_ts;
 897   
 898          /* next sequence number is seglen bytes away, plus SYN/FIN which counts as one byte */
 899          ual->nextseq=seq+seglen;
 900          if( flags&(TH_SYN|TH_FIN) ){
 901                  ual->nextseq+=1;
 902          }
 903   
 904          /* Store the highest number seen so far for nextseq so we can detect 
 905           * when we receive segments that arrive with a "hole"
 906           * If we dont have anything since before, just store what we got.
 907           * ZeroWindowProbes are special and dont really advance the nextseq 
 908           */
 909          if(GT_SEQ(ual->nextseq, tcpd->fwd->nextseq) || !tcpd->fwd->nextseq) {
 910                  if( !tcpd->ta || !(tcpd->ta->flags&TCP_A_ZERO_WINDOW_PROBE) ){
 911                          tcpd->fwd->nextseq=ual->nextseq;
 912                          tcpd->fwd->nextseqframe=pinfo->fd->num;
 913                          tcpd->fwd->nextseqtime.secs=pinfo->fd->abs_ts.secs;
 914                          tcpd->fwd->nextseqtime.nsecs=pinfo->fd->abs_ts.nsecs;
 915                  }
 916          }
 917   
 918   
 919          /* remember what the ack/window is so we can track window updates and retransmissions */
 920          tcpd->fwd->window=window;
 921          tcpd->fwd->lastack=ack;
 922          tcpd->fwd->lastacktime.secs=pinfo->fd->abs_ts.secs;
 923          tcpd->fwd->lastacktime.nsecs=pinfo->fd->abs_ts.nsecs;
 924   
 925   
 926          /* if there were any flags set for this segment we need to remember them
 927           * we only remember the flags for the very last segment though.
 928           */
 929          if(tcpd->ta){
 930                  tcpd->fwd->lastsegmentflags=tcpd->ta->flags;
 931          } else {
 932                  tcpd->fwd->lastsegmentflags=0;
 933          }
 934   
 935   
 936          /* remove all segments this ACKs and we dont need to keep around any more
 937           */
 938          ackcount=0;
 939          /* first we remove all such segments at the head of the list */
 940          while((ual=tcpd->rev->segments)){
 941                  tcp_unacked_t *tmpual;
 942                  if(ack==ual->nextseq){
 943                          tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 944                          tcpd->ta->frame_acked=ual->frame;
 945                          nstime_delta(&tcpd->ta->ts, &pinfo->fd->abs_ts, &ual->ts);
 946                  }
 947                  if(GT_SEQ(ual->nextseq,ack)){
 948                          break;
 949                  }
 950                  if(!ackcount){
 951  /*qqq do the ACKs segment x  delta y */
 952                  }
 953                  ackcount++;
 954                  tmpual=tcpd->rev->segments->next;
 955   
 956                  if (tcpd->rev->scps_capable) {
 957                    /* Track largest segment successfully sent for SNACK analysis */
 958                    if ((ual->nextseq - ual->seq) > tcpd->fwd->maxsizeacked) {
 959                      tcpd->fwd->maxsizeacked = (ual->nextseq - ual->seq);
 960                    }
 961                  }
 962   
 963                  TCP_UNACKED_FREE(ual);
 964                  tcpd->rev->segments=tmpual;
 965          }
 966          /* now we remove all such segments that are NOT at the head of the list */
 967          ual=tcpd->rev->segments;
 968          while(ual && ual->next){
 969                  tcp_unacked_t *tmpual;
 970                  if(GT_SEQ(ual->next->nextseq,ack)){
 971                          ual=ual->next;
 972                          continue;
 973                  }
 974                  if(!ackcount){
 975  /*qqq do the ACKs segment x  delta y */
 976                  }
 977                  ackcount++;
 978                  tmpual=ual->next->next;
 979   
 980                  if (tcpd->rev->scps_capable) {
 981                    /* Track largest segment successfully sent for SNACK analysis*/
 982                    if ((ual->next->nextseq - ual->next->seq) > tcpd->fwd->maxsizeacked){
 983                      tcpd->fwd->maxsizeacked = (ual->next->nextseq - ual->next->seq);
 984                    }
 985                  }
 986   
 987                  TCP_UNACKED_FREE(ual->next);
 988                  ual->next=tmpual;
 989                  ual=ual->next;
 990          }
 991   
 992          /* how many bytes of data are there in flight after this frame
 993           * was sent
 994           */
 995          ual=tcpd->fwd->segments;
 996          if (tcp_track_bytes_in_flight && seglen!=0 && ual) {
 997                  guint32 first_seq, last_seq, in_flight;
 998   
 999                  first_seq = ual->seq - tcpd->fwd->base_seq;
 1000                  last_seq = ual->nextseq - tcpd->fwd->base_seq;
 1001                  while (ual) {
 1002                          if ((ual->nextseq-tcpd->fwd->base_seq)>last_seq) {
 1003                                  last_seq = ual->nextseq-tcpd->fwd->base_seq;
 1004                          }
 1005                          if ((ual->seq-tcpd->fwd->base_seq)<first_seq) {
 1006                                  first_seq = ual->seq-tcpd->fwd->base_seq;
 1007                          }
 1008                          ual = ual->next;
 1009                  }
 1010                  in_flight = last_seq-first_seq;
 1011   
 1012                  if (in_flight>0 && in_flight<2000000000) {
 1013                          if(!tcpd->ta){
 1014                                  tcp_analyze_get_acked_struct(pinfo->fd->num, TRUE, tcpd);
 1015                          }
 1016                          tcpd->ta->bytes_in_flight = in_flight;
 1017                  }
 1018          }
 1019   
 1020  }
Show more  




Change Warning 3009.30777 : Null Test After Dereference

Priority:
State:
Finding:
Owner:
Note: