ndk_patches: Update android_setup_pwd() to avoid allocating memory, and check that ~/.termux/shell points att executable
This commit is contained in:
parent
26d0484d19
commit
b57fc0bbb3
@ -1,9 +1,19 @@
|
|||||||
diff -u -r /home/fornwall/lib/android-ndk/platforms/android-19/arch-arm/usr/include/pwd.h ./usr/include/pwd.h
|
diff -u -r /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/include/pwd.h ./usr/include/pwd.h
|
||||||
--- /home/fornwall/lib/android-ndk/platforms/android-19/arch-arm/usr/include/pwd.h 2012-08-21 07:23:12.000000000 +0200
|
--- /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/include/pwd.h 2014-10-14 22:53:49.000000000 -0400
|
||||||
+++ ./usr/include/pwd.h 2014-07-06 04:39:02.731221101 +0200
|
+++ ./usr/include/pwd.h 2015-07-15 09:42:32.974621965 -0400
|
||||||
@@ -114,6 +114,43 @@
|
@@ -65,6 +65,9 @@
|
||||||
struct passwd* getpwnam(const char*);
|
#include <sys/cdefs.h>
|
||||||
struct passwd* getpwuid(uid_t);
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
+/* For access(): */
|
||||||
|
+#include <unistd.h>
|
||||||
|
+
|
||||||
|
#define _PATH_PASSWD "/etc/passwd"
|
||||||
|
#define _PATH_MASTERPASSWD "/etc/master.passwd"
|
||||||
|
#define _PATH_MASTERPASSWD_LOCK "/etc/ptmp"
|
||||||
|
@@ -119,6 +122,39 @@
|
||||||
|
int getpwnam_r(const char*, struct passwd*, char*, size_t, struct passwd**);
|
||||||
|
int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**);
|
||||||
|
|
||||||
+extern char *realpath(const char *path, char *resolved_path);
|
+extern char *realpath(const char *path, char *resolved_path);
|
||||||
+extern void free(void *ptr);
|
+extern void free(void *ptr);
|
||||||
@ -11,17 +21,13 @@ diff -u -r /home/fornwall/lib/android-ndk/platforms/android-19/arch-arm/usr/incl
|
|||||||
+extern size_t strlen(const char *s);
|
+extern size_t strlen(const char *s);
|
||||||
+
|
+
|
||||||
+static void android_setup_pwd(struct passwd* pw) {
|
+static void android_setup_pwd(struct passwd* pw) {
|
||||||
+ static char realpath_buffer[255];
|
+ static char realpath_buffer[4096/*PATH_MAX*/];
|
||||||
+ size_t allocated_realpath_len;
|
+ char* result = realpath("@TERMUX_HOME@/.termux/shell", realpath_buffer);
|
||||||
+ char* allocated_realpath = realpath("@TERMUX_HOME@/.termux/shell", NULL);
|
+ if (result == NULL || access(realpath_buffer, X_OK) == -1) {
|
||||||
+ if (allocated_realpath == NULL || (allocated_realpath_len = strlen(allocated_realpath)) >= sizeof(realpath_buffer)) {
|
|
||||||
+ pw->pw_shell = "@TERMUX_PREFIX@/bin/ash";
|
+ pw->pw_shell = "@TERMUX_PREFIX@/bin/ash";
|
||||||
+ } else {
|
+ } else {
|
||||||
+ memcpy(realpath_buffer, allocated_realpath, allocated_realpath_len);
|
|
||||||
+ realpath_buffer[allocated_realpath_len] = 0;
|
|
||||||
+ pw->pw_shell = realpath_buffer;
|
+ pw->pw_shell = realpath_buffer;
|
||||||
+ }
|
+ }
|
||||||
+ free(allocated_realpath);
|
|
||||||
+ pw->pw_dir = "@TERMUX_HOME@";
|
+ pw->pw_dir = "@TERMUX_HOME@";
|
||||||
+ pw->pw_passwd = "*";
|
+ pw->pw_passwd = "*";
|
||||||
+}
|
+}
|
||||||
@ -43,5 +49,5 @@ diff -u -r /home/fornwall/lib/android-ndk/platforms/android-19/arch-arm/usr/incl
|
|||||||
+#define getpwnam android_polyfill_getpwnam
|
+#define getpwnam android_polyfill_getpwnam
|
||||||
+#define getpwuid android_polyfill_getpwuid
|
+#define getpwuid android_polyfill_getpwuid
|
||||||
void endpwent(void);
|
void endpwent(void);
|
||||||
|
struct passwd* getpwent(void);
|
||||||
#if 0 /* MISSING FROM BIONIC */
|
int setpwent(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user