Skip to content

Commit e623da3

Browse files
committed
Small fix of sql vuln
1 parent d20632f commit e623da3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

service/src/DatabaseManager/FindProblemsByAuthorId.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ public function __construct(
1616

1717
public function execute(?string $authorUsername): array
1818
{
19+
try {
1920
$sql = "SELECT p.title as title, p.difficulty as difficulty, p.is_published as is_published, p.id as id, p.description as description FROM problems p JOIN users u ON p.author_id = u.id WHERE p.is_published = true";
2021
if ($authorUsername) {
2122
$sql .= " AND u.username = '" . $authorUsername . "'";
2223
}
2324

2425
$preparedStatement = $this->entityManager->getConnection()->prepare($sql);
25-
$result = $preparedStatement->executeQuery();
26-
return $result->fetchAllAssociative();
26+
$result = $preparedStatement->executeQuery();
27+
return $result->fetchAllAssociative();
28+
} catch (\Exception $e) {
29+
return [];
30+
}
2731
}
2832
}

0 commit comments

Comments
 (0)