Merge lp:~stefanor/ibid/math-dos-381649 into lp:~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Stefano Rivera
Status: Merged
Approved by: Jonathan Hitchcock
Approved revision: 643
Merged at revision: 659
Proposed branch: lp:~stefanor/ibid/math-dos-381649
Merge into: lp:~ibid-core/ibid/old-trunk-pack-0.92
Diff against target: None lines
To merge this branch: bzr merge lp:~stefanor/ibid/math-dos-381649
Reviewer Review Type Date Requested Status
Jonathan Hitchcock Approve
Michael Gorven Approve
Review via email: mp+6889@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote :

Changed the semantics a little. The main bug was not checking isinstance(arg, long). But I prefer this limiting function.

Revision history for this message
Michael Gorven (mgorven) wrote :

 review approve

review: Approve
Revision history for this message
Jonathan Hitchcock (vhata) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/math.py'
2--- ibid/plugins/math.py 2009-05-02 16:33:45 +0000
3+++ ibid/plugins/math.py 2009-05-29 13:38:36 +0000
4@@ -76,9 +76,18 @@
5 pass
6
7 def limited_pow(*args):
8- for arg, limit in zip(args, (1e100, 200)):
9- if isinstance(arg, int) and (arg > limit or arg < -limit):
10- raise LimitException
11+ "We don't want users to DOS the bot. Pow is the most dangerous function. Limit it"
12+
13+ # Are all the arguments ints?
14+ if not [True for arg in args if not isinstance(arg, int) and not isinstance(arg, long)]:
15+ try:
16+ answer = pow(float(args[0]), float(args[1]))
17+ if answer > 1e+300:
18+ raise LimitException
19+
20+ except OverflowError, e:
21+ raise LimitException(e)
22+
23 return pow(*args)
24
25 # ast method

Subscribers

People subscribed via source and target branches