Skip to content

Commit 705f332

Browse files
committed
Truncate overly long 9p error messages
Potential stack write overflow reported by Ned Williamson, Google. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
1 parent f652754 commit 705f332

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/lib/pci_virtio_9p.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,12 @@ pci_vt9p_thread(void *vsc)
362362
ptr += ret;
363363
}
364364
DPRINTF(("[thread]got complete response for tag %d len %d\r\n", (int)tag, (int)len));
365-
if (command == 107) {
365+
if (command == 107) { /* Rerror */
366366
char msg[128];
367367
uint16_t slen = (uint16_t)((uint16_t)buf[7] | ((uint16_t)buf[8] << 8));
368+
if (slen > 128) {
369+
slen = 128; /* truncate overlong error message if required */
370+
}
368371
memcpy(msg, &buf[9], slen);
369372
msg[slen] = 0;
370373
DPRINTF(("[thread]Rerror: %s\r\n", msg));

0 commit comments

Comments
 (0)