Skip to content

Commit

Permalink
improved query safety in bulk album methods
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketMan committed May 25, 2024
1 parent 61517ce commit 67ebff0
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions engine/impl/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zookeeper Online
*
* @author Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2023 Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2024 Jim Mason <[email protected]>
* @link https://zookeeper.ibinx.com/
* @license GPL-3.0
*
Expand Down Expand Up @@ -416,14 +416,12 @@ private static function displayName($airname, $realname) {
public function linkReviews(&$albums, $loggedIn = false, $includeBody = false) {
$chain = [];
$tags = [];
$queryset = "";
for($i = 0; $albums != null && $i < sizeof($albums); $i++) {
$tag = array_key_exists("tag", $albums[$i])?$albums[$i]["tag"]:0;
if($tag) {
if($tag && is_numeric($tag)) {
if(array_key_exists($tag, $tags))
$chain[$i] = $tags[$tag];
else
$queryset .= ", $tag";

$tags[$tag] = $i;
}
}
Expand All @@ -433,7 +431,7 @@ public function linkReviews(&$albums, $loggedIn = false, $includeBody = false) {
"$ib review FROM reviews r " .
"LEFT JOIN users u ON r.user = u.name " .
"LEFT JOIN airnames a ON r.airname = a.id WHERE " .
"tag IN (0" . $queryset . ")";
"tag IN (" . implode(',', array_keys($tags)) . ")";
if(!$loggedIn)
$query .= " AND private = 0";
$query .= " GROUP BY tag";
Expand Down Expand Up @@ -461,21 +459,19 @@ public function linkReviews(&$albums, $loggedIn = false, $includeBody = false) {
public function markAlbumsReviewed(&$albums, $loggedIn = 0) {
$chain = [];
$tags = [];
$queryset = "";
for($i = 0; $albums != null && $i < sizeof($albums); $i++) {
$tag = array_key_exists("tag", $albums[$i])?$albums[$i]["tag"]:0;
if($tag) {
if($tag && is_numeric($tag)) {
if(array_key_exists($tag, $tags))
$chain[$i] = $tags[$tag];
else
$queryset .= ", $tag";

$tags[$tag] = $i;
}
}
$query = "SELECT tag, a.airname, realname FROM reviews r " .
"LEFT JOIN users u ON r.user = u.name " .
"LEFT JOIN airnames a ON r.airname = a.id WHERE " .
"tag IN (0" . $queryset . ")";
"tag IN (" . implode(',', array_keys($tags)) . ")";
if(!$loggedIn)
$query .= " AND private = 0";
$query .= " GROUP BY tag";
Expand All @@ -501,19 +497,19 @@ public function markAlbumsPlayable(&$albums) {

$chain = [];
$tags = [];
$queryset = "";
$querysetcoll = "";
$queryset = [];
$querysetcoll = [];
for($i = 0; $albums != null && $i < sizeof($albums); $i++) {
$tag = array_key_exists("tag", $albums[$i])?$albums[$i]["tag"]:0;
if($tag) {
if($tag && is_numeric($tag)) {
if(array_key_exists($tag, $tags))
$chain[$i] = $tags[$tag];
else {
if(array_key_exists("iscoll", $albums[$i]) &&
$albums[$i]["iscoll"])
$querysetcoll .= ", $tag";
$querysetcoll[] = $tag;
else
$queryset .= ", $tag";
$queryset[] = $tag;
}
$tags[$tag] = $i;
}
Expand All @@ -522,11 +518,11 @@ public function markAlbumsPlayable(&$albums) {
$urlFilter = $enableExternalLinks ? "url <> ''" : "url RLIKE ?";

$query = "SELECT tag FROM tracknames ".
"WHERE $urlFilter AND tag IN (0${queryset}) ".
"WHERE $urlFilter AND tag IN (" . implode(',', $queryset) . ") ".
"GROUP BY tag ";
if($querysetcoll)
$query .= "UNION SELECT tag FROM colltracknames ".
"WHERE $urlFilter AND tag IN (0${querysetcoll}) ".
"WHERE $urlFilter AND tag IN (" . implode(',', $querysetcoll) . ") ".
"GROUP BY tag";
$stmt = $this->prepare($query);
if(!$enableExternalLinks) {
Expand Down

0 comments on commit 67ebff0

Please sign in to comment.