Skip to content

Commit 52bb189

Browse files
23rdjohn-preston
authored andcommitted
Fixed possible crash when paste invalid proxy link to proxy box.
1 parent 8ff6f9a commit 52bb189

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

Telegram/SourceFiles/boxes/connection_box.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ void AddProxyFromClipboard(
111111
QGuiApplication::clipboard()->text());
112112
const auto isSingle = maybeUrls.size() == 1;
113113

114+
enum class Result {
115+
Success,
116+
Failed,
117+
Unsupported,
118+
Invalid,
119+
};
120+
114121
const auto proceedUrl = [=](const auto &local) {
115122
const auto command = base::StringViewMid(
116123
local,
@@ -146,6 +153,11 @@ void AddProxyFromClipboard(
146153
match->captured(1),
147154
qthelp::UrlParamNameTransform::ToLower);
148155
const auto proxy = ProxyDataFromFields(type, fields);
156+
if (!proxy) {
157+
return (proxy.status() == ProxyData::Status::Unsupported)
158+
? Result::Unsupported
159+
: Result::Invalid;
160+
}
149161
const auto contains = controller->contains(proxy);
150162
const auto toast = (contains
151163
? tr::lng_proxy_add_from_clipboard_existing_toast
@@ -158,19 +170,29 @@ void AddProxyFromClipboard(
158170
}
159171
break;
160172
}
161-
return true;
173+
return Result::Success;
162174
}
163-
return false;
175+
return Result::Failed;
164176
};
165177

166-
auto success = false;
178+
auto success = Result::Failed;
167179
for (const auto &maybeUrl : maybeUrls) {
168-
success |= proceedUrl(Core::TryConvertUrlToLocal(maybeUrl));
180+
const auto result = proceedUrl(Core::TryConvertUrlToLocal(maybeUrl));
181+
if (success != Result::Success) {
182+
success = result;
183+
}
169184
}
170185

171-
if (!success) {
172-
show->showToast(
173-
tr::lng_proxy_add_from_clipboard_failed_toast(tr::now));
186+
if (success != Result::Success) {
187+
if (success == Result::Failed) {
188+
show->showToast(
189+
tr::lng_proxy_add_from_clipboard_failed_toast(tr::now));
190+
} else {
191+
show->showBox(Ui::MakeInformBox(
192+
(success == Result::Unsupported
193+
? tr::lng_proxy_unsupported(tr::now)
194+
: tr::lng_proxy_invalid(tr::now))));
195+
}
174196
}
175197
}
176198

0 commit comments

Comments
 (0)