shithub: riscv

Download patch

ref: e1dcd2beb412a3e77b5c6df23571135137b486ed
parent: 05227960c6fd55dc8b050bf83e71f0924bfaf257
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Feb 24 22:21:09 EST 2019

webfs: properly handle %.*s in url path and debug prints

--- a/sys/src/cmd/webfs/http.c
+++ b/sys/src/cmd/webfs/http.c
@@ -663,7 +663,7 @@
 			for(;;){
 				if(n >= sizeof(buf)-2){
 					if(debug)
-						fprint(2, "-> %.*s", n, buf);
+						fprint(2, "-> %.*s", utfnlen(buf, n), buf);
 					if(hwrite(h, buf, n) != n)
 						goto Badflush;
 					n = 0;
@@ -685,7 +685,7 @@
 				continue;
 			if(n > 0){
 				if(debug)
-					fprint(2, "-> %.*s", n, buf);
+					fprint(2, "-> %.*s", utfnlen(buf, n), buf);
 				if(hwrite(h, buf, n) != n)
 					goto Badflush;
 			}
@@ -693,7 +693,7 @@
 		}
 		n += snprint(buf+n, sizeof(buf)-n, "\r\n");
 		if(debug)
-			fprint(2, "-> %.*s", n, buf);
+			fprint(2, "-> %.*s", utfnlen(buf, n), buf);
 		if(hwrite(h, buf, n) != n){
 		Badflush:
 			alarm(0);
--- a/sys/src/cmd/webfs/url.c
+++ b/sys/src/cmd/webfs/url.c
@@ -169,7 +169,7 @@
 			return estrdup(b);
 		if(*s != '/' && (x = strrchr(b, '/'))){
 			a = emalloc((x - b) + strlen(s) + 4);
-			sprint(a, "%.*s/%s", (int)(x - b), b, s);
+			sprint(a, "%.*s/%s", utfnlen(b, x - b), b, s);
 			return remdot(a);
 		}
 	}