Print this page
11506 smatch resync

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_struct_assignment.c
          +++ new/usr/src/tools/smatch/src/smatch_struct_assignment.c
↓ open down ↓ 437 lines elided ↑ open up ↑
 438  438  {
 439  439          struct expression *dest;
 440  440          struct expression *src;
 441  441  
 442  442          dest = get_argument_from_call_expr(expr->args, 0);
 443  443          src = get_argument_from_call_expr(expr->args, 1);
 444  444  
 445  445          __struct_members_copy(COPY_MEMCPY, expr, remove_addr(dest), remove_addr(src));
 446  446  }
 447  447  
      448 +static void match_memdup(const char *fn, struct expression *call_expr,
      449 +                        struct expression *expr, void *_unused)
      450 +{
      451 +        struct expression *left, *right, *arg;
      452 +
      453 +        if (!expr || expr->type != EXPR_ASSIGNMENT)
      454 +                return;
      455 +
      456 +        left = strip_expr(expr->left);
      457 +        right = strip_expr(expr->right);
      458 +
      459 +        if (right->type != EXPR_CALL)
      460 +                return;
      461 +        arg = get_argument_from_call_expr(right->args, 0);
      462 +        __struct_members_copy(COPY_MEMCPY, expr, left, arg);
      463 +}
      464 +
 448  465  static void match_memcpy_unknown(const char *fn, struct expression *expr, void *_arg)
 449  466  {
 450  467          struct expression *dest;
 451  468  
 452  469          dest = get_argument_from_call_expr(expr->args, 0);
 453  470          __struct_members_copy(COPY_MEMCPY, expr, remove_addr(dest), NULL);
 454  471  }
 455  472  
 456  473  static void match_sscanf(const char *fn, struct expression *expr, void *unused)
 457  474  {
↓ open down ↓ 83 lines elided ↑ open up ↑
 541  558  void register_struct_assignment(int id)
 542  559  {
 543  560          add_function_hook("memset", &match_memset, NULL);
 544  561          add_function_hook("__memset", &match_memset, NULL);
 545  562  
 546  563          add_function_hook("memcpy", &match_memcpy, INT_PTR(0));
 547  564          add_function_hook("memmove", &match_memcpy, INT_PTR(0));
 548  565          add_function_hook("__memcpy", &match_memcpy, INT_PTR(0));
 549  566          add_function_hook("__memmove", &match_memcpy, INT_PTR(0));
 550  567  
      568 +        if (option_project == PROJ_KERNEL)
      569 +                return_implies_state_sval("kmemdup", valid_ptr_min_sval, valid_ptr_max_sval, &match_memdup, NULL);
      570 +
 551  571          add_function_hook("sscanf", &match_sscanf, NULL);
 552  572  
 553  573          add_hook(&unop_expr, OP_HOOK);
 554  574          register_clears_param();
 555  575          select_return_states_hook(PARAM_CLEARED, &db_param_cleared);
 556  576  
 557  577          select_return_states_hook(CONTAINER, &returns_container_of);
 558  578  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX