Skip to content

Commit

Permalink
fix division by zero (reported by BigBobbyTable)
Browse files Browse the repository at this point in the history
(cherry picked from commit ef79b638519ec2a0313f36034f9b940e6cb290c3)
  • Loading branch information
jbremer authored and brad-sp committed Sep 17, 2015
1 parent b535b5d commit 3fa0daf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion web/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ def index(request):
# Get the amount of tasks that actually completed.
finished = len(tasks)

hourly = 60 * 60 * finished / (completed - started)
# It has happened that for unknown reasons completed and started were
# equal in which case an exception is thrown, avoid this.
if int(completed - started):
hourly = 60 * 60 * finished / (completed - started)
else:
hourly = 0

report["estimate_hour"] = int(hourly)
report["estimate_day"] = int(24 * hourly)
Expand Down

2 comments on commit 3fa0daf

@geudrik
Copy link
Contributor

@geudrik geudrik commented on 3fa0daf Jan 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 70, there are times when completed and started appear to be None. I've modified my local file to read if completed is not None and started is not None and int(completed - started):

As a result of the None types, with the current code, you get tracebacks that look like the following

[Wed Jan 06 06:23:05.108959 2016] [:error] [pid 16588] Traceback (most recent call last):
[Wed Jan 06 06:23:05.108964 2016] [:error] [pid 16588]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 132, in get_response
[Wed Jan 06 06:23:05.108968 2016] [:error] [pid 16588]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Wed Jan 06 06:23:05.108971 2016] [:error] [pid 16588]   File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/http.py", line 45, in inner
[Wed Jan 06 06:23:05.108975 2016] [:error] [pid 16588]     return func(request, *args, **kwargs)
[Wed Jan 06 06:23:05.108978 2016] [:error] [pid 16588]   File "/opt/cuckoo/cuckoo-modified/web/dashboard/views.py", line 70, in index
[Wed Jan 06 06:23:05.108981 2016] [:error] [pid 16588]     if int(completed - started):
[Wed Jan 06 06:23:05.108984 2016] [:error] [pid 16588] TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'

Tagging @brad-accuvant so that he see's this

@geudrik
Copy link
Contributor

@geudrik geudrik commented on 3fa0daf Jan 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing the code a little, this probably isn't an actual fix. The solution would be to figure out why we're getting NoneTypes back

Please sign in to comment.