mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
Diagnostic: check environment strings across exec
This commit is contained in:
1 parent
22484faef4
commit
046f02368f
1 file changed
+62
-3
@@ -1,3 +1,33 @@
|
||||
diff --git a/Source/Tools/FEXInterpreter/FEXInterpreter.cpp b/Source/Tools/FEXInterpreter/FEXInterpreter.cpp
|
||||
index 79f47aa..3358491 100644
|
||||
--- a/Source/Tools/FEXInterpreter/FEXInterpreter.cpp
|
||||
+++ b/Source/Tools/FEXInterpreter/FEXInterpreter.cpp
|
||||
@@ -6,6 +6,7 @@ desc: Glues the ELF loader, FEXCore and LinuxSyscalls to launch an elf under fex
|
||||
$end_info$
|
||||
*/
|
||||
|
||||
+#include <cstdio>
|
||||
#include "Common/ArgumentLoader.h"
|
||||
#include "Common/FEXServerClient.h"
|
||||
#include "Common/Config.h"
|
||||
@@ -384,6 +385,17 @@ static int StealFEXFDFromEnv(const char* Env) {
|
||||
}
|
||||
|
||||
int main(int argc, char** argv, char** const envp) {
|
||||
+ {
|
||||
+ long N = 0, Bad = -1;
|
||||
+ for (; envp[N]; ++N) {
|
||||
+ if (Bad < 0) {
|
||||
+ for (const unsigned char* C = reinterpret_cast<const unsigned char*>(envp[N]); *C; ++C) {
|
||||
+ if (*C < 0x20 || *C > 0x7e) { Bad = N; break; }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ ::dprintf(2, "DDENV %d main n=%ld bad=%ld envp=%p sp~%p\n", ::getpid(), N, Bad, (void*)envp, (void*)&N);
|
||||
+ }
|
||||
auto SBRKPointer = FEX::SBRKAllocations::DisableSBRKAllocations();
|
||||
FEXCore::Allocator::GLIBCScopedFault GLIBFaultScope;
|
||||
|
||||
diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp
|
||||
index 62acdb0..53a7b44 100644
|
||||
--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp
|
||||
@@ -123,17 +153,30 @@ index e8723e8..a3cc742 100644
|
||||
// Call back in to the previous handler
|
||||
if (Handler.OldAction.sa_flags & SA_SIGINFO) {
|
||||
diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp
|
||||
index 078faed..a866d13 100644
|
||||
index 078faed..531500d 100644
|
||||
--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp
|
||||
+++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp
|
||||
@@ -199,7 +199,15 @@ static fextl::string GetShebangInterpFilename(const fextl::string& Filename) {
|
||||
@@ -199,7 +199,28 @@ static fextl::string GetShebangInterpFilename(const fextl::string& Filename) {
|
||||
return Interp;
|
||||
}
|
||||
|
||||
+static uint64_t ExecveHandlerImpl(FEXCore::Core::CpuStateFrame* Frame, const char* pathname, char* const* argv, char* const* envp, ExecveAtArgs Args);
|
||||
+static void DDCheckEnv(const char* Tag, char* const* E) {
|
||||
+ if (!E) { ::dprintf(2, "DDENV %d %s null\n", ::getpid(), Tag); return; }
|
||||
+ long N = 0, Bad = -1;
|
||||
+ for (; E[N]; ++N) {
|
||||
+ if (Bad < 0) {
|
||||
+ for (const unsigned char* C = reinterpret_cast<const unsigned char*>(E[N]); *C; ++C) {
|
||||
+ if (*C < 0x20 || *C > 0x7e) { Bad = N; break; }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ ::dprintf(2, "DDENV %d %s n=%ld bad=%ld envp=%p e0=%p\n", ::getpid(), Tag, N, Bad, (void*)E, N ? (void*)E[0] : nullptr);
|
||||
+}
|
||||
uint64_t ExecveHandler(FEXCore::Core::CpuStateFrame* Frame, const char* pathname, char* const* argv, char* const* envp, ExecveAtArgs Args) {
|
||||
+ ::dprintf(2, "DDPT %d execve path=[%s] dirfd=%d flags=%#x a0=[%s] a1=[%s] a2=[%s] a3=[%s]\n", ::getpid(), pathname, Args.dirfd, Args.flags,
|
||||
+ argv && argv[0] ? argv[0] : "", argv && argv[0] && argv[1] ? argv[1] : "", argv && argv[0] && argv[1] && argv[2] ? argv[2] : "", argv && argv[0] && argv[1] && argv[2] && argv[3] ? argv[3] : "");
|
||||
+ DDCheckEnv("guest", envp);
|
||||
+ uint64_t R = ExecveHandlerImpl(Frame, pathname, argv, envp, Args);
|
||||
+ ::dprintf(2, "DDPT %d execve result=%ld\n", ::getpid(), (long)R);
|
||||
+ return R;
|
||||
@@ -142,7 +185,23 @@ index 078faed..a866d13 100644
|
||||
auto SyscallHandler = FEX::HLE::_SyscallHandler;
|
||||
Frame->Thread->CTX->FlushAndCloseCodeMap();
|
||||
|
||||
@@ -903,6 +911,10 @@ void SyscallHandler::HandleSyscallImpl(FEXCore::Core::CpuStateFrame* Frame, uint
|
||||
@@ -417,6 +438,7 @@ uint64_t ExecveHandler(FEXCore::Core::CpuStateFrame* Frame, const char* pathname
|
||||
}
|
||||
|
||||
if (IsBinfmtCompatible || IsOtherELF || IsForeignShebang) {
|
||||
+ DDCheckEnv("host-direct", EnvpPtr);
|
||||
Result = ::syscall(SYS_execveat, Args.dirfd, Filename.c_str(), argv, EnvpPtr, Args.flags);
|
||||
CloseSeccompFD();
|
||||
CloseFDExecFD();
|
||||
@@ -465,6 +487,7 @@ uint64_t ExecveHandler(FEXCore::Core::CpuStateFrame* Frame, const char* pathname
|
||||
ExecveArgs.emplace_back(nullptr);
|
||||
}
|
||||
|
||||
+ DDCheckEnv("host-loader", EnvpPtr);
|
||||
Result = ::syscall(SYS_execveat, Args.dirfd, "/proc/self/exe", const_cast<char* const*>(ExecveArgs.data()), EnvpPtr, Args.flags);
|
||||
CloseSeccompFD();
|
||||
CloseFDExecFD();
|
||||
@@ -903,6 +926,10 @@ void SyscallHandler::HandleSyscallImpl(FEXCore::Core::CpuStateFrame* Frame, uint
|
||||
if constexpr (Is64Bit) {
|
||||
FEX::HLE::GuestHighMemory::TranslateSyscallArguments(SyscallNum, &A[1], 6);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user