Skip to content

Commit 76d5ef9

Browse files
committed
Improve error handling
1 parent e0b1e0d commit 76d5ef9

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

easybuggy/views.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ def redirect_login(request):
9595
# redirect(response.encodeRedirectURL("/" + login_type + "/login" + query_string))
9696
else:
9797
return redirect("/" + login_type + "/login" + query_string)
98-
99-
10098
# -----------------------------------------------------------------------
10199

102100

@@ -396,7 +394,7 @@ def integer_overflow(request):
396394
if request.method == 'POST':
397395
str_times = request.POST.get("times")
398396

399-
if str_times is not None and str_times is not '':
397+
if str_times is not None and str_times is not '' and str_times.isdigit():
400398
times = int(str_times)
401399
if times >= 0:
402400
# TODO Change a better way
@@ -452,8 +450,8 @@ def loss_of_trailing_digits(request):
452450
}
453451
if request.method == 'POST':
454452
number = request.POST.get("number")
455-
d['number'] = number
456-
if number is not None and -1 < float(number) < 1:
453+
if number is not None and is_number(number) and -1 < float(number) < 1:
454+
d['number'] = number
457455
d['result'] = float(number) + 1
458456
return render(request, 'lossoftrailingdigits.html', d)
459457

@@ -466,7 +464,7 @@ def xss(request):
466464
}
467465
if request.method == 'POST':
468466
input_str = request.POST.get("string")
469-
if input_str is not None:
467+
if input_str is not None and input_str is not '':
470468
d['msg'] = input_str[::-1]
471469
return render(request, 'xss.html', d)
472470

@@ -544,7 +542,7 @@ def code_injection(request):
544542
d['expression'] = expression
545543
expression = expression.replace("math", "__import__('math')")
546544
try:
547-
d['value'] = eval(expression)
545+
d['value'] = str(eval(expression))
548546
except Exception as e:
549547
logger.exception('Exception occurs: %s', e)
550548
d['errmsg'] = _("msg.invalid.expression") % {"exception": e}
@@ -969,6 +967,14 @@ def send_email(subject, msg_body):
969967
smtp_server.sendmail(settings.MAIL_USER, settings.MAIL_ADMIN_ADDRESS, msg.as_string())
970968

971969

970+
def is_number(s):
971+
try:
972+
float(s)
973+
return True
974+
except ValueError:
975+
return False
976+
977+
972978
class MyObject:
973979
def __init__(self):
974980
self.id = None

locale/en/LC_MESSAGES/django.mo

9 Bytes
Binary file not shown.

locale/en/LC_MESSAGES/django.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ msgstr "Reverse String"
173173
#: easybuggy/views.py:457 templates/xss.html:16
174174
msgid "msg.note.xss"
175175
msgstr ""
176-
"Session ID is shown if you enter name to <code>>tpircs/<;)eikooc."
176+
"JavaScript is executed if you enter name to <code>>tpircs/<;)eikooc."
177177
"tnemucod(trela>tpIrcs<</code>"
178178

179179
#: easybuggy/views.py:468
@@ -847,7 +847,7 @@ msgstr "You can reverse the color of an image file."
847847

848848
#: templates/xss.html:7
849849
msgid "description.reverse.string"
850-
msgstr "If you enter a string, then JavaScript is executed."
850+
msgstr "If you enter a string, then the reversed string is shown."
851851

852852
#: templates/xxe.html:8
853853
msgid "label.result"

locale/ja/LC_MESSAGES/django.mo

4 Bytes
Binary file not shown.

locale/ja/LC_MESSAGES/django.po

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ msgstr "文字列の逆転"
172172
#: easybuggy/views.py:457 templates/xss.html:16
173173
msgid "msg.note.xss"
174174
msgstr ""
175-
"名前に<code>>tpircs/<;)eikooc.tnemucod(trela>tpIrcs<</code>を入力すると、セッ"
176-
"ションIDが表示されます。"
175+
"名前に<code>>tpircs/<;)eikooc.tnemucod(trela>tpIrcs<</code>を入力すると、"
176+
"JavaScriptが実行されます。"
177177

178178
#: easybuggy/views.py:468
179179
msgid "title.sqlijc.page"
@@ -844,7 +844,7 @@ msgstr "画像ファイルの色反転を行うことができます。"
844844

845845
#: templates/xss.html:7
846846
msgid "description.reverse.string"
847-
msgstr "文字列を入力すると、JavaScriptが実行されます。"
847+
msgstr "文字列を入力すると、文字列が逆転して表示されます。"
848848

849849
#: templates/xxe.html:8
850850
msgid "label.result"

0 commit comments

Comments
 (0)