Fix a bug that showed up on netbsd-10:

serv_input: read@3 need 468 got 396
read(2) isn't garanteed to be atomic on unix sockets. Loop on poll()/read()
until we read the expected len or get an error.
This commit is contained in:
bouyer 2023-09-06 18:34:24 +00:00
parent 5e7a8d2e53
commit 70d388bc04
3 changed files with 70 additions and 13 deletions

View File

@ -1,7 +1,7 @@
# $NetBSD: Makefile,v 1.34 2021/09/10 08:28:21 he Exp $
# $NetBSD: Makefile,v 1.35 2023/09/06 18:34:24 bouyer Exp $
DISTNAME= rtty-3.2
PKGREVISION= 3
PKGREVISION= 4
CATEGORIES= sysutils
MASTER_SITES= http://gatekeeper.hpl.hp.com/archive/pub/misc/vixie/
MASTER_SITES+= ftp://gatekeeper.hpl.hp.com/pub/misc/vixie/

View File

@ -1,10 +1,10 @@
$NetBSD: distinfo,v 1.10 2021/10/26 11:20:08 nia Exp $
$NetBSD: distinfo,v 1.11 2023/09/06 18:34:24 bouyer Exp $
BLAKE2s (rtty-3.2.tar.gz) = da5c9c2d6b19bdb70e87b13e795693d3f746736903451d0235bdd4f433c1b097
SHA512 (rtty-3.2.tar.gz) = 11d1fa82ddce97320c1aa44f726a2b05e49c7dd67fc9a902a29531e934f7f16b3ad193f9e4f247d8d03fc61bd0337c165faa08e1585374820b8f306b1b5315a4
Size (rtty-3.2.tar.gz) = 23445 bytes
SHA1 (patch-aa) = 11cf781b562bfe35c1003db6f3ac94653c1f8e06
SHA1 (patch-ab) = 32644f9383ef43b45421fc100382509e2e6b2e34
SHA1 (patch-ac) = 8b1b1be9eb471f68d62b4454f9bd74dddb471d75
SHA1 (patch-ac) = a300e46abdf5971b05580382b6ecfc95152c9abc
SHA1 (patch-ad) = dee546ca499fa4fb534f137d58fcbbb800b244d3
SHA1 (patch-agelogs.sh) = 50754d303652d7c2ee3bce55101b3b0dbe60b044

View File

@ -1,24 +1,29 @@
$NetBSD: patch-ac,v 1.3 2000/08/02 17:33:45 thorpej Exp $
$NetBSD: patch-ac,v 1.4 2023/09/06 18:34:24 bouyer Exp $
Make this compile on Solaris.
Fix a bug where rtty would loop forever if its parent process
(such as a shell) were to die and close rtty's standard input.
--- rtty.c.orig Fri Aug 23 15:25:28 1996
+++ rtty.c Wed Aug 2 10:25:30 2000
@@ -35,6 +35,10 @@
Fix a bug where rtty would exit with messages like
serv_input: read@3 need 468 got 396
when a read on the unix socket returns a partial read.
--- rtty.c.orig 2023-09-06 18:23:56.430905709 +0200
+++ rtty.c 2023-09-06 18:24:21.275470294 +0200
@@ -34,6 +34,11 @@
#include <string.h>
#include <pwd.h>
#include <termios.h>
+#include <poll.h>
+
+#if (defined(__sun__) && defined(__svr4__))
+#include <fcntl.h>
+#endif
+
#include "rtty.h"
#ifdef NEED_BITYPES_H
# include "bitypes.h"
@@ -266,13 +270,16 @@
@@ -266,13 +271,16 @@
static void
tty_input(fd) {
static enum {base, need_cr, tilde} state = base;
@ -36,7 +41,7 @@ Fix a bug where rtty would loop forever if its parent process
switch (state) {
case base:
@@ -346,6 +353,14 @@
@@ -346,6 +354,14 @@
write(Log, buf, 1);
}
}
@ -51,3 +56,55 @@ Fix a bug where rtty would loop forever if its parent process
#if 0
fcntl(Tty, F_SETFL, fcntl(Tty, F_GETFL, 0)&~O_NONBLOCK);
#endif
@@ -502,6 +518,33 @@
}
}
+static ssize_t
+read_exact(int fd, void *buf, size_t nbytes)
+{
+ struct pollfd pfd;
+ ssize_t ret = 0, r;
+
+ while (nbytes > 0) {
+ pfd.fd = fd;
+ pfd.events = POLLRDNORM;
+ pfd.revents = 0;
+
+ switch (poll(&pfd, 1, 1000)) {
+ case -1:
+ return -1;
+ case 0:
+ return ret;
+ default:
+ r = read(fd, buf, nbytes);
+ if (r < 0)
+ return r;
+ ret += r;
+ nbytes -= r;
+ break;
+ }
+ }
+}
+
static void
serv_input(fd) {
char passwd[TP_MAXVAR], s[3], *c, *crypt();
@@ -521,7 +564,7 @@
switch (t) {
case TP_DATA: /* FALLTHROUGH */
case TP_NOTICE:
- if (i != (nchars = read(fd, T.c, i))) {
+ if (i != (nchars = read_exact(fd, T.c, i))) {
fprintf(stderr, "serv_input: read@%d need %d got %d\n",
fd, i, nchars);
server_died();
@@ -563,7 +606,7 @@
break;
case TP_PARITY:
if (o & TP_QUERY) {
- if (i != (nchars = read(fd, T.c, i))) {
+ if (i != (nchars = read_exact(fd, T.c, i))) {
server_died();
}
T.c[i] = '\0';