]> git.lizzy.rs Git - plan9front.git/commitdiff
rio: fix bug causing short reads of wctl files
authorAlex Musolino <alex@musolino.id.au>
Tue, 19 Nov 2019 02:08:13 +0000 (12:38 +1030)
committerAlex Musolino <alex@musolino.id.au>
Tue, 19 Nov 2019 02:08:13 +0000 (12:38 +1030)
Previously, reads of wctl files would return one byte less than
requested as the returned string must be null terminated.  Now we pass
the actual size of the allocated buffer to the handler, which is large
enough to accommodate a trailing partial rune and terminating null
byte.

sys/src/cmd/rio/xfid.c

index 3985bea0097956330fd36c0e88628fa59d09eb99..b8e4be84a43f525fd8d00e0d69d6d9bad6e56049 100644 (file)
@@ -670,9 +670,9 @@ xfidread(Xfid *x)
                }
                c1 = crm.c1;
                c2 = crm.c2;
-               t = emalloc(cnt+UTFmax+1);      /* room to unpack partial rune plus */
+               pair.ns = cnt+UTFmax+1; /* room for partial rune and null byte */
+               t = emalloc(pair.ns);
                pair.s = t;
-               pair.ns = cnt;
                send(c1, &pair);
                recv(c2, &pair);
                fc.data = pair.s;