diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2014-12-11 20:20:47 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2014-12-11 20:20:47 +0100 |
commit | 854d028db99d81752082028700bd7ada53306424 (patch) | |
tree | 45abbdabd5a2dd720388a94daa21a5df56ea0e4b /sys/src/cmd/acme/exec.c | |
parent | 86e63c36eded29e46a17628264b73d743df9a864 (diff) |
acme: fix buffer overrun in xfidutfread() and xfidruneread(), cleanup
the utf8 buffers b1 where allocated from fbufalloc() which gives
us BUFSIZE bytes, but Xfid->count can be bigger than that. so just
emalloc() the requested number of bytes.
when converting from Runes to utf-8, we have to account for the
terminating '\0' byte snprint() places, so fix the maxrune number
calculation instead of using BUFSIZE+1 as buffer size.
Diffstat (limited to 'sys/src/cmd/acme/exec.c')
-rw-r--r-- | sys/src/cmd/acme/exec.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/sys/src/cmd/acme/exec.c b/sys/src/cmd/acme/exec.c index 46bec984e..8acb63028 100644 --- a/sys/src/cmd/acme/exec.c +++ b/sys/src/cmd/acme/exec.c @@ -602,10 +602,10 @@ putfile(File *f, int q0, int q1, Rune *namer, int nname) for(q=q0; q<q1; q+=n){ n = q1 - q; - if(n > BUFSIZE/UTFmax) - n = BUFSIZE/UTFmax; + if(n > (BUFSIZE-1)/UTFmax) + n = (BUFSIZE-1)/UTFmax; bufread(f, q, r, n); - m = snprint(s, BUFSIZE+1, "%.*S", n, r); + m = snprint(s, BUFSIZE, "%.*S", n, r); if(write(fd, s, m) != m){ warning(nil, "can't write file %s: %r\n", name); goto Rescue2; |