shithub: riscv

Download patch

ref: 8a2d96257007f66abaa5396be1f11cea84ec719e
parent: fb1551e9973ee86ccdd0ed8b125de97e9865e5ba
author: cinap_lenrek <[email protected]>
date: Fri Mar 11 16:46:49 EST 2016

mothra: dynamically allocate buffer for refresh url (was 20 bytes stack buffer before) (thanks BurnZeZ for reporting)

--- a/sys/src/cmd/mothra/rdhtml.c
+++ b/sys/src/cmd/mothra/rdhtml.c
@@ -268,8 +268,9 @@
 	return c;
 }
 
-char *unquot(char *dst, char *src, int len){
-	char *e;
+char *unquot(char *src){
+	char *e, *dst;
+	int len;
 
 	e=0;
 	while(*src && strchr(" \t\r\n", *src))
@@ -279,10 +280,9 @@
 		src++;
 	}
 	if(e==0) e=strchr(src, 0);
-	len--;
-	if((e - src) < len)
-		len=e-src;
-	if(len>0) memmove(dst, src, len);
+	len=e-src;
+	dst = emalloc(len+1);
+	memmove(dst, src, len);
 	dst[len]=0;
 	return dst;
 }
@@ -877,8 +877,9 @@
 			str++;
 			pl_htmloutput(&g, 0, "[refresh: ", 0);
 			free(g.state->link);
-			g.state->link=unquot(buf, str, sizeof(buf));
-			pl_htmloutput(&g, 0, str, 0);
+			g.state->link=unquot(str);
+			pl_htmloutput(&g, 0, g.state->link, 0);
+			free(g.state->link);
 			g.state->link=0;
 			pl_htmloutput(&g, 0, "]", 0);
 			g.linebrk=1;