Text   |  XML   |  ReML   |   Visible Warnings:

Redundant Condition  at packet-rpc.c:2906

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

dissect_rpc_fragment

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-rpc.c)expand/collapse
Show more  
 2883  dissect_rpc_fragment(tvbuff_t *tvb, int offset, packet_info *pinfo,
 2884      proto_tree *tree, rec_dissector_t dissector, gboolean is_heur,
 2885      int proto, int ett, gboolean defragment, gboolean first_pdu)
 2886  {
 2887          struct tcpinfo *tcpinfo;
 2888          guint32 seq;
 2889          guint32 rpc_rm;
 2890          volatile guint32 len;
 2891          gint32 seglen;
 2892          gint tvb_len, tvb_reported_len;
 2893          tvbuff_t *frag_tvb;
 2894          gboolean rpc_succeeded;
 2895          gboolean save_fragmented;
 2896          rpc_fragment_key old_rfk, *rfk, *new_rfk;
 2897          conversation_t *conversation;
 2898          fragment_data *ipfd_head;
 2899          tvbuff_t *rec_tvb;
 2900   
 2901          if (pinfo == NULL || pinfo->private_data == NULL) {
 2902                  return 0;
 2903          }
 2904          tcpinfo = pinfo->private_data;
 2905   
 2906          if (tcpinfo == NULL) {
 2907                  return 0;
 2908          }
 2909          seq = tcpinfo->seq + offset;
 2910   
 2911          /*
 2912           * Get the record mark.
 2913           */
 2914          if (!tvb_bytes_exist(tvb, offset, 4)) {
 2915                  /*
 2916                   * XXX - we should somehow arrange to handle
 2917                   * a record mark split across TCP segments.
 2918                   */
 2919                  return 0;       /* not enough to tell if it's valid */
 2920          }
 2921          rpc_rm = tvb_get_ntohl(tvb, offset);
 2922   
 2923          len = rpc_rm & RPC_RM_FRAGLEN;
 2924   
 2925          /*
 2926           * Do TCP desegmentation, if enabled.
 2927           *
 2928           * reject fragments bigger than this preference setting.
 2929           * This is arbitrary, but should at least prevent 
 2930           * some crashes from either packets with really 
 2931           * large RPC-over-TCP fragments or from stuff that's
 2932           * not really valid for this protocol.
 2933           */
 2934          if (len > max_rpc_tcp_pdu_size)
 2935                  return 0;       /* pretend it's not valid */
 2936          if (rpc_desegment) {
 2937                  seglen = tvb_length_remaining(tvb, offset + 4);
 2938   
 2939                  if ((gint)len > seglen && pinfo->can_desegment) {
 2940                          /*
 2941                           * This frame doesn't have all of the
 2942                           * data for this message, but we can do
 2943                           * reassembly on it.
 2944                           *
 2945                           * If this is a heuristic dissector, just 
 2946                           * return 0 - we don't want to try to get 
 2947                           * more data, as that's too likely to cause
 2948                           * us to misidentify this as valid.
 2949                           *
 2950                           * XXX - this means that we won't
 2951                           * recognize the first fragment of a
 2952                           * multi-fragment RPC operation unless 
 2953                           * we've already identified this 
 2954                           * conversation as being an RPC 
 2955                           * conversation (and thus aren't running 
 2956                           * heuristically) - that would be a problem 
 2957                           * if, for example, the first segment were
 2958                           * the beginning of a large NFS WRITE.
 2959                           *
 2960                           * If this isn't a heuristic dissector,
 2961                           * we've already identified this conversation
 2962                           * as containing data for this protocol, as we
 2963                           * saw valid data in previous frames.  Try to 
 2964                           * get more data.
 2965                           */
 2966                          if (is_heur)
 2967                                  return 0;       /* not valid */
 2968                          else {
 2969                                  pinfo->desegment_offset = offset;
 2970                                  pinfo->desegment_len = len - seglen;
 2971                                  return -((gint32) pinfo->desegment_len);
 2972                          }
 2973                  }
 2974          }
 2975          len += 4;       /* include record mark */
 2976          tvb_len = tvb_length_remaining(tvb, offset);
 2977          tvb_reported_len = tvb_reported_length_remaining(tvb, offset);
 2978          if (tvb_len > (gint)len)
 2979                  tvb_len = len;
 2980          if (tvb_reported_len > (gint)len)
 2981                  tvb_reported_len = len;
 2982          frag_tvb = tvb_new_subset(tvb, offset, tvb_len,
 2983              tvb_reported_len);
 2984   
 2985          /*
 2986           * If we're not defragmenting, just hand this to the 
 2987           * disssector.
 2988           */
 2989          if (!defragment) {
 2990                  /*
 2991                   * This is the first fragment we've seen, and it's also 
 2992                   * the last fragment; that means the record wasn't
 2993                   * fragmented.  Hand the dissector the tvbuff for the
 2994                   * fragment as the tvbuff for the record.
 2995                   */
 2996                  rec_tvb = frag_tvb;
 2997                  ipfd_head = NULL;
 2998   
 2999                  /*
 3000                   * Mark this as fragmented, so if somebody throws an 
 3001                   * exception, we don't report it as a malformed frame.
 3002                   */
 3003                  save_fragmented = pinfo->fragmented;
 3004                  pinfo->fragmented = TRUE;
 3005                  rpc_succeeded = call_message_dissector(tvb, rec_tvb, pinfo,
 3006                      tree, frag_tvb, dissector, ipfd_head, rpc_rm, first_pdu);
 3007                  pinfo->fragmented = save_fragmented;
 3008                  if (!rpc_succeeded)
 3009                          return 0;       /* not RPC */
 3010                  return len;
 3011          }
 3012   
 3013          /*
 3014           * First, we check to see if this fragment is part of a record
 3015           * that we're in the process of defragmenting.
 3016           *
 3017           * The key is the conversation ID for the conversation to which 
 3018           * the packet belongs and the current sequence number.
 3019           * We must first find the conversation and, if we don't find 
 3020           * one, create it.  We know this is running over TCP, so the
 3021           * conversation should not wildcard either address or port.
 3022           */
 3023          conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
 3024              pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
 3025          if (conversation == NULL) {
 3026                  /*
 3027                   * It's not part of any conversation - create a new one.
 3028                   */
 3029                  conversation = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst,
 3030                      pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
 3031          }
 3032          old_rfk.conv_id = conversation->index;
 3033          old_rfk.seq = seq;
 3034          old_rfk.port = pinfo->srcport;
 3035          rfk = g_hash_table_lookup(rpc_reassembly_table, &old_rfk);
 3036   
 3037          if (rfk == NULL) {
 3038                  /*
 3039                   * This fragment was not found in our table, so it doesn't
 3040                   * contain a continuation of a higher-level PDU.
 3041                   * Is it the last fragment?
 3042                   */
 3043                  if (!(rpc_rm & RPC_RM_LASTFRAG)) {
 3044                          /*
 3045                           * This isn't the last fragment, so we don't
 3046                           * have the complete record.
 3047                           *
 3048                           * It's the first fragment we've seen, so if
 3049                           * it's truly the first fragment of the record,
 3050                           * and it has enough data, the dissector can at
 3051                           * least check whether it looks like a valid
 3052                           * message, as it contains the start of the 
 3053                           * message.
 3054                           *
 3055                           * The dissector should not dissect anything
 3056                           * if the "last fragment" flag isn't set in
 3057                           * the record marker, so it shouldn't throw 
 3058                           * an exception.
 3059                           */
 3060                          if (!(*dissector)(frag_tvb, pinfo, tree, frag_tvb,
 3061                              NULL, TRUE, rpc_rm, first_pdu))
 3062                                  return 0;       /* not valid */
 3063   
 3064                          /*
 3065                           * OK, now start defragmentation with that 
 3066                           * fragment.  Add this fragment, and set up 
 3067                           * next packet/sequence number as well.
 3068                           *
 3069                           * We must remember this fragment.
 3070                           */
 3071   
 3072                          rfk = se_alloc(sizeof(rpc_fragment_key));
 3073                          rfk->conv_id = conversation->index;
 3074                          rfk->seq = seq;
 3075                          rfk->port = pinfo->srcport;
 3076                          rfk->offset = 0;
 3077                          rfk->start_seq = seq;
 3078                          g_hash_table_insert(rpc_reassembly_table, rfk, rfk);
 3079   
 3080                          /*
 3081                           * Start defragmentation.
 3082                           */
 3083                          ipfd_head = fragment_add_multiple_ok(tvb, offset + 4,
 3084                              pinfo, rfk->start_seq, rpc_fragment_table,
 3085                              rfk->offset, len - 4, TRUE);
 3086   
 3087                          /*
 3088                           * Make sure that defragmentation isn't complete;
 3089                           * it shouldn't be, as this is the first fragment
 3090                           * we've seen, and the "last fragment" bit wasn't
 3091                           * set on it.
 3092                           */
 3093                          if (ipfd_head == NULL) {
 3094                                  new_rfk = se_alloc(sizeof(rpc_fragment_key));
 3095                                  new_rfk->conv_id = rfk->conv_id;
 3096                                  new_rfk->seq = seq + len;
 3097                                  new_rfk->port = pinfo->srcport;
 3098                                  new_rfk->offset = rfk->offset + len - 4;
 3099                                  new_rfk->start_seq = rfk->start_seq;
 3100                                  g_hash_table_insert(rpc_reassembly_table, new_rfk,
 3101                                          new_rfk);
 3102   
 3103                                  /*
 3104                                   * This is part of a fragmented record,
 3105                                   * but it's not the first part.
 3106                                   * Show it as a record marker plus data, under 
 3107                                   * a top-level tree for this protocol.
 3108                                   */
 3109                                  make_frag_tree(frag_tvb, tree, proto, ett,rpc_rm);
 3110   
 3111                                  /*
 3112                                   * No more processing need be done, as we don't
 3113                                   * have a complete record.
 3114                                   */
 3115                                  return len;
 3116                          } else {
 3117                                  /* oddly, we have a first fragment, not marked as last,
 3118                                   * but which the defragmenter thinks is complete.
 3119                                   * So rather than creating a fragment reassembly tree,
 3120                                   * we simply throw away the partial fragment structure
 3121                                   * and fall though to our "sole fragment" processing below.
 3122                                   */
 3123                          }
 3124                  }
 3125   
 3126                  /*
 3127                   * This is the first fragment we've seen, and it's also 
 3128                   * the last fragment; that means the record wasn't
 3129                   * fragmented.  Hand the dissector the tvbuff for the
 3130                   * fragment as the tvbuff for the record.
 3131                   */
 3132                  rec_tvb = frag_tvb;
 3133                  ipfd_head = NULL;
 3134          } else {
 3135                  /*
 3136                   * OK, this fragment was found, which means it continues
 3137                   * a record.  This means we must defragment it.
 3138                   * Add it to the defragmentation lists.
 3139                   */
 3140                  ipfd_head = fragment_add_multiple_ok(tvb, offset + 4, pinfo,
 3141                      rfk->start_seq, rpc_fragment_table,
 3142                      rfk->offset, len - 4, !(rpc_rm & RPC_RM_LASTFRAG));
 3143   
 3144                  if (ipfd_head == NULL) {
 3145                          /*
 3146                           * fragment_add_multiple_ok() returned NULL.
 3147                           * This means that defragmentation is not
 3148                           * completed yet.
 3149                           *
 3150                           * We must add an entry to the hash table with
 3151                           * the sequence number following this fragment
 3152                           * as the starting sequence number, so that when 
 3153                           * we see that fragment we'll find that entry.
 3154                           *
 3155                           * XXX - as TCP stream data is not currently 
 3156                           * guaranteed to be provided in order to dissectors,
 3157                           * RPC fragments aren't guaranteed to be provided
 3158                           * in order, either.
 3159                           */
 3160                          new_rfk = se_alloc(sizeof(rpc_fragment_key));
 3161                          new_rfk->conv_id = rfk->conv_id;
 3162                          new_rfk->seq = seq + len;
 3163                          new_rfk->port = pinfo->srcport;
 3164                          new_rfk->offset = rfk->offset + len - 4;
 3165                          new_rfk->start_seq = rfk->start_seq;
 3166                          g_hash_table_insert(rpc_reassembly_table, new_rfk,
 3167                              new_rfk);
 3168   
 3169                          /*
 3170                           * This is part of a fragmented record,
 3171                           * but it's not the first part.
 3172                           * Show it as a record marker plus data, under 
 3173                           * a top-level tree for this protocol,
 3174                           * but don't hand it to the dissector 
 3175                           */
 3176                          make_frag_tree(frag_tvb, tree, proto, ett, rpc_rm);
 3177   
 3178                          /*
 3179                           * No more processing need be done, as we don't
 3180                           * have a complete record.
 3181                           */
 3182                          return len;
 3183                  }
 3184   
 3185                  /*
 3186                   * It's completely defragmented.
 3187                   *
 3188                   * We only call subdissector for the last fragment.
 3189                   * XXX - this assumes in-order delivery of RPC 
 3190                   * fragments, which requires in-order delivery of TCP 
 3191                   * segments.
 3192                   */
 3193                  if (!(rpc_rm & RPC_RM_LASTFRAG)) {
 3194                          /*
 3195                           * Well, it's defragmented, but this isn't
 3196                           * the last fragment; this probably means 
 3197                           * this isn't the first pass, so we don't
 3198                           * need to start defragmentation.
 3199                           *
 3200                           * This is part of a fragmented record,
 3201                           * but it's not the first part.
 3202                           * Show it as a record marker plus data, under 
 3203                           * a top-level tree for this protocol,
 3204                           * but don't show it to the dissector.
 3205                           */
 3206                          make_frag_tree(frag_tvb, tree, proto, ett, rpc_rm);
 3207   
 3208                          /*
 3209                           * No more processing need be done, as we
 3210                           * only disssect the data with the last 
 3211                           * fragment.
 3212                           */
 3213                          return len;
 3214                  }
 3215   
 3216                  /*
 3217                   * OK, this is the last segment.
 3218                   * Create a tvbuff for the defragmented
 3219                   * record.
 3220                   */
 3221   
 3222                  /*
 3223                   * Create a new TVB structure for
 3224                   * defragmented data.
 3225                   */
 3226                  rec_tvb = tvb_new_real_data(ipfd_head->data,
 3227                      ipfd_head->datalen, ipfd_head->datalen);
 3228   
 3229                  /*
 3230                   * Add this tvb as a child to the original 
 3231                   * one.
 3232                   */
 3233                  tvb_set_child_real_data_tvbuff(tvb, rec_tvb);
 3234   
 3235                  /*
 3236                   * Add defragmented data to the data source list.
 3237                   */
 3238                  add_new_data_source(pinfo, rec_tvb, "Defragmented");
 3239          }
 3240   
 3241          /*
 3242           * We have something to hand to the RPC message 
 3243           * dissector.
 3244           */
 3245          if (!call_message_dissector(tvb, rec_tvb, pinfo, tree,
 3246              frag_tvb, dissector, ipfd_head, rpc_rm, first_pdu))
 3247                  return 0;       /* not RPC */
 3248          return len;
 3249  }  /* end of dissect_rpc_fragment() */
Show more  




Change Warning 2921.31777 : Redundant Condition

Priority:
State:
Finding:
Owner:
Note: