From: Po Lu Date: Wed, 5 Mar 2025 06:32:34 +0000 (+0800) Subject: Permit executing programs with >1024 args on Android X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=479e36489f3a9c535278401a141a83e2ed5be1a8;p=emacs.git Permit executing programs with >1024 args on Android * src/android.c (MAXARGS): Delete enumerator. (android_rewrite_spawn_argv): Don't mandate a maximum number of arguments. (cherry picked from commit 3d7cc22d25cef88464f18e5cc69eb696f8c8a4a2) --- diff --git a/src/android.c b/src/android.c index b7d68def467..6a6996a438b 100644 --- a/src/android.c +++ b/src/android.c @@ -7389,12 +7389,6 @@ android_free_cursor (android_cursor cursor) application data directory to manually load executables and replace the `execve' system call. */ -enum - { - /* Maximum number of arguments available. */ - MAXARGS = 1024, - }; - /* Rewrite the command line given in *ARGV to utilize the `exec1' bootstrap binary if necessary. @@ -7406,9 +7400,11 @@ enum int android_rewrite_spawn_argv (const char ***argv) { - static const char *new_args[MAXARGS]; - static char exec1_name[PATH_MAX], loader_name[PATH_MAX]; + static const char **new_args; + static size_t n_new_args; + static char exec1_name[PATH_MAX + 1], loader_name[PATH_MAX + 1]; size_t i, nargs; + int n; /* This isn't required on Android 9 or earlier. */ @@ -7428,22 +7424,25 @@ android_rewrite_spawn_argv (const char ***argv) while ((*argv)[nargs]) ++nargs; - /* nargs now holds the number of arguments in argv. If it's larger - than MAXARGS, return failure. */ - - if (nargs + 2 > MAXARGS) + /* Allocate a buffer in which to save the rewritten argument + array. */ + if (n_new_args != nargs) { - errno = E2BIG; - return 1; + new_args = xrealloc (new_args, sizeof *new_args * (nargs + 3)); + n_new_args = nargs + 2; } /* Fill in the name of `libexec1.so'. */ - snprintf (exec1_name, PATH_MAX, "%s/libexec1.so", - android_lib_dir); + n = snprintf (exec1_name, PATH_MAX + 1, "%s/libexec1.so", + android_lib_dir); + if (n >= PATH_MAX) + goto name_too_long; /* And libloader.so. */ - snprintf (loader_name, PATH_MAX, "%s/libloader.so", - android_lib_dir); + n = snprintf (loader_name, PATH_MAX + 1, "%s/libloader.so", + android_lib_dir); + if (n >= PATH_MAX) + goto name_too_long; /* Now fill in the first two arguments. */ new_args[0] = exec1_name; @@ -7458,6 +7457,10 @@ android_rewrite_spawn_argv (const char ***argv) /* Return success. */ return 0; + + name_too_long: + errno = ENAMETOOLONG; + return 0; }