Text   |  XML   |  ReML   |   Visible Warnings:

Null Test After Dereference  at packet-ber.c:2589

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

dissect_ber_choice

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-ber.c)expand/collapse
Show more  
 2507  dissect_ber_choice(asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_choice_t *choice, gint hf_id, gint ett_id, gint *branch_taken)
 2508  {
 2509          gint8 class;
 2510          gboolean pc, ind, imp_tag = FALSE;
 2511          gint32 tag;
 2512          guint32 len;
 2513          const ber_choice_t *ch;
 2514          proto_tree *tree=parent_tree;
 2515          proto_item *item=NULL;
 2516          int end_offset, start_offset, count;
 2517          int hoffset = offset;
 2518          header_field_info       *hfinfo;
 2519          gint length, length_remaining;
 2520          tvbuff_t *next_tvb;
 2521          gboolean first_pass;
 2522   
 2523  #ifdef DEBUG_BER_CHOICE 
 2524  {
 2525  const char *name;
 2526  header_field_info *hfinfo;
 2527  if(hf_id>=0){
 2528  hfinfo = proto_registrar_get_nth(hf_id);
 2529  name=hfinfo->name;
 2530  } else {
 2531  name="unnamed";
 2532  }
 2533  if(tvb_length_remaining(tvb,offset)>3){
 2534  printf("CHOICE dissect_ber_choice(%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));
 2535  }else{
 2536  printf("CHOICE dissect_ber_choice(%s) entered len:%d\n",name,tvb_length_remaining(tvb,offset));
 2537  }
 2538  }
 2539  #endif
 2540          start_offset=offset;
 2541   
 2542          if(tvb_length_remaining(tvb,offset) == 0) {
 2543                  item = proto_tree_add_text(parent_tree, tvb, offset, 0, "BER Error: Empty choice was found");
 2544                  proto_item_set_expert_flags(item, PI_MALFORMED, PI_WARN);
 2545                  expert_add_info_format(actx->pinfo, item, PI_MALFORMED, PI_WARN, "BER Error: Empty choice was found");
 2546                  return offset;  
 2547          }        
 2548   
 2549          /* read header and len for choice field */
 2550          offset=get_ber_identifier(tvb, offset, &class, &pc, &tag);
 2551          offset=get_ber_length(tvb, offset, &len, &ind);
 2552            end_offset = offset + len ;
 2553   
 2554          /* Some sanity checks.
 2555           * The hf field passed to us MUST be an integer type 
 2556           */
 2557          if(hf_id >= 0){
 2558                  hfinfo=proto_registrar_get_nth(hf_id);
 2559                  switch(hfinfo->type) {
 2560                          case FT_UINT8:
 2561                          case FT_UINT16:
 2562                          case FT_UINT24:
 2563                          case FT_UINT32:
 2564                                  break;
 2565                  default:
 2566                          proto_tree_add_text(tree, tvb, offset, len,"dissect_ber_choice(): Was passed a HF field that was not integer type : %s",hfinfo->abbrev);
 2567                          fprintf(stderr,"dissect_ber_choice(): frame:%u offset:%d Was passed a HF field that was not integer type : %s\n",actx->pinfo->fd->num,offset,hfinfo->abbrev);
 2568                          return end_offset;
 2569                  }
 2570          }
 2571   
 2572   
 2573   
 2574          /* loop over all entries until we find the right choice or 
 2575             run out of entries */
 2576          ch = choice;
 2577          if(branch_taken){
 2578                  *branch_taken=-1;
 2579          }
 2580          first_pass = TRUE;
 2581          while(ch->func || first_pass){
 2582                  if(branch_taken){
 2583                          (*branch_taken)++;
 2584                  }
 2585            /* we reset for a second pass when we will look for choices */
 2586            if(!ch->func) {
 2587              first_pass = FALSE;
 2588              ch = choice; /* reset to the beginning */
 2589                  if(branch_taken){
 2590                          *branch_taken=-1;
 2591                  }
 2592            }
 2593   
 2594  choice_try_again:
 2595  #ifdef DEBUG_BER_CHOICE 
 2596  printf("CHOICE testing potential subdissector class[%p]:%d:(expected)%d  tag:%d:(expected)%d flags:%d\n",ch,class,ch->class,tag,ch->tag,ch->flags);
 2597  #endif
 2598                  if( (first_pass && (((ch->class==class)&&(ch->tag==tag))
 2599                       ||  ((ch->class==class)&&(ch->tag==-1)&&(ch->flags&BER_FLAGS_NOOWNTAG)))) ||
 2600                      (!first_pass && (((ch->class == BER_CLASS_ANY) && (ch->tag == -1)))) /* we failed on the first pass so now try any choices */
 2601                  ){
 2602                          if(!(ch->flags & BER_FLAGS_NOOWNTAG)){
 2603                                  /* dissect header and len for field */
 2604                                  hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, start_offset, NULL, NULL, NULL);
 2605                                  hoffset = dissect_ber_length(actx->pinfo, tree, tvb, hoffset, NULL, NULL);
 2606                                  start_offset=hoffset;
 2607                                  if (ind)
 2608                                          {
 2609                                          length = len-2;
 2610                                          }
 2611                                  else 
 2612                                          {
 2613                                          length = len;
 2614                                          }
 2615                          }
 2616                          else 
 2617                                  length = end_offset- hoffset;
 2618                          /* create subtree */
 2619                          if(hf_id >= 0){
 2620                                  if(parent_tree){
 2621                                          item = proto_tree_add_uint(parent_tree, hf_id, tvb, hoffset, end_offset - hoffset, ch->value);
 2622                                          tree = proto_item_add_subtree(item, ett_id);
 2623                                  }
 2624                          }
 2625   
 2626                          length_remaining=tvb_length_remaining(tvb, hoffset);
 2627                          if(length_remaining>length)
 2628                                  length_remaining=length;
 2629   
 2630  #ifdef REMOVED 
 2631                          /* This is bogus and makes the OID_1.0.9506.1.1.cap file 
 2632                           * in Steven J Schaeffer's email of 2005-09-12 fail to dissect 
 2633                           * properly.  Maybe we should get rid of 'first_pass'
 2634                           * completely.
 2635                           * It was added as a qad workaround for some problem CMIP 
 2636                           * traces anyway.
 2637                           * God, this file is a mess and it is my fault. /ronnie
 2638                           */
 2639                          if(first_pass)
 2640                          next_tvb=tvb_new_subset(tvb, hoffset, length_remaining, length);
 2641                          else 
 2642                            next_tvb = tvb; /* we didn't make selection on this class/tag so pass it on */
 2643  #endif
 2644                          next_tvb=tvb_new_subset(tvb, hoffset, length_remaining, length);
 2645   
 2646   
 2647  #ifdef DEBUG_BER_CHOICE 
 2648  {
 2649  const char *name;
 2650  header_field_info *hfinfo;
 2651  if(hf_id>=0){
 2652  hfinfo = proto_registrar_get_nth(hf_id);
 2653  name=hfinfo->name;
 2654  } else {
 2655  name="unnamed";
 2656  }
 2657  if(tvb_length_remaining(next_tvb,0)>3){
 2658  printf("CHOICE dissect_ber_choice(%s) calling subdissector start_offset:%d offset:%d len:%d %02x:%02x:%02x\n",name,start_offset,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));
 2659  }else{
 2660  printf("CHOICE dissect_ber_choice(%s) calling subdissector len:%d\n",name,tvb_length(next_tvb));
 2661  }
 2662  }
 2663  #endif
 2664                          if (next_tvb == NULL) {
 2665                                  /* Assume that we have a malformed packet. */
 2666                                  THROW(ReportedBoundsError);
 2667                          }
 2668                          imp_tag = FALSE;
 2669                          if ((ch->flags & BER_FLAGS_IMPLTAG))
 2670                                  imp_tag = TRUE;
 2671                          count=ch->func(imp_tag, next_tvb, 0, actx, tree, *ch->p_id);
 2672  #ifdef DEBUG_BER_CHOICE 
 2673  {
 2674  const char *name;
 2675  header_field_info *hfinfo;
 2676  if(hf_id>=0){
 2677  hfinfo = proto_registrar_get_nth(hf_id);
 2678  name=hfinfo->name;
 2679  } else {
 2680  name="unnamed";
 2681  }
 2682  printf("CHOICE dissect_ber_choice(%s) subdissector ate %d bytes\n",name,count);
 2683  }
 2684  #endif
 2685                          if((count==0)&&(((ch->class==class)&&(ch->tag==-1)&&(ch->flags&BER_FLAGS_NOOWNTAG)) || !first_pass)){
 2686                                  /* wrong one, break and try again */
 2687                                  ch++;
 2688  #ifdef DEBUG_BER_CHOICE 
 2689  {
 2690  const char *name;
 2691  header_field_info *hfinfo;
 2692  if(hf_id>=0){
 2693  hfinfo = proto_registrar_get_nth(hf_id);
 2694  name=hfinfo->name;
 2695  } else {
 2696  name="unnamed";
 2697  }
 2698  printf("CHOICE dissect_ber_choice(%s) trying again\n",name);
 2699  }
 2700  #endif
 2701                                  goto choice_try_again;
 2702                          }
 2703                          if(!(ch->flags & BER_FLAGS_NOOWNTAG)){
 2704                           if(ind)
 2705                                  {
 2706                                  /* we are traversing a indfinite length choice where we did not pass the tag length */
 2707                                  /* we need to eat the EOC */
 2708                                  if(show_internal_ber_fields){
 2709                                          proto_tree_add_text(tree, tvb, start_offset, count+2, "CHOICE EOC");
 2710                                  }
 2711                           }
 2712                          }
 2713                          return end_offset;
 2714                  }
 2715                  ch++;
 2716          }
 2717          if(branch_taken){
 2718                  /* none of the branches were taken so set the param
 2719                     back to -1 */
 2720                  *branch_taken=-1;
 2721          }
 2722   
 2723  #ifdef REMOVED 
 2724          /*XXX here we should have another flag to the CHOICE to distinguish 
 2725           * between the case when we know it is a mandatory   or if the CHOICE is optional == no arm matched */
 2726   
 2727          /* oops no more entries and we still havent found 
 2728           * our guy :-(
 2729           */
 2730          item = proto_tree_add_text(tree, tvb, offset, len, "BER Error: This choice field was not found.");
 2731          proto_item_set_expert_flags(item, PI_MALFORMED, PI_WARN);
 2732          expert_add_info_format(actx->pinfo, item, PI_MALFORMED, PI_WARN, "BER Error: This choice field was not found");
 2733          return end_offset;
 2734  #endif
 2735   
 2736          return start_offset;
 2737  }
Show more  




Change Warning 12347.31764 : Null Test After Dereference

Priority:
State:
Finding:
Owner:
Note: