How is integer overflow exploitable?

后端 未结 5 1852
余生分开走
余生分开走 2020-12-14 17:45

Does anyone have a detailed explanation on how integers can be exploited? I have been reading a lot about the concept, and I understand what an it is, and I understand buffe

5条回答
  •  孤城傲影
    2020-12-14 17:47

    It depends on how the variable is used. If you never make any security decisions based on integers you have added with input integers (where an adversary could provoke an overflow), then I can't think of how you would get in trouble (but this kind of stuff can be subtle).

    Then again, I have seen plenty of code like this that doesn't validate user input (although this example is contrived):

    int pricePerWidgetInCents = 3199;
    int numberOfWidgetsToBuy = int.Parse(/* some user input string */);
    int totalCostOfWidgetsSoldInCents = pricePerWidgetInCents * numberOfWidgetsToBuy; // KA-BOOM!
    
    // potentially much later
    int orderSubtotal = whatever + totalCostOfWidgetInCents;
    

    Everything is hunky-dory until the day you sell 671,299 widgets for -$21,474,817.95. Boss might be upset.

提交回复
热议问题