+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.
/* 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
#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];
-# 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.
*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