mirror of
https://github.com/hyprwm/xdg-desktop-portal-hyprland.git
synced 2024-11-23 14:55:57 +01:00
core: sanitize environment and paths from user data
cherry-picked from the fix for #242
This commit is contained in:
parent
57ab6df950
commit
84a9cdca3a
6 changed files with 33 additions and 22 deletions
|
@ -3,8 +3,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
enum eLogLevel
|
enum eLogLevel {
|
||||||
{
|
|
||||||
TRACE = 0,
|
TRACE = 0,
|
||||||
INFO,
|
INFO,
|
||||||
LOG,
|
LOG,
|
||||||
|
@ -17,7 +16,7 @@ enum eLogLevel
|
||||||
if (!(expr)) { \
|
if (!(expr)) { \
|
||||||
Debug::log(CRIT, "\n==========================================================================================\nASSERTION FAILED! \n\n{}\n\nat: line {} in {}", \
|
Debug::log(CRIT, "\n==========================================================================================\nASSERTION FAILED! \n\n{}\n\nat: line {} in {}", \
|
||||||
std::format(reason, ##__VA_ARGS__), __LINE__, \
|
std::format(reason, ##__VA_ARGS__), __LINE__, \
|
||||||
([]() constexpr->std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })().c_str()); \
|
([]() constexpr -> std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })().c_str()); \
|
||||||
printf("Assertion failed! See the log in /tmp/hypr/hyprland.log for more info."); \
|
printf("Assertion failed! See the log in /tmp/hypr/hyprland.log for more info."); \
|
||||||
*((int*)nullptr) = 1; /* so that we crash and get a coredump */ \
|
*((int*)nullptr) = 1; /* so that we crash and get a coredump */ \
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
|
std::string lastScreenshot;
|
||||||
|
|
||||||
void pickHyprPicker(sdbus::MethodCall& call) {
|
void pickHyprPicker(sdbus::MethodCall& call) {
|
||||||
const std::string HYPRPICKER_CMD = "hyprpicker --format=rgb --no-fancy";
|
const std::string HYPRPICKER_CMD = "hyprpicker --format=rgb --no-fancy";
|
||||||
std::string rgbColor = execAndGet(HYPRPICKER_CMD.c_str());
|
std::string rgbColor = execAndGet(HYPRPICKER_CMD.c_str());
|
||||||
|
@ -133,11 +135,15 @@ void CScreenshotPortal::onScreenshot(sdbus::MethodCall& call) {
|
||||||
bool isInteractive = options.count("interactive") && options["interactive"].get<bool>() && inShellPath("slurp");
|
bool isInteractive = options.count("interactive") && options["interactive"].get<bool>() && inShellPath("slurp");
|
||||||
|
|
||||||
// make screenshot
|
// make screenshot
|
||||||
const std::string HYPR_DIR = "/tmp/hypr/";
|
|
||||||
const std::string SNAP_FILE = "xdph_screenshot.png";
|
const auto RUNTIME_DIR = getenv("XDG_RUNTIME_DIR");
|
||||||
|
srand(time(nullptr));
|
||||||
|
|
||||||
|
const std::string HYPR_DIR = RUNTIME_DIR ? std::string{RUNTIME_DIR} + "/hypr/" : "/tmp/hypr/";
|
||||||
|
const std::string SNAP_FILE = std::format("xdph_screenshot_{:x}.png", rand()); // rand() is good enough
|
||||||
const std::string FILE_PATH = HYPR_DIR + SNAP_FILE;
|
const std::string FILE_PATH = HYPR_DIR + SNAP_FILE;
|
||||||
const std::string SNAP_CMD = "grim " + FILE_PATH;
|
const std::string SNAP_CMD = "grim '" + FILE_PATH + "'";
|
||||||
const std::string SNAP_INTERACTIVE_CMD = "grim -g \"$(slurp)\" " + FILE_PATH;
|
const std::string SNAP_INTERACTIVE_CMD = "grim -g \"$(slurp)\" '" + FILE_PATH + "'";
|
||||||
|
|
||||||
std::unordered_map<std::string, sdbus::Variant> results;
|
std::unordered_map<std::string, sdbus::Variant> results;
|
||||||
results["uri"] = "file://" + FILE_PATH;
|
results["uri"] = "file://" + FILE_PATH;
|
||||||
|
@ -145,6 +151,11 @@ void CScreenshotPortal::onScreenshot(sdbus::MethodCall& call) {
|
||||||
std::filesystem::remove(FILE_PATH);
|
std::filesystem::remove(FILE_PATH);
|
||||||
std::filesystem::create_directory(HYPR_DIR);
|
std::filesystem::create_directory(HYPR_DIR);
|
||||||
|
|
||||||
|
// remove last screenshot. This could cause issues if the app hasn't read the screenshot back yet, but oh well.
|
||||||
|
if (!lastScreenshot.empty())
|
||||||
|
std::filesystem::remove(lastScreenshot);
|
||||||
|
lastScreenshot = FILE_PATH;
|
||||||
|
|
||||||
if (isInteractive)
|
if (isInteractive)
|
||||||
execAndGet(SNAP_INTERACTIVE_CMD.c_str());
|
execAndGet(SNAP_INTERACTIVE_CMD.c_str());
|
||||||
else
|
else
|
||||||
|
|
|
@ -16,7 +16,7 @@ std::string sanitizeNameForWindowList(const std::string& name) {
|
||||||
for (size_t i = 1; i < result.size(); ++i) {
|
for (size_t i = 1; i < result.size(); ++i) {
|
||||||
if (result[i - 1] == '>' && result[i] == ']')
|
if (result[i - 1] == '>' && result[i] == ']')
|
||||||
result[i] = ' ';
|
result[i] = ' ';
|
||||||
if (result[i] == '\"')
|
if (result[i] == '\"' || result[i] == '\'')
|
||||||
result[i] = ' ';
|
result[i] = ' ';
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -43,8 +43,10 @@ SSelectionData promptForScreencopySelection() {
|
||||||
const char* XCURSOR_SIZE = getenv("XCURSOR_SIZE");
|
const char* XCURSOR_SIZE = getenv("XCURSOR_SIZE");
|
||||||
const char* HYPRLAND_INSTANCE_SIGNATURE = getenv("HYPRLAND_INSTANCE_SIGNATURE");
|
const char* HYPRLAND_INSTANCE_SIGNATURE = getenv("HYPRLAND_INSTANCE_SIGNATURE");
|
||||||
|
|
||||||
|
// DANGEROUS: we are sending a list of app IDs and titles via env. Make sure it's in 'singlequotes' to avoid something like $(rm -rf /)
|
||||||
|
// TODO: this is dumb, use a pipe or something.
|
||||||
std::string cmd =
|
std::string cmd =
|
||||||
std::format("WAYLAND_DISPLAY={} QT_QPA_PLATFORM=\"wayland\" XCURSOR_SIZE={} HYPRLAND_INSTANCE_SIGNATURE={} XDPH_WINDOW_SHARING_LIST=\"{}\" hyprland-share-picker 2>&1",
|
std::format("WAYLAND_DISPLAY='{}' QT_QPA_PLATFORM='wayland' XCURSOR_SIZE='{}' HYPRLAND_INSTANCE_SIGNATURE='{}' XDPH_WINDOW_SHARING_LIST='{}' hyprland-share-picker 2>&1",
|
||||||
WAYLAND_DISPLAY ? WAYLAND_DISPLAY : "", XCURSOR_SIZE ? XCURSOR_SIZE : "24", HYPRLAND_INSTANCE_SIGNATURE ? HYPRLAND_INSTANCE_SIGNATURE : "0", buildWindowList());
|
WAYLAND_DISPLAY ? WAYLAND_DISPLAY : "", XCURSOR_SIZE ? XCURSOR_SIZE : "24", HYPRLAND_INSTANCE_SIGNATURE ? HYPRLAND_INSTANCE_SIGNATURE : "0", buildWindowList());
|
||||||
|
|
||||||
const auto RETVAL = execAndGet(cmd.c_str());
|
const auto RETVAL = execAndGet(cmd.c_str());
|
||||||
|
|
|
@ -22,8 +22,7 @@ extern "C" {
|
||||||
#define XDPH_PWR_BUFFERS_MIN 2
|
#define XDPH_PWR_BUFFERS_MIN 2
|
||||||
#define XDPH_PWR_ALIGN 16
|
#define XDPH_PWR_ALIGN 16
|
||||||
|
|
||||||
enum eSelectionType
|
enum eSelectionType {
|
||||||
{
|
|
||||||
TYPE_INVALID = -1,
|
TYPE_INVALID = -1,
|
||||||
TYPE_OUTPUT = 0,
|
TYPE_OUTPUT = 0,
|
||||||
TYPE_WINDOW,
|
TYPE_WINDOW,
|
||||||
|
|
Loading…
Reference in a new issue