]> Savannah Git Hosting - gnulib.git/commitdiff
ptsname_r: Work around ptsname_r bug on NetBSD 10.0.
authorBruno Haible <bruno@clisp.org>
Mon, 8 Apr 2024 23:16:15 +0000 (01:16 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 19 Apr 2024 12:39:53 +0000 (14:39 +0200)
* m4/ptsname_r.m4 (gl_FUNC_PTSNAME_R): On NetBSD, arrange to override
ptsname_r.
* lib/ptsname_r.c (ptsname_r): Add workaround for NetBSD bug.
* doc/glibc-functions/ptsname_r.texi: Mention the NetBSD bug.

ChangeLog
doc/glibc-functions/ptsname_r.texi
lib/ptsname_r.c
m4/ptsname_r.m4

index 18b132946a20e7f908630b55a1b92d7958dfcbf5..49eba22168d0ac91204eb6096ffc148deec2ebfa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-04-08  Bruno Haible  <bruno@clisp.org>
+
+       ptsname_r: Work around ptsname_r bug on NetBSD 10.0.
+       * m4/ptsname_r.m4 (gl_FUNC_PTSNAME_R): On NetBSD, arrange to override
+       ptsname_r.
+       * lib/ptsname_r.c (ptsname_r): Add workaround for NetBSD bug.
+       * doc/glibc-functions/ptsname_r.texi: Mention the NetBSD bug.
+
 2024-04-07  Bruno Haible  <bruno@clisp.org>
 
        sigsegv tests: Avoid a crash on NetBSD 10.0/i386.
index 198ebf3fe645072aee8e6a4375d96cd250dd0f8e..785064a2fe4d7da971368b359025b9e32f8b97f9 100644 (file)
@@ -28,6 +28,10 @@ MSVC 14.
 When this function fails, it returns -1 instead of the error code
 on some platforms:
 macOS 11.1, FreeBSD 14.0, Android 4.3.
+@item
+When this function fails with ERANGE, it stores an empty string as result
+on some platforms:
+NetBSD 10.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 460220b201cfc59935d9df28189998358f0275fa..cc1ae495ec75ef0276b833dd21472c8247887401 100644 (file)
@@ -68,11 +68,34 @@ ptsname_r (int fd, char *buf, size_t buflen)
 #undef ptsname_r
 {
 #if HAVE_ESSENTIALLY_WORKING_PTSNAME_R
+# if defined __NetBSD__
+  char tmpbuf[32];
+  if (buf == NULL)
+    return EINVAL;
+  if (buflen >= sizeof (tmpbuf))
+    /* ERANGE should not happen in this case.  */
+    return ptsname_r (fd, buf, buflen);
+  else
+    {
+      int ret = ptsname_r (fd, tmpbuf, sizeof (tmpbuf));
+      if (ret != 0)
+        return ret;
+      else
+        {
+          size_t len = strlen (tmpbuf);
+          if (len >= buflen)
+            return ERANGE;
+          memcpy (buf, tmpbuf, len + 1);
+          return 0;
+        }
+    }
+# else
   int ret = ptsname_r (fd, buf, buflen);
   if (ret == 0)
     return 0;
   else
     return errno;
+# endif
 #elif defined __DragonFly__
   int saved_errno = errno;
   char tmpbuf[5 + 4 + 10 + 1];
index 8a44b6d2460d2cb2fc5983e43d1de90993e56118..bbf2d08284b5e13e3907d1bd2ee95084218ea058 100644 (file)
@@ -1,4 +1,4 @@
-# ptsname_r.m4 serial 9
+# ptsname_r.m4 serial 10
 dnl Copyright (C) 2010-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -73,6 +73,13 @@ main (void)
         *yes) ;;
         *) REPLACE_PTSNAME_R=1 ;;
       esac
+      dnl On NetBSD 10.0, when ptsname_r fails with ERANGE, it clobbers the
+      dnl result buffer. We don't use an AC_RUN_IFELSE test here, because
+      dnl while the bug exists on all platforms, only NetBSD/i386 has the
+      dnl files /dev/ptyp[01] on which the bug becomes apparent.
+      case "$host_os" in
+        netbsd*) REPLACE_PTSNAME_R=1 ;;
+      esac
     fi
   fi