aboutsummaryrefslogtreecommitdiffstats
path: root/src/android.c
diff options
context:
space:
mode:
authorPo Lu2025-03-05 14:32:34 +0800
committerPo Lu2025-03-05 15:00:14 +0800
commit3d7cc22d25cef88464f18e5cc69eb696f8c8a4a2 (patch)
tree9a6e767c2d322e90006b9a2ebc80b9634c5f51c4 /src/android.c
parent336cc32f2aa83a06dbbde42463a99e2f5c94f8ff (diff)
downloademacs-3d7cc22d25cef88464f18e5cc69eb696f8c8a4a2.tar.gz
emacs-3d7cc22d25cef88464f18e5cc69eb696f8c8a4a2.zip
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.
Diffstat (limited to 'src/android.c')
-rw-r--r--src/android.c39
1 files changed, 21 insertions, 18 deletions
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)
7389 application data directory to manually load executables and replace 7389 application data directory to manually load executables and replace
7390 the `execve' system call. */ 7390 the `execve' system call. */
7391 7391
7392enum
7393 {
7394 /* Maximum number of arguments available. */
7395 MAXARGS = 1024,
7396 };
7397
7398/* Rewrite the command line given in *ARGV to utilize the `exec1' 7392/* Rewrite the command line given in *ARGV to utilize the `exec1'
7399 bootstrap binary if necessary. 7393 bootstrap binary if necessary.
7400 7394
@@ -7406,9 +7400,11 @@ enum
7406int 7400int
7407android_rewrite_spawn_argv (const char ***argv) 7401android_rewrite_spawn_argv (const char ***argv)
7408{ 7402{
7409 static const char *new_args[MAXARGS]; 7403 static const char **new_args;
7410 static char exec1_name[PATH_MAX], loader_name[PATH_MAX]; 7404 static size_t n_new_args;
7405 static char exec1_name[PATH_MAX + 1], loader_name[PATH_MAX + 1];
7411 size_t i, nargs; 7406 size_t i, nargs;
7407 int n;
7412 7408
7413 /* This isn't required on Android 9 or earlier. */ 7409 /* This isn't required on Android 9 or earlier. */
7414 7410
@@ -7428,22 +7424,25 @@ android_rewrite_spawn_argv (const char ***argv)
7428 while ((*argv)[nargs]) 7424 while ((*argv)[nargs])
7429 ++nargs; 7425 ++nargs;
7430 7426
7431 /* nargs now holds the number of arguments in argv. If it's larger 7427 /* Allocate a buffer in which to save the rewritten argument
7432 than MAXARGS, return failure. */ 7428 array. */
7433 7429 if (n_new_args != nargs)
7434 if (nargs + 2 > MAXARGS)
7435 { 7430 {
7436 errno = E2BIG; 7431 new_args = xrealloc (new_args, sizeof *new_args * (nargs + 3));
7437 return 1; 7432 n_new_args = nargs + 2;
7438 } 7433 }
7439 7434
7440 /* Fill in the name of `libexec1.so'. */ 7435 /* Fill in the name of `libexec1.so'. */
7441 snprintf (exec1_name, PATH_MAX, "%s/libexec1.so", 7436 n = snprintf (exec1_name, PATH_MAX + 1, "%s/libexec1.so",
7442 android_lib_dir); 7437 android_lib_dir);
7438 if (n >= PATH_MAX)
7439 goto name_too_long;
7443 7440
7444 /* And libloader.so. */ 7441 /* And libloader.so. */
7445 snprintf (loader_name, PATH_MAX, "%s/libloader.so", 7442 n = snprintf (loader_name, PATH_MAX + 1, "%s/libloader.so",
7446 android_lib_dir); 7443 android_lib_dir);
7444 if (n >= PATH_MAX)
7445 goto name_too_long;
7447 7446
7448 /* Now fill in the first two arguments. */ 7447 /* Now fill in the first two arguments. */
7449 new_args[0] = exec1_name; 7448 new_args[0] = exec1_name;
@@ -7458,6 +7457,10 @@ android_rewrite_spawn_argv (const char ***argv)
7458 7457
7459 /* Return success. */ 7458 /* Return success. */
7460 return 0; 7459 return 0;
7460
7461 name_too_long:
7462 errno = ENAMETOOLONG;
7463 return 0;
7461} 7464}
7462 7465
7463 7466