mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-01 02:25:40 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7898360e3 |
No files matched your search
@@ -4130,13 +4130,20 @@ EXPORT ssize_t read(int fd, void *buf, size_t count) {
|
||||
return read_input(fd, buf, count);
|
||||
}
|
||||
|
||||
// glibc's fortify failure; bionic (DroidDeck-Bionic preloads this library into its Wine processes) has no
|
||||
// __chk_fail, and a library naming it there cannot be loaded, which stops every Wine program from starting.
|
||||
#if defined(__BIONIC__)
|
||||
[[noreturn]] static void fakeinput_chk_fail(void) { abort(); }
|
||||
#else
|
||||
extern "C" [[noreturn]] void __chk_fail(void);
|
||||
[[noreturn]] static void fakeinput_chk_fail(void) { __chk_fail(); }
|
||||
#endif
|
||||
|
||||
/* Programs built with _FORTIFY_SOURCE (Flatpak runtimes among them) call these instead of read, poll
|
||||
* and ppoll, and glibc's versions go straight to the kernel. */
|
||||
EXPORT ssize_t __read_chk(int fd, void *buf, size_t count, size_t buflen) {
|
||||
static auto next_read_chk = reinterpret_cast<ssize_t (*)(int, void *, size_t, size_t)>(dlsym(RTLD_NEXT, "__read_chk"));
|
||||
if (count > buflen) __chk_fail();
|
||||
if (count > buflen) fakeinput_chk_fail();
|
||||
if (next_read_chk && !is_fake_input_fd(fd)) return next_read_chk(fd, buf, count, buflen);
|
||||
return read_input(fd, buf, count);
|
||||
}
|
||||
@@ -4390,13 +4397,13 @@ EXPORT int ppoll(struct pollfd *fds, nfds_t nfds,
|
||||
}
|
||||
|
||||
EXPORT int __poll_chk(struct pollfd *fds, nfds_t nfds, int timeout, size_t fdslen) {
|
||||
if (fdslen / sizeof(*fds) < nfds) __chk_fail();
|
||||
if (fdslen / sizeof(*fds) < nfds) fakeinput_chk_fail();
|
||||
return poll(fds, nfds, timeout);
|
||||
}
|
||||
|
||||
EXPORT int __ppoll_chk(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
|
||||
const sigset_t *sigmask, size_t fdslen) {
|
||||
if (fdslen / sizeof(*fds) < nfds) __chk_fail();
|
||||
if (fdslen / sizeof(*fds) < nfds) fakeinput_chk_fail();
|
||||
return ppoll(fds, nfds, timeout, sigmask);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
from pathlib import Path
|
||||
import re
|
||||
import unittest
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[2] / "app/src/main/cpp/fakeinput_steam.cpp"
|
||||
|
||||
|
||||
def code_only(text):
|
||||
"""The source without its comments and string literals."""
|
||||
text = re.sub(r"/\*.*?\*/", " ", text, flags=re.S)
|
||||
text = re.sub(r"//[^\n]*", " ", text)
|
||||
return re.sub(r'"(?:\\.|[^"\\\n])*"', '""', text)
|
||||
|
||||
|
||||
class FakeinputBionicTest(unittest.TestCase):
|
||||
# DroidDeck-Bionic preloads this library into its Wine processes (tools/bionic-runtime/build.sh). bionic
|
||||
# exports no __chk_fail: a library that names it there cannot be loaded, so no Wine program starts
|
||||
# ("cannot locate symbol "__chk_fail"").
|
||||
def test_glibcs_fortify_failure_is_named_only_off_bionic(self):
|
||||
code = code_only(SOURCE.read_text())
|
||||
guarded = re.compile(r"#if defined\(__BIONIC__\)\n(?P<bionic>.*?)#else\n(?P<glibc>.*?)#endif\n", re.S)
|
||||
blocks = [m for m in guarded.finditer(code) if "__chk_fail" in m.group("glibc")]
|
||||
self.assertTrue(blocks, "the glibc-only __chk_fail is behind #if defined(__BIONIC__) ... #else")
|
||||
for block in blocks:
|
||||
self.assertNotIn("__chk_fail", block.group("bionic"))
|
||||
self.assertNotIn("__chk_fail", guarded.sub("", code))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user