]> git.eshelyaron.com Git - emacs.git/commitdiff
Permit executing programs with >1024 args on Android
authorPo Lu <luangruo@yahoo.com>
Wed, 5 Mar 2025 06:32:34 +0000 (14:32 +0800)
committerEshel Yaron <me@eshelyaron.com>
Sun, 9 Mar 2025 07:05:26 +0000 (08:05 +0100)
* src/android.c (MAXARGS): Delete enumerator.
(android_rewrite_spawn_argv): Don't mandate a maximum number of
arguments.

(cherry picked from commit 3d7cc22d25cef88464f18e5cc69eb696f8c8a4a2)

src/android.c

index b7d68def4671529ec5de3a50a0f0f346dbcd4d13..6a6996a438b92f872abb20052663a1d30ae3e213 100644 (file)
@@ -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;
 }
 
 \f