Skip to content

Commit

Permalink
Ignore invalid URL for text drag&drop
Browse files Browse the repository at this point in the history
  • Loading branch information
black-sliver committed Aug 29, 2024
1 parent 2a00174 commit 53ad682
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/http/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string>
#include <iostream>
#include <functional>
#include <string.h>
#include <cstring>
#include <list>
#include <set>
#include <map>
Expand Down Expand Up @@ -219,10 +219,21 @@ class HTTP {
return true;
}

static bool is_uri(const std::string& uri)
{
std::string proto, host, port, path;
return parse_uri(uri, proto, host, port, path);
}

static bool parse_uri(const std::string& uri, std::string& proto, std::string& host, std::string& port, std::string& path)
{
auto allowed = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=%";
for (const auto c: uri)
if (!strchr(allowed, c))
return false;
std::string::size_type pos = uri.find("://");
if (pos == uri.npos) return false;
if (pos == uri.npos)
return false;
proto = uri.substr(0, pos);
std::string::size_type pos2 = uri.find("/", pos+3);
std::string::size_type pos3 = uri.find(":", pos+3);
Expand Down
7 changes: 6 additions & 1 deletion src/poptracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,13 @@ bool PopTracker::start()
}
} else if (type == Ui::DropType::TEXT && strncasecmp(data.c_str(), "https://", 8)==0 && strcasecmp(data.c_str()+data.length()-4, ".zip") == 0) {
// ask user to download and "install" pack
if (!HTTP::is_uri(data)) {
fprintf(stderr, "Dropped URI is not valid!\n");
return;
}
const char* zipname = strrchr(data.c_str() + 8, '/');
if (!zipname) return;
if (!zipname)
return;
zipname += 1;
std::string msg = "Download pack from " + data + " ?";
if (Dlg::MsgBox("PopTracker", msg, Dlg::Buttons::YesNo, Dlg::Icon::Question) != Dlg::Result::Yes)
Expand Down

0 comments on commit 53ad682

Please sign in to comment.