shithub: riscv

Download patch

ref: 876907a5306fc8c41536403185e3cafa23a2c7ed
parent: 4ab2d149d46c6762c9b8d9fd24d0bf92b10704f6
author: Igor Böhm <igor@9lab.org>
date: Tue Feb 8 19:11:44 EST 2022

rio: fix parsing of directory path (-cd) when creating a new window via wctl

Before applying this patch the following will fail to open ed
in the '/tmp/s p a c e' folder:

<snip>
% mkdir '/tmp/s p a c e'
% window -cd '/tmp/s p a c e' ed
!pwd
/tmp/s p a c e
!
q
<snap>

After applying the patch the above sequence works as expected,
opening ed in the '/tmp/s p a c e' folder, printing the present
working directory, and quitting ed.

The root cause was a faulty computation of the pointer `s`,
being off by one, leading to any arguments after the
directory path to be skipped.

This regression was introduced in revision:
• 614f1d6268fd986fc628eec3754bd4599363ad13

Thanks umbraticus for finding and reporting the issue.

--- a/sys/src/cmd/rio/wctl.c
+++ b/sys/src/cmd/rio/wctl.c
@@ -202,7 +202,7 @@
 int
 parsewctl(char **argp, Rectangle r, Rectangle *rp, int *pidp, int *idp, int *hiddenp, int *scrollingp, char **cdp, char *s, char *err)
 {
-	int cmd, param, xy, sign;
+	int cmd, n, nt, param, xy, sign;
 	char *f[2], *t;
 
 	*pidp = 0;
@@ -252,13 +252,12 @@
 			s++;
 		if(param == Cd){
 			*cdp = s;
-			gettokens(*cdp, f, nelem(f), " \t\r\n\v\f");
-			s += strlen(*cdp);
-			if((*cdp)[0] == '\'' && s[-1] == '\''){
-				/* drop quotes */
-				*cdp += 1;
-				s[-1] = '\0';
-			}
+			if((nt = gettokens(*cdp, f, nelem(f), " \t\r\n\v\f")) < 1)
+				return -1;
+			n = strlen(*cdp);
+			if((*cdp)[0] == '\'' && (*cdp)[n-1] == '\'')
+				((*cdp)++)[n-1] = '\0'; /* drop quotes */
+			s += n+(nt-1);
 			continue;
 		}
 		sign = 0;