bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Subject: perror: Fix "perror clobbers strerror's buffer" problem on Android
Date: Wed, 11 Jan 2023 20:45:03 +0100	[thread overview]
Message-ID: <76359641.VQpxGFKSoK@nimes> (raw)

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
 ])





                 reply	other threads:[~2023-01-11 19:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=76359641.VQpxGFKSoK@nimes \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).