Repository navigation
Commit 75e554a
authored
iop/devfs: fix off-by-one buffer overflow in devfs_ioctl2 GETDESC
## Description
In `devfs_ioctl2()`, the `DEVFS_IOCTL_GETDESC` handler copies the device
description with `strncpy(buf, dev->node.desc, buflen - 1)` and then
tries to NUL-terminate the result with:
*(((u8 *)buf + buflen)) = 0;
This writes at `buf[buflen]`, which is one byte past the end of the
caller-provided buffer (valid indices are `0 .. buflen - 1`). It also
leaves `buf[buflen - 1]` unterminated when the description is longer
than `buflen - 1` characters, so the following `strlen(buf)` can read
past the buffer.
The terminator must be written at `buf[buflen - 1]`, which is the last
byte of the buffer and the one `strncpy` was told to leave free.
## Changes
- `iop/fs/devfs/src/devfs.c`: NUL-terminate at `buflen - 1` instead of
`buflen`.
## Impact
- Fixes a 1-byte out-of-bounds write on the IOP (memory corruption of
whatever follows the caller's buffer).
- Fixes a possible unterminated string being passed to `strlen()`.
- No behavior change for valid use otherwise; the return value is still
`strlen(buf)`.1 parent f1ca58a commit 75e554a
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
600 | 600 | | |
601 | 601 | | |
602 | 602 | | |
603 | | - | |
| 603 | + | |
604 | 604 | | |
605 | 605 | | |
606 | 606 | | |
| |||
0 commit comments