]> 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 13:04:15 +0000 (15:04 +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.

ChangeLog
lib/ptsname_r.c
m4/ptsname_r.m4

index 539ce071818c76e920af827eeae82319e2d04b15..18f412a483dac30727e935c8ec087d5b28d353e7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+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.
+
 2024-04-07  Bruno Haible  <bruno@clisp.org>
 
        sigsegv tests: Avoid a crash on NetBSD 10.0/i386.
index ed70b0b438014fe4f615a70ccedfb28229a6563d..cc1ae495ec75ef0276b833dd21472c8247887401 100644 (file)
@@ -1,5 +1,5 @@
 /* Determine name of the slave side of a pseudo-terminal.
-   Copyright (C) 1998, 2002, 2010-2023 Free Software Foundation, Inc.
+   Copyright (C) 1998, 2002, 2010-2024 Free Software Foundation, Inc.
 
    This file is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as
@@ -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 a62bb0196050b086b5e98dba408c98dd613986eb..79923ecb2ebeb0524573c9c38cb6814e2de8a3b6 100644 (file)
@@ -1,5 +1,5 @@
-# ptsname_r.m4 serial 8
-dnl Copyright (C) 2010-2023 Free Software Foundation, Inc.
+# ptsname_r.m4 serial 8.1
+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,
 dnl with or without modifications, as long as this notice is preserved.
@@ -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