Print this page
11506 smatch resync

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_buf_size.c
          +++ new/usr/src/tools/smatch/src/smatch_buf_size.c
↓ open down ↓ 322 lines elided ↑ open up ↑
 323  323          if (!state)
 324  324                  return NULL;
 325  325          return estate_rl(state);
 326  326  }
 327  327  
 328  328  static int get_bytes_from_address(struct expression *expr)
 329  329  {
 330  330          struct symbol *type;
 331  331          int ret;
 332  332  
 333      -        if (!option_spammy)
 334      -                return 0;
 335  333          if (expr->type != EXPR_PREOP || expr->op != '&')
 336  334                  return 0;
 337  335          type = get_type(expr);
 338  336          if (!type)
 339  337                  return 0;
 340  338  
 341  339          if (type->type == SYM_PTR)
 342  340                  type = get_base_type(type);
 343  341  
 344  342          ret = type_bytes(type);
↓ open down ↓ 154 lines elided ↑ open up ↑
 499  497                  bytes = type_bytes(type);
 500  498                  if (bytes == 0)
 501  499                          return NULL;
 502  500                  offset.value *= bytes;
 503  501                  size = get_array_size_bytes(expr->left);
 504  502                  if (size <= 0)
 505  503                          return NULL;
 506  504                  return alloc_int_rl(size - offset.value);
 507  505          }
 508  506  
      507 +        size = get_stored_size_end_struct_bytes(expr);
      508 +        if (size)
      509 +                return alloc_int_rl(size);
      510 +
 509  511          /* buf[4] */
 510  512          size = get_real_array_size(expr);
 511  513          if (size)
 512  514                  return alloc_int_rl(elements_to_bytes(expr, size));
 513  515  
 514  516          /* buf = malloc(1024); */
 515  517          ret = get_stored_size_bytes(expr);
 516  518          if (ret)
 517  519                  return ret;
 518  520  
 519      -        size = get_stored_size_end_struct_bytes(expr);
 520      -        if (size)
 521      -                return alloc_int_rl(size);
 522      -
 523  521          /* char *foo = "BAR" */
 524  522          size = get_size_from_initializer(expr);
 525  523          if (size)
 526  524                  return alloc_int_rl(elements_to_bytes(expr, size));
 527  525  
 528  526          size = get_bytes_from_address(expr);
 529  527          if (size)
 530  528                  return alloc_int_rl(size);
 531  529  
 532  530          ret = size_from_db(expr);
↓ open down ↓ 171 lines elided ↑ open up ↑
 704  702          right = strip_expr(expr->right);
 705  703          arg = get_argument_from_call_expr(right->args, size_arg);
 706  704          get_absolute_rl(arg, &rl);
 707  705          rl = cast_rl(&int_ctype, rl);
 708  706          store_alloc(expr->left, rl);
 709  707  }
 710  708  
 711  709  static void match_calloc(const char *fn, struct expression *expr, void *unused)
 712  710  {
 713  711          struct expression *right;
 714      -        struct expression *arg;
 715      -        sval_t elements;
 716      -        sval_t size;
      712 +        struct expression *size, *nr, *mult;
      713 +        struct range_list *rl;
 717  714  
 718  715          right = strip_expr(expr->right);
 719      -        arg = get_argument_from_call_expr(right->args, 0);
 720      -        if (!get_implied_value(arg, &elements))
 721      -                return; // FIXME!!!
 722      -        arg = get_argument_from_call_expr(right->args, 1);
 723      -        if (get_implied_value(arg, &size))
 724      -                store_alloc(expr->left, size_to_rl(elements.value * size.value));
      716 +        nr = get_argument_from_call_expr(right->args, 0);
      717 +        size = get_argument_from_call_expr(right->args, 1);
      718 +        mult = binop_expression(nr, '*', size);
      719 +        if (get_implied_rl(mult, &rl))
      720 +                store_alloc(expr->left, rl);
 725  721          else
 726  722                  store_alloc(expr->left, size_to_rl(-1));
 727  723  }
 728  724  
 729  725  static void match_page(const char *fn, struct expression *expr, void *_unused)
 730  726  {
 731  727          sval_t page_size = {
 732  728                  .type = &int_ctype,
 733  729                  {.value = 4096},
 734  730          };
↓ open down ↓ 131 lines elided ↑ open up ↑
 866  862                  return;
 867  863  
 868  864          snprintf(buf, sizeof(buf), "%d", bytes);
 869  865          sql_insert_data_info_var_sym(sym->ident->name, sym, BUF_SIZE, buf);
 870  866  }
 871  867  
 872  868  void register_buf_size(int id)
 873  869  {
 874  870          my_size_id = id;
 875  871  
      872 +        set_dynamic_states(my_size_id);
      873 +
 876  874          add_unmatched_state_hook(my_size_id, &unmatched_size_state);
 877  875  
 878  876          select_caller_info_hook(set_param_buf_size, BUF_SIZE);
 879  877          select_return_states_hook(BUF_SIZE, &db_returns_buf_size);
 880  878          add_split_return_callback(print_returned_allocations);
 881  879  
 882  880          allocation_funcs = create_function_hashtable(100);
 883  881          add_allocation_function("malloc", &match_alloc, 0);
 884  882          add_allocation_function("calloc", &match_calloc, 0);
 885  883          add_allocation_function("memdup", &match_alloc, 1);
↓ open down ↓ 15 lines elided ↑ open up ↑
 901  899                  add_allocation_function("dma_alloc_attrs", &match_alloc, 1);
 902  900                  add_allocation_function("pci_alloc_consistent", &match_alloc, 1);
 903  901                  add_allocation_function("pci_alloc_coherent", &match_alloc, 1);
 904  902                  add_allocation_function("devm_kmalloc", &match_alloc, 1);
 905  903                  add_allocation_function("devm_kzalloc", &match_alloc, 1);
 906  904                  add_allocation_function("krealloc", &match_alloc, 1);
 907  905                  add_allocation_function("__alloc_bootmem", &match_alloc, 0);
 908  906                  add_allocation_function("alloc_bootmem", &match_alloc, 0);
 909  907                  add_allocation_function("kmap", &match_page, 0);
 910  908                  add_allocation_function("get_zeroed_page", &match_page, 0);
      909 +                add_allocation_function("alloc_page", &match_page, 0);
      910 +                add_allocation_function("page_address", &match_page, 0);
      911 +                add_allocation_function("lowmem_page_address", &match_page, 0);
 911  912                  add_allocation_function("alloc_pages", &match_alloc_pages, 1);
 912  913                  add_allocation_function("alloc_pages_current", &match_alloc_pages, 1);
 913  914                  add_allocation_function("__get_free_pages", &match_alloc_pages, 1);
 914  915          }
 915  916  
 916  917          add_allocation_function("strndup", match_strndup, 0);
 917  918          if (option_project == PROJ_KERNEL)
 918  919                  add_allocation_function("kstrndup", match_strndup, 0);
 919  920  
 920  921          add_modification_hook(my_size_id, &set_size_undefined);
↓ open down ↓ 15 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX