Use readstr() for #device text buffers
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 28 Sep 2018 20:12:06 +0000 (16:12 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 2 Oct 2018 18:07:01 +0000 (14:07 -0400)
These two follow the sized_kmalloc pattern for generating buffers.  They
generate text, not raw data, and it should be readstr, not readmem.
Otherwise, we'll return extra bytes (zeros).

Note that our snprintf() (which creates the data in these cases) enforces
null-termination, so there's no concern with running off the end of the
sza.

Also note that our snprintf() returns the amount written, not the amount of
space needed, which is non-standard.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/drivers/dev/mem.c
kern/drivers/dev/proc.c

index fefed1e..8feadcc 100644 (file)
@@ -424,7 +424,7 @@ static size_t mem_read(struct chan *c, void *ubuf, size_t n, off64_t offset)
        case Qfree:
        case Qkmemstat:
                sza = c->synth_buf;
-               return readmem(offset, ubuf, n, sza->buf, sza->size);
+               return readstr(offset, ubuf, n, sza->buf);
        default:
                panic("Bad Qid %p!", c->qid.path);
        }
index ff9c66a..13608c6 100644 (file)
@@ -1040,7 +1040,7 @@ static size_t procread(struct chan *c, void *va, size_t n, off64_t off)
                        return i;
                case Qmaps:
                        sza = c->aux;
-                       i = readmem(off, va, n, sza->buf, sza->size);
+                       i = readstr(off, va, n, sza->buf);
                        proc_decref(p);
                        return i;
        }