termux-packages/packages/bash/verify-prefix.patch.txt

34 lines
1.3 KiB
Plaintext

Patch to encourage third-parties to compile own packages instead
of using hosted by Termux.
diff -uNr bash-5.0/shell.c bash-5.0.mod/shell.c
--- bash-5.0/shell.c 2018-12-06 18:28:21.000000000 +0200
+++ bash-5.0.mod/shell.c 2020-09-27 23:27:30.347678058 +0300
@@ -384,6 +384,26 @@
USE_VAR(saverst);
#endif
+ // Reversed /data/data/com.termux/files/usr. Prevents patching with 'sed'
+ // by using equal-size prefixes.
+ const char termux_prefix_obfs[] = "rsu/selif/xumret.moc/atad/atad/";
+ char termux_prefix[sizeof(termux_prefix_obfs)/sizeof(char)] = {0};
+ int termux_prefix_len = sizeof(termux_prefix_obfs)/sizeof(char) - 1;
+
+ // Decode.
+ for (int i=0; i<termux_prefix_len; i++) {
+ termux_prefix[termux_prefix_len - 1 - i] = termux_prefix_obfs[i];
+ }
+
+ // Stub to verify that we can access @TERMUX_PREFIX@ and it is a directory.
+ // If checks failed, then we probably running in incompatible environment.
+ // In this case warn user and exit with status 1.
+ if (access(termux_prefix, R_OK) != 0) {
+ fprintf(stderr, "Warning: aborting execution because %s is not accessible.\n", termux_prefix);
+ fprintf(stderr, "Please make sure that program is compiled with correct prefix.\n");
+ return 1;
+ }
+
/* Catch early SIGINTs. */
code = setjmp_nosigs (top_level);
if (code)