code: plan9front

Download patch

ref: 82435c350a1d3530c87ea88ada68e984fc6b9b80
parent: 7d108832528eb1ee85a445a562c00b5a8344d882
author: Michael Forney <mforney@mforney.org>
date: Sat Oct 29 19:06:58 EDT 2022

upas/fs: clear errstr after chkunix

The readmessage loop clears errstr at start and expects it not to
change unless there is a read error.  However, strtotm may use
multiple calls to tmparse while trying to determine the date format,
which may leave errstr non-empty on success.  Clear it after chkunix
so that this doesn't get treated as a message read error.

This also fixes handling of naked From lines, which were previously
just warned about, but since the conversion to tmparse they
accidentally triggered a message read failure.

--- a/sys/src/cmd/upas/fs/plan9.c
+++ b/sys/src/cmd/upas/fs/plan9.c
@@ -129,6 +129,7 @@
 {
 	char *s, *n;
 	long l, state;
+	int r;
 
 	werrstr("");
 	state = 0;
@@ -138,10 +139,12 @@
 			break;
 		n = s + (l = Blinelen(b->in)) - 1;
 		if(l >= 28 + 7 && n[0] == '\n')
-		if(strncmp(s, "From ", 5) == 0)
-		if(!chkunix(s + 5, l - 5))
-		if(++state == 2)
-			break;
+		if(strncmp(s, "From ", 5) == 0){
+			r = chkunix(s + 5, l - 5);
+			werrstr("");
+			if(r == 0 && ++state == 2)
+				break;
+		}
 		if(state == 0)
 			return -1;
 		addtomessage(m, s, l);