From 900281eb1c87f27dfac3c54c21df25aac4c62c76 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 11 Mar 2023 19:44:54 -0600 Subject: [PATCH] fix: check tr_ctorSetFoo() return values before adding torrent via RPC (#5202) --- libtransmission/rpcimpl.cc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libtransmission/rpcimpl.cc b/libtransmission/rpcimpl.cc index 1ba8c13bd..77c20bec7 100644 --- a/libtransmission/rpcimpl.cc +++ b/libtransmission/rpcimpl.cc @@ -1688,21 +1688,25 @@ char const* torrentAdd(tr_session* session, tr_variant* args_in, tr_variant* /*a } else { + auto ok = false; + if (std::empty(filename)) { auto const metainfo = tr_base64_decode(metainfo_base64); - tr_ctorSetMetainfo(ctor, std::data(metainfo), std::size(metainfo), nullptr); + ok = tr_ctorSetMetainfo(ctor, std::data(metainfo), std::size(metainfo), nullptr); + } + else if (tr_sys_path_exists(tr_pathbuf{ filename })) + { + ok = tr_ctorSetMetainfoFromFile(ctor, filename); } else { - if (tr_sys_path_exists(tr_pathbuf{ filename })) - { - tr_ctorSetMetainfoFromFile(ctor, filename); - } - else - { - tr_ctorSetMetainfoFromMagnetLink(ctor, filename); - } + ok = tr_ctorSetMetainfoFromMagnetLink(ctor, filename); + } + + if (!ok) + { + return "unrecognized info"; } addTorrentImpl(idle_data, ctor);