shithub: riscv

Download patch

ref: 4063334e6f121b42b0e28fcbdd3108d040893fee
parent: 951ab17262c61dca249baf5aca1810b55117e684
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Jul 20 14:52:02 EDT 2022

pc/rtc: make sure string is NUL terminates for rtc write

--- a/sys/src/9/pc/devrtc.c
+++ b/sys/src/9/pc/devrtc.c
@@ -227,26 +227,25 @@
 	char *a, *start;
 	Rtc rtc;
 	ulong secs;
+	char *cp, sbuf[32];
 	uchar bcdclock[Nbcd];
-	char *cp, *ep;
 	ulong offset = off;
 
 	if(offset!=0)
 		error(Ebadarg);
 
-
 	switch((ulong)c->qid.path){
 	case Qrtc:
 		/*
 		 *  read the time
 		 */
-		cp = ep = buf;
-		ep += n;
-		while(cp < ep){
-			if(*cp>='0' && *cp<='9')
+		if(n >= sizeof(sbuf))
+			error(Ebadarg);
+		strncpy(sbuf, buf, n);
+		sbuf[n] = '\0';
+		for(cp = sbuf; *cp != '\0'; cp++)
+			if(*cp >= '0' && *cp <= '9')
 				break;
-			cp++;
-		}
 		secs = strtoul(cp, 0, 0);
 	
 		/*