Hi,
attached there is a patch to fix few issues in Hurd's ptsname_r(),
mostly checking for more error conditions and making sure to set as
errno and return the proper values on error conditions.
Thanks,
--
Pino Toscano
[hurd_ptsname.diff]
hurd: compliance fixes for ptsname_r
ptsname_r on failure returns the value that is also set as errno; furthermore,
add more checks to it.
* set errno to EINVAL and return it if `buf' is NULL
* set errno and return it on __term_get_peername failure
* set errno to ERANGE other than returning it
In ptsname do not set errno manually, since ptsname_r has set it already.
2012-04-27 Pino Toscano <toscano.pino@...>
* sysdeps/mach/hurd/ptsname.c (ptsname): Do not manually set errno.
(__ptsname_r): Fail with EINVAL if `buf' is NULL. Set errno and return
it on __term_get_peername failure. Set errno when `buf' is too short.
--- a/sysdeps/mach/hurd/ptsname.c
+++ b/sysdeps/mach/hurd/ptsname.c
@@ -33,8 +33,6 @@ ptsname (int fd)
error_t err;
err = __ptsname_r (fd, peername, sizeof (peername));
- if (err)
- __set_errno (err);
return err ? NULL : peername;
}
@@ -50,13 +48,22 @@ __ptsname_r (int fd, char *buf, size_t b
size_t len;
error_t err;
+ if (!buf)
+ {
+ errno = EINVAL;
+ return EINVAL;
+ }
+
peername[0] = '\0';
if (err = HURD_DPORT_USE (fd, __term_get_peername (port, peername)))
- return _hurd_fd_error (fd, err);
+ return __hurd_dfail (fd, err), errno;
len = strlen (peername) + 1;
if (len > buflen)
- return ERANGE;
+ {
+ errno = ERANGE;
+ return ERANGE;
+ }
memcpy (buf, peername, len);
return 0;