]> git.eshelyaron.com Git - emacs.git/commitdiff
Enable Gnulib substitute on Android systems with defective strnlen
authorPo Lu <luangruo@yahoo.com>
Fri, 5 Jul 2024 04:09:52 +0000 (12:09 +0800)
committerEshel Yaron <me@eshelyaron.com>
Sun, 7 Jul 2024 13:16:53 +0000 (15:16 +0200)
* configure.ac (AC_FUNC_STRNLEN): Detect a bug where strnlen is
liable to integer overflows if addition of the search limit to
the string would also overflow.

* src/xdisp.c (store_mode_line_string): Remove stopgap measure.

(cherry picked from commit 04d7318efa20cce3aa369fdfd563d8364feb6e78)

configure.ac
src/xdisp.c

index 402e5fdc752cdbf4ec5f9c6ee5df17d3a52e0b4c..15deb1f89aceff99489e2113b90c891499bb027e 100644 (file)
@@ -1611,6 +1611,30 @@ AC_DEFUN([gl_TYPE_OFF64_T],
   [HAVE_OFF64_T=1
    AC_SUBST([HAVE_OFF64_T])])
 
+# `strnlen' cannot accept nlen greater than the size of the object S
+# on Android 2.2 and earlier.
+m4_define([ORIGINAL_AC_FUNC_STRNLEN], m4_defn([AC_FUNC_STRNLEN]))
+AC_DEFUN([AC_FUNC_STRNLEN], [
+AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_CACHE_CHECK([for strnlen capable of accepting large limits],
+  [emacs_cv_func_strnlen_working],
+  [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [[
+  volatile size_t (*strnlen_pointer) (const char *s, size_t) = &strnlen;
+  if ((*strnlen_pointer) ("", -1) != 0)
+    return 1;
+  return 0;
+]])],[emacs_cv_func_strnlen_working=yes],
+     [emacs_cv_func_strnlen_working=no],
+     [# Guess no on Android 21 and earlier, yes elsewhere.
+      AS_IF([test -n "$ANDROID_SDK" && test "$ANDROID_SDK" -lt 22],
+        [emacs_cv_func_strnlen_working=no],
+       [emacs_cv_func_strnlen_working='guessing yes'])])])
+AS_IF([test "$emacs_cv_func_strnlen_working" != "no"],
+  [ORIGINAL_AC_FUNC_STRNLEN],
+  [ac_cv_func_strnlen_working=no
+   AC_LIBOBJ([strnlen])])])
+
 # Initialize gnulib right after choosing the compiler.
 dnl Amongst other things, this sets AR and ARFLAGS.
 gl_EARLY
index 566c4b211d6bb31498738f57dd61a4bb051909c8..8c7e8e5cb43b58bfdcd31b2d9a64172cb2c7ff43 100644 (file)
@@ -28065,18 +28065,7 @@ store_mode_line_string (const char *string, Lisp_Object lisp_string,
 
   if (string != NULL)
     {
-#if defined HAVE_ANDROID && !defined ANDROID_STUBIFY   \
-  && __ANDROID_API__ < 22
-      /* Circumvent a bug in memchr preventing strnlen from returning
-        valid values when a large limit is specified.
-
-         https://issuetracker.google.com/issues/37020957 */
-      if (precision <= 0 || ((uintptr_t) string
-                            > (UINTPTR_MAX - precision)))
-       len = strlen (string);
-      else
-#endif /* HAVE_ANDROID && !ANDROID_STUBIFY && __ANDROID_API__ < 22 */
-       len = strnlen (string, precision <= 0 ? SIZE_MAX : precision);
+      len = strnlen (string, precision <= 0 ? SIZE_MAX : precision);
       lisp_string = make_string (string, len);
       if (NILP (props))
        props = mode_line_string_face_prop;