Module Name:    src
Committed By:   christos
Date:           Sun May  3 16:32:16 UTC 2020

Modified Files:
        src/usr.bin/rlogin: rlogin.c

Log Message:
PR/54435: Adjust for new kernel behavior of soreceive(9) clearing MSG_OOB
when receiving the oob message. This made SIOCATMARK return always 0 since
the oob message was cleared. Instead, use recvmsg(2) to determine if
the message was oob or not. This works with both the old and new kernel
and it is not racy.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/rlogin/rlogin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/rlogin/rlogin.c
diff -u src/usr.bin/rlogin/rlogin.c:1.46 src/usr.bin/rlogin/rlogin.c:1.47
--- src/usr.bin/rlogin/rlogin.c:1.46	Sun May  3 12:11:06 2020
+++ src/usr.bin/rlogin/rlogin.c	Sun May  3 12:32:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: rlogin.c,v 1.46 2020/05/03 16:11:06 christos Exp $	*/
+/*	$NetBSD: rlogin.c,v 1.47 2020/05/03 16:32:16 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1990, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "@(#)rlogin.c	8.4 (Berkeley) 4/29/95";
 #else
-__RCSID("$NetBSD: rlogin.c,v 1.46 2020/05/03 16:11:06 christos Exp $");
+__RCSID("$NetBSD: rlogin.c,v 1.47 2020/05/03 16:32:16 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -577,16 +577,34 @@ static pid_t ppid;
 static ssize_t rcvcnt, rcvstate;
 static char rcvbuf[8 * 1024];
 
+static int
+recvx(int fd, void *buf, size_t len, int flags, int *msgflags)
+{
+	struct msghdr msg;
+	struct iovec iov;
+	int error;
+
+	memset(&msg, 0, sizeof(msg));
+	msg.msg_iov = &iov;
+	iov.iov_base = buf;
+	iov.iov_len = len;
+	error = recvmsg(fd, &msg, flags);
+	if (error)
+		return error;
+	*msgflags = msg.msg_flags;
+	return 0;
+}
+
 static void
 oob(int signo)
 {
 	struct termios tty;
-	int atmark;
+	int atmark = 0;
 	ssize_t n, rcvd;
 	char waste[BUFSIZ], mark;
 
 	rcvd = 0;
-	while (recv(rem, &mark, 1, MSG_OOB) == -1) {
+	while (recvx(rem, &mark, 1, MSG_OOB, &atmark) == -1) {
 		switch (errno) {
 		case EWOULDBLOCK:
 			/*
@@ -610,6 +628,7 @@ oob(int signo)
 			return;
 		}
 	}
+	atmark &= MSG_OOB;
 	if (mark & TIOCPKT_WINDOW) {
 		/* Let server know about window size changes */
 		(void)kill(ppid, SIGUSR1);
@@ -626,17 +645,8 @@ oob(int signo)
 	}
 	if (mark & TIOCPKT_FLUSHWRITE) {
 		(void)tcflush(1, TCIOFLUSH);
-		for (;;) {
-			if (ioctl(rem, SIOCATMARK, &atmark) < 0) {
-				warn("ioctl SIOCATMARK (ignored)");
-				break;
-			}
-			if (atmark)
-				break;
+		if (!atmark)
 			n = read(rem, waste, sizeof (waste));
-			if (n <= 0)
-				break;
-		}
 		/*
 		 * Don't want any pending data to be output, so clear the recv
 		 * buffer.  If we were hanging on a write when interrupted,

Reply via email to