bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* perror: Fix "perror clobbers strerror's buffer" problem on Android
@ 2023-01-11 19:45 Bruno Haible
  0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2023-01-11 19:45 UTC (permalink / raw)
  To: bug-gnulib

In a testdir on Android 11, I see this test failure:

FAIL: test-perror2
==================

../../gltests/test-perror2.c:82: assertion 'STREQ (msg4, str4)' failed
Aborted
FAIL test-perror2 (exit status: 134)

When I print the values of msg4 and str4, I get:
msg4="Unknown error -5"
str4="Unknown error 1729576"

This means that perror() clobbers the strerror() buffer, at least in the
case where errno < 0. But according to the Gnulib documentation, this
should not happen.

This patch fixes it. (I could have written an Autoconf test here, but
it would need a cross-compilation guess anyway.)


2023-01-11  Bruno Haible  <bruno@clisp.org>

	perror: Fix "perror clobbers strerror's buffer" problem on Android.
	* m4/perror.m4 (gl_FUNC_PERROR): Set REPLACE_PERROR to 1 on Android.
	* doc/posix-functions/perror.texi: Mention the Android problem.

diff --git a/doc/posix-functions/perror.texi b/doc/posix-functions/perror.texi
index bbc2925d60..4c4a7e36dd 100644
--- a/doc/posix-functions/perror.texi
+++ b/doc/posix-functions/perror.texi
@@ -18,7 +18,7 @@ requires that the message declare it as a success, on some platforms:
 FreeBSD 8.2, OpenBSD 4.7, macOS 11.1.
 @item
 This function clobbers the @code{strerror} buffer on some platforms:
-Cygwin 1.7.9.
+Cygwin 1.7.9, Android 11.
 @item
 This function fails to print a useful a string for out-of-range integers on
 some platforms:
diff --git a/m4/perror.m4 b/m4/perror.m4
index 3ff029de76..2545cb3487 100644
--- a/m4/perror.m4
+++ b/m4/perror.m4
@@ -1,4 +1,4 @@
-# perror.m4 serial 10
+# perror.m4 serial 11
 dnl Copyright (C) 2008-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -10,7 +10,7 @@ AC_DEFUN([gl_FUNC_PERROR],
   AC_REQUIRE([gl_HEADER_ERRNO_H])
   AC_REQUIRE([gl_FUNC_STRERROR_R])
   AC_REQUIRE([gl_FUNC_STRERROR_0])
-  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([AC_CANONICAL_HOST])
   dnl We intentionally do not check for the broader REPLACE_STRERROR_R,
   dnl since on glibc systems, strerror_r is replaced only for signature
   dnl issues, and perror is just fine.  Rather, we only want to
@@ -68,4 +68,9 @@ AC_DEFUN([gl_FUNC_PERROR],
       REPLACE_PERROR=1
       ;;
   esac
+  dnl Does perror clobber the strerror buffer?
+  case "$host_os" in
+                     # Yes on Android 11.
+    linux*-android*) REPLACE_PERROR=1 ;;
+  esac
 ])





^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-11 19:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-11 19:45 perror: Fix "perror clobbers strerror's buffer" problem on Android Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).