Comments (4)
Easier repro steps:
Submit the same wrong answer twice to a challenge. Go to the Submissions page and mark both submissions as correct. Go back to the Challenges page. You'll see an SQL exception.
from mellivora.
Tracked down the bug. It is in this code:
https://github.com/Nakiami/mellivora/blob/master/htdocs/challenges.php
$challenges = db_query_fetch_all('
SELECT
c.id,
c.title,
c.description,
c.available_from,
c.available_until,
c.points,
c.num_attempts_allowed,
c.min_seconds_between_submissions,
c.automark,
c.relies_on,
IF(c.automark = 1, 0, (SELECT ss.id FROM submissions AS ss WHERE ss.challenge = c.id AND ss.user_id = :user_id_1 AND ss.marked = 0)) AS unmarked, -- a submission is waiting to be marked
(SELECT ss.added FROM submissions AS ss WHERE ss.challenge = c.id AND ss.user_id = :user_id_2 AND ss.correct = 1) AS correct_submission_added, -- a correct submission has been made
(SELECT COUNT(*) FROM submissions AS ss WHERE ss.challenge = c.id AND ss.user_id = :user_id_3) AS num_submissions, -- number of submissions made
(SELECT max(ss.added) FROM submissions AS ss WHERE ss.challenge = c.id AND ss.user_id = :user_id_4) AS latest_submission_added
FROM challenges AS c
WHERE c.category = :category
ORDER BY c.points ASC, c.id ASC',
array(
'user_id_1'=>$_SESSION['id'],
'user_id_2'=>$_SESSION['id'],
'user_id_3'=>$_SESSION['id'],
'user_id_4'=>$_SESSION['id'],
'category'=>$current_category['id']
)
The problem is that if there are multiple correct submissions, a subquery returns more than one row where MySQL requires just one return row, and so it causes an error. This cascades into an unrelated error message which is a really annoying "feature" of MySQL.
Here is the problem subquery:
(SELECT ss.added FROM submissions AS ss WHERE ss.challenge = c.id AND ss.user_id = :user_id_2 AND ss.correct = 1)
Here is the fix:
(SELECT ss.added FROM submissions AS ss WHERE ss.challenge = c.id AND ss.user_id = :user_id_2 AND ss.correct = 1 LIMIT 1)
I'll submit a pull request.
from mellivora.
Hi! Thanks for your work. I think this hides the underlying problem. There needs to be a more reliable way to stop duplicate correct entries. I'd suggest implementing:
- Race condition protection using sessions for the challenges page. We could also disable the button after being pressed once for a better user experience.
- A check when marking submissions in the admin panel to make sure the challenge doesn't already have a correct solution for that user.
from mellivora.
from mellivora.
Related Issues (20)
- Cleartext password in error log
- Trouble with setting up SSL behind nginx reverse proxy HOT 1
- Connecting to "virtual" web interface from the host HOT 4
- XSS issue leading to platform takeover under certain setups HOT 1
- Documentation on installing on Ubuntu should be updated HOT 2
- Docker compose error HOT 1
- Docker: harcoded localhost HOT 10
- email not connecting
- admin getting logged out. HOT 4
- No connection to database HOT 1
- Flags stored in plaintext
- Etymology HOT 1
- docker version not working HOT 1
- Disable registration mail sending. Suggestion for solution HOT 1
- Account mail confirmation HOT 4
- Database error
- How to open admin panel HOT 4
- Description Formatting HOT 1
- help with users HOT 1
- After login Redirection error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mellivora.