mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 20:10:13 +02:00
Prevent nuking socket base dir if not temporary
If `yabridge-host.exe` were somehow to be run with a socket base directory that's not inside of `$XDG_RUNTIME_DIR`/`/tmp`, then we'll now warn instead of removing that directory. This should not be necessary, but in case someone wants to write a wrapper around `yabridge-host.exe.so` us using a custom `$WINELOADER` then this could save a lot of headaches.
This commit is contained in:
@@ -98,6 +98,10 @@ TODO: Add an updated screenshot with some fancy VST3-only plugins to the readme
|
||||
and up. The build process now detect which version of Wine is used to build
|
||||
with, and it then applies the change conditionally to be able to support
|
||||
building with both older and newer versions of Wine.
|
||||
- `yabridge-host.exe` will no longer remove the socket directories if they're
|
||||
outside of a temporary directory. This could otherwise cause a very unpleasant
|
||||
surprise if someone was passing random arguments to it when for instancing
|
||||
trying to write a wrapper around `yabridge-host.exe`.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
|
||||
#include <bitsery/adapter/buffer.h>
|
||||
@@ -32,6 +33,7 @@
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "../logging/common.h"
|
||||
#include "../utils.h"
|
||||
|
||||
template <typename B>
|
||||
using OutputAdapter = bitsery::OutputBufferAdapter<B>;
|
||||
@@ -217,12 +219,22 @@ class Sockets {
|
||||
*/
|
||||
virtual ~Sockets() {
|
||||
try {
|
||||
// TODO: Check whether `base_dir` is actually in `/tmp` or
|
||||
// `$XDG_RUNTIME_DIR`, don't do anything if it's not. Someone
|
||||
// has deleted their entire home directory while messing with
|
||||
// `yabridge-host.exe`'s arguments, and that sounds like
|
||||
// something that would be easy to prevent.
|
||||
boost::filesystem::remove_all(base_dir);
|
||||
// NOTE: Because someone has wiped their home directory in the past
|
||||
// by manually modifying the socket base directory argument
|
||||
// for `yabridge-host.exe` to point to their home directory
|
||||
// there's now a safeguard against that very thing. Hopefully
|
||||
// this should never be needed, but if it is, then I'm glad
|
||||
// we'll have it!
|
||||
const boost::filesystem::path temp_dir = get_temporary_directory();
|
||||
if (base_dir.string().starts_with(temp_dir.string())) {
|
||||
boost::filesystem::remove_all(base_dir);
|
||||
} else {
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "WARNING: Unexpected socket base directory found, "
|
||||
"not removing '"
|
||||
<< base_dir.string() << "'" << std::endl;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
} catch (const boost::filesystem::filesystem_error&) {
|
||||
// There should not be any filesystem errors since only one side
|
||||
// removes the files, but if we somehow can't delete the file
|
||||
|
||||
Reference in New Issue
Block a user