Skip to content

Commit

Permalink
@cxx/ClassCns.cxx:execves Reuse Termux LD_PRELOAD
Browse files Browse the repository at this point in the history
  as workaround (for termux-play-store/termux-issues#24
  termux/termux-app#2155
  termux/termux-app#4037 ).

Fixes
```
~/SubStack $ ./a.out
cxx/Macros.hxx: pass
execves(): pass
execvex(): pass
virusAnalysisTestsThrows(): pass
assistantCnsTestsThrows(): /data/data/com.termux/files/usr/bin/sh: 1: wget: Permission denied /data/data/com.termux/files/usr/bin
```
, (to
```
conversationCnsTestsThrows(): --2024-06-15 18:22:01--  https://stackoverflow.com/robots.txt
Resolving stackoverflow.com (stackoverflow.com)... 172.64.155.249, 104.18.32.7
Connecting to stackoverflow.com (stackoverflow.com)|172.64.155.249|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/plain]
Saving to: ‘robots.txt’

robots.txt                                   [ <=>                                                                              ]   1.99K  --.-KB/s    in 0.07s

2024-06-15 18:22:02 (27.4 KB/s) - ‘robots.txt’ saved [2036]

```
, as was)
  • Loading branch information
SwuduSusuwu committed Sep 21, 2024
1 parent f93af74 commit 999ed37
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cxx/ClassCns.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <vector> /* std::vector */
#include <ctype.h> /* size_t */
#ifdef _POSIX_VERSION
#include <stdlib.h> /* getenv */
#include <stdio.h> /* asprintf */
#include <unistd.h> /* execve fork EXIT_FAILURE */
#include <sys/wait.h> /* waitpid */
#endif /* def _POSIX_VERSION */
Expand All @@ -31,6 +33,16 @@ const int execves(const std::vector<const std::string> &argvS, const std::vector
for(auto x = envpSmutable.begin(); envpSmutable.end() != x; ++x) {
envp.push_back(const_cast<char *>(x->c_str()));
}
if(envp.empty()) {
char* ld_preload = getenv("LD_PRELOAD");
if (ld_preload) {
// Keep LD_PRELOAD, necessary for now on the Google Play build of Termux.
char* ld_preload_env;
int allocated_bytes = asprintf(&ld_preload_env, "LD_PRELOAD=%s", ld_preload);
assert(allocated_bytes > 0);
envp.push_back(ld_preload_env);
}
}
envp.push_back(NULL);
execve(argv[0], &argv[0], &envp[0]); /* NORETURN */
exit(EXIT_FAILURE);
Expand Down

0 comments on commit 999ed37

Please sign in to comment.