From 359c4fef9d9e1478fe4abf62c4b2e0f38307d0a8 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Tue, 19 Apr 2022 13:52:56 +0300 Subject: [PATCH] Avoid dereferencing null pointers PR #16896. Closes #16884 and similar issues. --- src/base/bittorrent/session.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 22dd85a9a..c1e8dcc98 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -4150,7 +4150,8 @@ void Session::handleTorrentMetadataReceived(TorrentImpl *const torrent) if (!torrentExportDirectory().isEmpty()) { #ifdef QBT_USES_LIBTORRENT2 - const TorrentInfo torrentInfo {*torrent->nativeHandle().torrent_file_with_hashes()}; + const std::shared_ptr completeTorrentInfo = torrent->nativeHandle().torrent_file_with_hashes(); + const TorrentInfo torrentInfo {*(completeTorrentInfo ? completeTorrentInfo : torrent->nativeHandle().torrent_file())}; #else const TorrentInfo torrentInfo {*torrent->nativeHandle().torrent_file()}; #endif @@ -4209,7 +4210,8 @@ void Session::handleTorrentFinished(TorrentImpl *const torrent) if (!finishedTorrentExportDirectory().isEmpty()) { #ifdef QBT_USES_LIBTORRENT2 - const TorrentInfo torrentInfo {*torrent->nativeHandle().torrent_file_with_hashes()}; + const std::shared_ptr completeTorrentInfo = torrent->nativeHandle().torrent_file_with_hashes(); + const TorrentInfo torrentInfo {*(completeTorrentInfo ? completeTorrentInfo : torrent->nativeHandle().torrent_file())}; #else const TorrentInfo torrentInfo {*torrent->nativeHandle().torrent_file()}; #endif