preempt out-of-bounds

master
bqv 3 years ago
parent 1187a0a21e
commit 2bb69b68ff
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -1243,13 +1243,15 @@ int channel__send_message(struct t_account *account, struct t_channel *channel,
{ {
const std::string_view prefix = "content-type: "; const std::string_view prefix = "content-type: ";
std::istringstream ss(out ? out : ""); std::istringstream ss(out ? out : "");
std::string line; std::string line, mime;
while (std::getline(ss, line)) { while (std::getline(ss, line)) {
std::transform(line.begin(), line.end(), line.begin(), std::transform(line.begin(), line.end(), line.begin(),
[](char c) -> char { return std::tolower(c); }); [](char c) -> char { return std::tolower(c); });
if (line.starts_with(prefix)) break; if (line.starts_with(prefix)) {
mime = line.substr(prefix.size());
break;
}
} }
std::string mime = line.substr(prefix.size());
if (mime.starts_with("image") || mime.starts_with("video")) if (mime.starts_with("image") || mime.starts_with("video"))
{ {
weechat_printf_date_tags(task->channel->buffer, 0, weechat_printf_date_tags(task->channel->buffer, 0,
@ -1259,9 +1261,14 @@ int channel__send_message(struct t_account *account, struct t_channel *channel,
task->to, task->body, { task->url }); task->to, task->body, { task->url });
} }
else else
{
weechat_printf_date_tags(task->channel->buffer, 0,
"notify_none,no_log", "[curl]\t%s%s",
weechat_color("red"), err);
channel__send_message(task->account, task->channel, channel__send_message(task->account, task->channel,
task->to, task->body); task->to, task->body);
} }
}
else else
{ {
channel__send_message(task->account, task->channel, channel__send_message(task->account, task->channel,

Loading…
Cancel
Save