Peer ID was erased if it contained non-latin characters (#1185)

This commit is contained in:
Cønstantine Kovalensky 2023-12-04 13:36:12 +04:00 committed by GitHub
commit 5f6ade8db9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -80,14 +80,14 @@ if (!isset($info_hash)) {
}
// Store info hash in hex format
$info_hash_hex = mb_check_encoding($info_hash, 'UTF8') ? $info_hash : bin2hex($info_hash);
$info_hash_hex = bin2hex($info_hash);
// Store peer id
$peer_id_sql = rtrim(DB()->escape(htmlCHR($peer_id)), ' ');
$peer_id_sql = rtrim(DB()->escape(preg_replace('/[^a-zA-Z0-9\-\_\.]/', '', $peer_id)), ' ');
// Check info_hash length
if (strlen($info_hash) !== 20) {
msg_die('Invalid info_hash: ' . $info_hash_hex);
msg_die('Invalid info_hash: ' . (mb_check_encoding($info_hash, 'UTF8') ? $info_hash : $info_hash_hex));
}
if (!isset($port) || $port < 0 || $port > 0xFFFF) {
@ -390,12 +390,13 @@ if (!$output) {
// Retrieve peers
$numwant = (int)$bb_cfg['tracker']['numwant'];
$compact_mode = ($bb_cfg['tracker']['compact_mode'] || !empty($compact));
$priority = $seeder ? 'seeder ASC, RAND()' : 'RAND()';
$rowset = DB()->fetch_rowset("
SELECT ip, ipv6, port
FROM " . BB_BT_TRACKER . "
WHERE topic_id = $topic_id
ORDER BY seeder ASC, RAND()
ORDER BY $priority
LIMIT $numwant
");