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

This commit is contained in:
cinap_lenrek 2022-07-20 18:52:02 +00:00
parent 951ab17262
commit 4063334e6f

View file

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