From 68c3438474ddd857d5e21f8da0c0cf398e6b3812 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Wed, 8 Feb 2023 13:22:16 -0500 Subject: [PATCH] Fix issue where dynamic challenges break if the decay is 0 (#2255) * Fix issue where dynamic challenges break if the decay is 0 * Prevent users from adding a decay limit of 0 to dynamic value challenges --- CTFd/plugins/dynamic_challenges/__init__.py | 5 +++++ CTFd/plugins/dynamic_challenges/assets/create.html | 2 +- CTFd/plugins/dynamic_challenges/assets/update.html | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CTFd/plugins/dynamic_challenges/__init__.py b/CTFd/plugins/dynamic_challenges/__init__.py index 24591428..ab7aaca2 100644 --- a/CTFd/plugins/dynamic_challenges/__init__.py +++ b/CTFd/plugins/dynamic_challenges/__init__.py @@ -69,6 +69,11 @@ class DynamicValueChallenge(BaseChallenge): # We subtract -1 to allow the first solver to get max point value solve_count -= 1 + # Handle situations where admins have entered a 0 decay + # This is invalid as it can cause a division by zero + if challenge.decay == 0: + challenge.decay = 1 + # It is important that this calculation takes into account floats. # Hence this file uses from __future__ import division value = ( diff --git a/CTFd/plugins/dynamic_challenges/assets/create.html b/CTFd/plugins/dynamic_challenges/assets/create.html index c6e261e8..d8f3e2a1 100644 --- a/CTFd/plugins/dynamic_challenges/assets/create.html +++ b/CTFd/plugins/dynamic_challenges/assets/create.html @@ -25,7 +25,7 @@ The amount of solves before the challenge reaches its minimum value - +
diff --git a/CTFd/plugins/dynamic_challenges/assets/update.html b/CTFd/plugins/dynamic_challenges/assets/update.html index 48a0711f..d432fe34 100644 --- a/CTFd/plugins/dynamic_challenges/assets/update.html +++ b/CTFd/plugins/dynamic_challenges/assets/update.html @@ -25,7 +25,7 @@ The amount of solves before the challenge reaches its minimum value - +