Text   |  XML   |  ReML   |   Visible Warnings:

Null Test After Dereference  at packet-smb.c:15017

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

dissect_transaction_response

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-smb.c)expand/collapse
Show more  
 14946  dissect_transaction_response(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, proto_tree *smb_tree _U_)
 14947  {
 14948          guint8 sc, wc;
 14949          guint16 od=0, po=0, pc=0, pd=0, dc=0, dd=0, td=0, tp=0;
 14950          smb_info_t *si;
 14951          smb_transact2_info_t *t2i = NULL;
 14952          guint16 bc;
 14953          int padcnt;
 14954          gboolean dissected_trans;
 14955          fragment_data *r_fd = NULL;
 14956          tvbuff_t *pd_tvb=NULL, *d_tvb=NULL, *p_tvb=NULL;
 14957          tvbuff_t *s_tvb=NULL, *sp_tvb=NULL;
 14958          gboolean save_fragmented;
 14959          proto_item *item;
 14960   
 14961          si = (smb_info_t *)pinfo->private_data;
 14962          DISSECTOR_ASSERT(si);
 14963   
 14964          switch(si->cmd){
 14965          case SMB_COM_TRANSACTION2:
 14966                  /* transaction2 */
 14967                  if (si->sip != NULL && si->sip->extra_info_type == SMB_EI_T2I) {
 14968                          t2i = si->sip->extra_info;
 14969                  } else 
 14970                          t2i = NULL;
 14971                  if (t2i == NULL) {
 14972                          /*
 14973                           * We didn't see the matching request, so we don't
 14974                           * know what type of transaction this is.
 14975                           */
 14976                          proto_tree_add_text(tree, tvb, 0, 0,
 14977                                  "Subcommand: <UNKNOWN> since request packet wasn't seen");
 14978                          if (check_col(pinfo->cinfo, COL_INFO)) {
 14979                                  col_append_str(pinfo->cinfo, COL_INFO, "<unknown>");
 14980                          }
 14981                  } else {
 14982                          si->info_level = t2i->info_level;
 14983                          if (t2i->subcmd == -1) {
 14984                                  /*
 14985                                   * We didn't manage to extract the subcommand 
 14986                                   * from the matching request (perhaps because 
 14987                                   * the frame was short), so we don't know what
 14988                                   * type of transaction this is.
 14989                                   */
 14990                                  proto_tree_add_text(tree, tvb, 0, 0,
 14991                                          "Subcommand: <UNKNOWN> since transaction code wasn't found in request packet");
 14992                                  if (check_col(pinfo->cinfo, COL_INFO)) {
 14993                                          col_append_str(pinfo->cinfo, COL_INFO, "<unknown>");
 14994                                  }
 14995                          } else {
 14996                                  proto_tree_add_uint(tree, hf_smb_trans2_subcmd, tvb, 0, 0, t2i->subcmd);
 14997                                  /* FIND_FIRST2 */
 14998                                  if(t2i && t2i->subcmd==0x0001){
 14999                                          item=proto_tree_add_uint(tree, hf_smb_ff2_information_level, tvb, 0, 0, t2i->info_level);
 15000                                          PROTO_ITEM_SET_GENERATED(item);
 15001                                          if(t2i->name){
 15002                                                  item=proto_tree_add_string(tree, hf_smb_search_pattern, tvb, 0, 0, t2i->name);
 15003                                                  PROTO_ITEM_SET_GENERATED(item);
 15004                                          }
 15005                                  }
 15006   
 15007                                  /* QUERY_PATH_INFORMATION */
 15008                                  if(t2i && t2i->subcmd==0x0005){
 15009                                          item=proto_tree_add_uint(tree, hf_smb_qpi_loi, tvb, 0, 0, t2i->info_level);
 15010                                          PROTO_ITEM_SET_GENERATED(item);
 15011                                          if(t2i->name){
 15012                                                  item=proto_tree_add_string(tree, hf_smb_file_name, tvb, 0, 0, t2i->name);
 15013                                                  PROTO_ITEM_SET_GENERATED(item);
 15014                                          }
 15015                                  }
 15016                                  /* QUERY_FILE_INFORMATION */
 15017                                  if(t2i && t2i->subcmd==0x0007){
 15018                                          item=proto_tree_add_uint(tree, hf_smb_qpi_loi, tvb, 0, 0, t2i->info_level);
 15019                                          PROTO_ITEM_SET_GENERATED(item);
 15020                                  }
 15021                                  /* QUERY_FS_INFORMATION */
 15022                                  if(t2i && t2i->subcmd==0x0003){
 15023                                          item=proto_tree_add_uint(tree, hf_smb_qfsi_information_level, tvb, 0, 0, si->info_level);
 15024                                          PROTO_ITEM_SET_GENERATED(item);
 15025                                  }
 15026   
 15027                                  if (t2i && check_col(pinfo->cinfo, COL_INFO)) {
 15028                                          col_append_fstr(pinfo->cinfo, COL_INFO, ", %s",
 15029                                                  val_to_str(t2i->subcmd,
 15030                                                          trans2_cmd_vals,
 15031                                                          "<unknown (0x%02x)>"));
 15032                                  }
 15033                          }
 15034                  }
 15035                  break;
 15036          }
 15037   
 15038          WORD_COUNT;
 15039   
 15040          /* total param count, only a 16bit integer here */
 15041          tp = tvb_get_letohs(tvb, offset);
 15042          proto_tree_add_uint(tree, hf_smb_total_param_count, tvb, offset, 2, tp);
 15043          offset += 2;
 15044   
 15045          /* total data count, only a 16 bit integer here */
 15046          td = tvb_get_letohs(tvb, offset);
 15047          proto_tree_add_uint(tree, hf_smb_total_data_count, tvb, offset, 2, td);
 15048          offset += 2;
 15049   
 15050          /* 2 reserved bytes */
 15051          proto_tree_add_item(tree, hf_smb_reserved, tvb, offset, 2, TRUE);
 15052          offset += 2;
 15053   
 15054          /* param count */
 15055          pc = tvb_get_letohs(tvb, offset);
 15056          proto_tree_add_uint(tree, hf_smb_param_count16, tvb, offset, 2, pc);
 15057          offset += 2;
 15058   
 15059          /* param offset */
 15060          po = tvb_get_letohs(tvb, offset);
 15061          proto_tree_add_uint(tree, hf_smb_param_offset16, tvb, offset, 2, po);
 15062          offset += 2;
 15063   
 15064          /* param disp */
 15065          pd = tvb_get_letohs(tvb, offset);
 15066          proto_tree_add_uint(tree, hf_smb_param_disp16, tvb, offset, 2, pd);
 15067          offset += 2;
 15068   
 15069          /* data count */
 15070          dc = tvb_get_letohs(tvb, offset);
 15071          proto_tree_add_uint(tree, hf_smb_data_count16, tvb, offset, 2, dc);
 15072          offset += 2;
 15073   
 15074          /* data offset */
 15075          od = tvb_get_letohs(tvb, offset);
 15076          proto_tree_add_uint(tree, hf_smb_data_offset16, tvb, offset, 2, od);
 15077          offset += 2;
 15078   
 15079          /* data disp */
 15080          dd = tvb_get_letohs(tvb, offset);
 15081          proto_tree_add_uint(tree, hf_smb_data_disp16, tvb, offset, 2, dd);
 15082          offset += 2;
 15083   
 15084          /* setup count */
 15085          sc = tvb_get_guint8(tvb, offset);
 15086          proto_tree_add_uint(tree, hf_smb_setup_count, tvb, offset, 1, sc);
 15087          offset += 1;
 15088   
 15089          /* reserved byte */
 15090          proto_tree_add_item(tree, hf_smb_reserved, tvb, offset, 1, TRUE);
 15091          offset += 1;
 15092   
 15093   
 15094          /* if there were any setup bytes, put them in a tvb for later */
 15095          if(sc){
 15096                  if((2*sc)>tvb_length_remaining(tvb, offset)){
 15097                          s_tvb = tvb_new_subset(tvb, offset, tvb_length_remaining(tvb, offset), 2*sc);
 15098                  } else {
 15099                          s_tvb = tvb_new_subset(tvb, offset, 2*sc, 2*sc);
 15100                  }
 15101                  sp_tvb = tvb_new_subset(tvb, offset, -1, -1);
 15102          } else {
 15103                  s_tvb = NULL;
 15104                  sp_tvb=NULL;
 15105          }
 15106          offset += 2*sc;
 15107   
 15108   
 15109          BYTE_COUNT;
 15110   
 15111   
 15112          /* reassembly of SMB Transaction data payload.
 15113             In this section we do reassembly of both the data and parameters 
 15114             blocks of the SMB transaction command.
 15115          */
 15116          save_fragmented = pinfo->fragmented;
 15117          /* do we need reassembly? */
 15118          if( (td!=dc) || (tp!=pc) ){
 15119                  /* oh yeah, either data or parameter section needs
 15120                     reassembly
 15121                  */
 15122                  pinfo->fragmented = TRUE;
 15123                  if(smb_trans_reassembly){
 15124                          /* ...and we were told to do reassembly */
 15125                          if(pc && (tvb_length_remaining(tvb, po)>=pc) ){
 15126                                  r_fd = smb_trans_defragment(tree, pinfo, tvb,
 15127                                                               po, pc, pd, td+tp);
 15128   
 15129                          }
 15130                          if((r_fd==NULL) && dc && (tvb_length_remaining(tvb, od)>=dc) ){
 15131                                  r_fd = smb_trans_defragment(tree, pinfo, tvb,
 15132                                                               od, dc, dd+tp, td+tp);
 15133                          }
 15134                  }
 15135          }
 15136   
 15137          /* if we got a reassembled fd structure from the reassembly routine we must 
 15138             create pd_tvb from it 
 15139          */
 15140          if(r_fd){
 15141          proto_item *frag_tree_item;
 15142   
 15143                  pd_tvb = tvb_new_real_data(r_fd->data, r_fd->datalen,
 15144                                               r_fd->datalen);
 15145                  tvb_set_child_real_data_tvbuff(tvb, pd_tvb);
 15146                  add_new_data_source(pinfo, pd_tvb, "Reassembled SMB");
 15147                  show_fragment_tree(r_fd, &smb_frag_items, tree, pinfo, pd_tvb, &frag_tree_item);
 15148          }
 15149   
 15150   
 15151          if(pd_tvb){
 15152                  /* OK we have reassembled data, extract d_tvb and p_tvb from it */
 15153                  if(tp){
 15154                          p_tvb = tvb_new_subset(pd_tvb, 0, tp, tp);
 15155                  }
 15156                  if(td){
 15157                          d_tvb = tvb_new_subset(pd_tvb, tp, td, td);
 15158                  }
 15159          } else {
 15160                  /* It was not reassembled. Do as best as we can.
 15161                   * in this case we always try to dissect the stuff if 
 15162                   * data and param displacement is 0. i.e. for the first 
 15163                   * (and maybe only) packet.
 15164                   */
 15165                  if( (pd==0) && (dd==0) ){
 15166                          int min;
 15167                          int reported_min;
 15168                          min = MIN(pc,tvb_length_remaining(tvb,po));
 15169                          reported_min = MIN(pc,tvb_reported_length_remaining(tvb,po));
 15170                          if(min && reported_min) {
 15171                                  p_tvb = tvb_new_subset(tvb, po, min, reported_min);
 15172                          }
 15173                          min = MIN(dc,tvb_length_remaining(tvb,od));
 15174                          reported_min = MIN(dc,tvb_reported_length_remaining(tvb,od));
 15175                          if(min && reported_min) {
 15176                                  d_tvb = tvb_new_subset(tvb, od, min, reported_min);
 15177                          }
 15178                          /*
 15179                           * A tvbuff containing the parameters 
 15180                           * and the data.
 15181                           * XXX - check pc and dc as well?
 15182                           */
 15183                          if (tvb_length_remaining(tvb, po)){
 15184                                  pd_tvb = tvb_new_subset(tvb, po, -1, -1);
 15185                          }
 15186                  }
 15187          }
 15188   
 15189   
 15190   
 15191          /* parameters */
 15192          if(po>offset){
 15193                  /* We have some padding bytes.
 15194                  */
 15195                  padcnt = po-offset;
 15196                  if (padcnt > bc)
 15197                          padcnt = bc;
 15198                  proto_tree_add_item(tree, hf_smb_padding, tvb, offset, padcnt, TRUE);
 15199                  COUNT_BYTES(padcnt);
 15200          }
 15201          if(si->cmd==SMB_COM_TRANSACTION2 && p_tvb){
 15202                  /* TRANSACTION2 parameters*/
 15203                  dissect_transaction2_response_parameters(p_tvb, pinfo, tree);
 15204          }
 15205          COUNT_BYTES(pc);
 15206   
 15207   
 15208          /* data */
 15209          if(od>offset){
 15210                  /* We have some initial padding bytes.
 15211                  */
 15212                  padcnt = od-offset;
 15213                  if (padcnt > bc)
 15214                          padcnt = bc;
 15215                  proto_tree_add_item(tree, hf_smb_padding, tvb, offset, padcnt, TRUE);
 15216                  COUNT_BYTES(padcnt);
 15217          }
 15218          /*
 15219           * If the data count is bigger than the count of bytes 
 15220           * remaining, clamp it so that the count of bytes remaining 
 15221           * doesn't go negative.
 15222           */
 15223          if (dc > bc)
 15224                  dc = bc;
 15225          COUNT_BYTES(dc);
 15226   
 15227   
 15228   
 15229          /* from now on, everything is in separate tvbuffs so we dont count 
 15230             the bytes with COUNT_BYTES any more.
 15231             neither do we reference offset any more (which by now points to the 
 15232             first byte AFTER this PDU */
 15233   
 15234   
 15235          if(si->cmd==SMB_COM_TRANSACTION2 && d_tvb){
 15236                  /* TRANSACTION2 parameters*/
 15237                  dissect_transaction2_response_data(d_tvb, pinfo, tree);
 15238          }
 15239   
 15240   
 15241          if(si->cmd==SMB_COM_TRANSACTION){
 15242                  smb_transact_info_t *tri;
 15243   
 15244                  dissected_trans = FALSE;
 15245                  if (si->sip != NULL && si->sip->extra_info_type == SMB_EI_TRI)
 15246                          tri = si->sip->extra_info;
 15247                  else 
 15248                          tri = NULL;
 15249                  if (tri != NULL) {
 15250                          switch(tri->subcmd){
 15251   
 15252                          case TRANSACTION_PIPE:
 15253                                  /* This function is safe to call for 
 15254                                     s_tvb==sp_tvb==NULL, i.e. if we don't
 15255                                     know them at this point.
 15256                                     It's also safe to call if "p_tvb"
 15257                                     or "d_tvb" are null.
 15258                                  */
 15259                                  if( pd_tvb) {
 15260                                          dissected_trans = dissect_pipe_smb(
 15261                                                  sp_tvb, s_tvb, pd_tvb, p_tvb,
 15262                                                  d_tvb, NULL, pinfo, top_tree);
 15263                                  }
 15264                                  break;
 15265   
 15266                          case TRANSACTION_MAILSLOT:
 15267                                  /* This one should be safe to call 
 15268                                     even if s_tvb and sp_tvb is NULL
 15269                                  */
 15270                                  if(d_tvb){
 15271                                          dissected_trans = dissect_mailslot_smb(
 15272                                                  sp_tvb, s_tvb, d_tvb, NULL, pinfo,
 15273                                                  top_tree);
 15274                                  }
 15275                                  break;
 15276                          }
 15277                  }
 15278                  if (!dissected_trans) {
 15279                          /* This one is safe to call for s_tvb==p_tvb==d_tvb==NULL */
 15280                          dissect_trans_data(s_tvb, p_tvb, d_tvb, tree);
 15281                  }
 15282          }
 15283   
 15284   
 15285          if( (p_tvb==0) && (d_tvb==0) ){
 15286                  if(check_col(pinfo->cinfo, COL_INFO)){
 15287                          col_append_str(pinfo->cinfo, COL_INFO,
 15288                                         "[transact continuation]");
 15289                  }
 15290          }
 15291   
 15292          pinfo->fragmented = save_fragmented;
 15293          END_OF_SMB 
 15294   
 15295          return offset;
 15296  }
Show more  




Change Warning 2974.35028 : Null Test After Dereference

Priority:
State:
Finding:
Owner:
Note: