Text   |  XML   |  ReML   |   Visible Warnings:

Null Pointer Dereference  at packet-ber.c:2419

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

dissect_ber_old_set

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-ber.c)expand/collapse
Show more  
 2238  int dissect_ber_old_set(gboolean implicit_tag,asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_old_sequence_t *set, gint hf_id, gint ett_id) {
 2239          gint8 classx;
 2240          gboolean pcx, ind = 0, ind_field;
 2241          gint32 tagx;
 2242          guint32 lenx;
 2243          proto_tree *tree = parent_tree;
 2244          proto_item *item = NULL;
 2245          proto_item *cause;
 2246          int end_offset, s_offset;
 2247          int hoffset;
 2248          gint length_remaining;
 2249          tvbuff_t *next_tvb;
 2250          const ber_old_sequence_t *cset = NULL;
 2251  # define MAX_SET_ELEMENTS 32 
 2252          guint32   mandatory_fields = 0;
 2253          guint8   set_idx;
 2254          gboolean first_pass;
 2255          s_offset = offset;
 2256  #ifdef DEBUG_BER 
 2257          {
 2258  const char *name;
 2259  header_field_info *hfinfo;
 2260  if(hf_id>=0){
 2261  hfinfo = proto_registrar_get_nth(hf_id);
 2262  name=hfinfo->name;
 2263  } else {
 2264  name="unnamed";
 2265  }
 2266  if(tvb_length_remaining(tvb,offset)>3){
 2267  printf("SET dissect_old_ber_set(%s) entered offset:%d len:%d %02x:%02x:%02x\n",name,offset,tvb_length_remaining(tvb,offset),tvb_get_guint8(tvb,offset),tvb_get_guint8(tvb,offset+1),tvb_get_guint8(tvb,offset+2));
 2268  }else{
 2269  printf("SET dissect_old_ber_set(%s) entered\n",name);
 2270  }
 2271  }
 2272  #endif
 2273   
 2274          if(!implicit_tag){
 2275                  hoffset = offset;
 2276                  /* first we must read the sequence header */
 2277                  offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &classx, &pcx, &tagx);
 2278                  offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &lenx, &ind);
 2279                  if(ind){
 2280                  /*  Fixed the length is correctly returned from dissect ber_length
 2281                    end_offset = tvb_length(tvb);*/
 2282                    end_offset = offset + lenx -2;
 2283                  } else {
 2284                    end_offset = offset + lenx;
 2285                  }
 2286   
 2287                  /* sanity check: we only handle Constructed Universal Sets */
 2288                  if ((classx!=BER_CLASS_APP)&&(classx!=BER_CLASS_PRI))
 2289                  if ((!pcx)
 2290                  ||(!implicit_tag&&((classx!=BER_CLASS_UNI)
 2291                                                          ||(tagx!=BER_UNI_TAG_SET)))) {
 2292                    tvb_ensure_bytes_exist(tvb, hoffset, 2);
 2293                    cause = proto_tree_add_text(tree, tvb, offset, lenx, "BER Error: SET expected but class:%s(%d) %s tag:%d was found", val_to_str(classx,ber_class_codes,"Unknown"), classx, pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tagx);
 2294                    proto_item_set_expert_flags(cause, PI_MALFORMED, PI_WARN);
 2295                    expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: SET expected");
 2296                    if (decode_unexpected) {
 2297                      proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
 2298                      dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
 2299                    }
 2300                    return end_offset;
 2301                  }
 2302          } else {
 2303                  /* was implicit tag so just use the length of the tvb */
 2304                  lenx=tvb_length_remaining(tvb,offset);
 2305                  end_offset=offset+lenx;
 2306          }
 2307   
 2308          /* create subtree */
 2309          if (hf_id >= 0) {
 2310                  if(parent_tree){
 2311                          item = proto_tree_add_item(parent_tree, hf_id, tvb, offset, lenx, FALSE);
 2312                          tree = proto_item_add_subtree(item, ett_id);
 2313                  }
 2314          }
 2315   
 2316          /* record the mandatory elements of the set so we can check we found everything at the end 
 2317             we can only record 32 elements for now ... */
 2318          for(set_idx = 0; (cset=&set[set_idx])->func && (set_idx < MAX_SET_ELEMENTS); set_idx++) {
 2319   
 2320            if(!(cset->flags & BER_FLAGS_OPTIONAL))
 2321                mandatory_fields |= 1 << set_idx;
 2322   
 2323          }
 2324   
 2325          /* loop over all entries until we reach the end of the set */
 2326          while (offset < end_offset){
 2327                  gint8 class;
 2328                  gboolean pc;
 2329                  gint32 tag;
 2330                  guint32 len;
 2331                  int eoffset, count;
 2332   
 2333                  /*if(ind){  this sequence was of indefinite length, if this is implicit indefinite impossible maybe 
 2334                    but ber dissector uses this to eat the tag length then pass into here... EOC still on there...*/
 2335   
 2336[+]                         if((tvb_get_guint8(tvb, offset)==0)&&(tvb_get_guint8(tvb, offset+1)==0)){
 2337                                  if(show_internal_ber_fields){
 2338                                          proto_tree_add_text(tree, tvb, s_offset, offset+2, "SEQ EOC");
 2339                                  }
 2340                                  return end_offset;
 2341                          }
 2342                          /* } */
 2343                  hoffset = offset;
 2344                  /* read header and len for next field */
 2345                  offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
 2346                  offset = get_ber_length(tvb, offset, &len, &ind_field);
 2347                  eoffset = offset + len;
 2348   
 2349                  /* Look through the Set to see if this class/id exists and
 2350                   * hasn't been seen before 
 2351                   * Skip check completely if class==ANY
 2352                   * of if NOCHKTAG is set 
 2353                   */
 2354   
 2355   
 2356                  for(first_pass=TRUE, cset = set, set_idx = 0; cset->func || first_pass; cset++, set_idx++) {
 2357   
 2358                    /* we reset for a second pass when we will look for choices */
 2359                    if(!cset->func) {
 2360                      first_pass = FALSE;
 2361   
 2362                      cset=set; /* reset to the beginning */
 2363                      set_idx = 0;
 2364                    }
 2365   
 2366                    if((first_pass && ((cset->class==class) && (cset->tag==tag))) ||
 2367                       (!first_pass && ((cset->class== BER_CLASS_ANY) && (cset->tag == -1))) ) /* choices */
 2368                    {
 2369   
 2370                          if (!(cset->flags & BER_FLAGS_NOOWNTAG) ) {
 2371                        /* dissect header and len for field */
 2372                                  hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
 2373                                  hoffset = dissect_ber_length(actx->pinfo, tree, tvb, hoffset, NULL, NULL);
 2374                                  length_remaining=tvb_length_remaining(tvb, hoffset);
 2375                                  if (length_remaining>eoffset-hoffset-(2*ind_field))
 2376                                          length_remaining=eoffset-hoffset-(2*ind_field);
 2377                                  next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset-hoffset-(2*ind_field));
 2378                      }
 2379                          else {
 2380                                  length_remaining=tvb_length_remaining(tvb, hoffset);
 2381                                  if (length_remaining>eoffset-hoffset)
 2382                                          length_remaining=eoffset-hoffset;
 2383[+]                                 next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset-hoffset);
 2384                          }
 2385   
 2386   
 2387                          /* call the dissector for this field */
 2388                          /*if    ((eoffset-hoffset)>length_remaining) {*/
 2389                                  /* If the field is indefinite (i.e. we dont know the
 2390                                   * length) of if the tvb is short, then just
 2391                                   * give it all of the tvb and hope for the best.
 2392                                   */
 2393                                  /*next_tvb = tvb_new_subset(tvb, hoffset, -1, -1);*/
 2394
2404
Show [ Lines 2394 to 2404 omitted. ]
 2405  } else {
 2406  name="unnamed";
 2407  }
 2408  if(tvb_length_remaining(next_tvb,0)>3){
 2409  printf("SET dissect_old_ber_set(%s) calling subdissector offset:%d len:%d %02x:%02x:%02x\n",name,offset,tvb_length_remaining(next_tvb,0),tvb_get_guint8(next_tvb,0),tvb_get_guint8(next_tvb,1),tvb_get_guint8(next_tvb,2));
 2410  }else{
 2411  printf("SET dissect_old_ber_set(%s) calling subdissector\n",name);
 2412  }
 2413  }
 2414  #endif
 2415                          if (next_tvb == NULL) {
 2416                                  /* Assume that we have a malformed packet. */
 2417                                  THROW(ReportedBoundsError);
 2418                          }
 2419                          count=cset->func(tree, next_tvb, 0, actx);
 2420   
 2421                          /* if we consumed some bytes,  
 2422                             or we knew the length was zero (during the first pass only) */
 2423                          if(count || (first_pass && (len == 0 || (ind_field == 1 && len == 2)))) {
Show more  




Change Warning 1928.34826 : Null Pointer Dereference

Priority:
State:
Finding:
Owner:
Note: