Several functions were using sprintf() to write RPC server-controlled
data to a stack buffer. Adopt some minimal changes from NetBSD to avoid
the potential overflows.
Details
- Reviewers
khorben - Group Reviewers
secteam - Commits
- rG152ba2d3c5ff: rpcinfo: Fix buffer overflows
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Skipped - Unit
Tests Skipped - Build Status
Buildable 75102 Build 71985: arc lint + arc unit
Event Timeline
| usr.bin/rpcinfo/rpcinfo.c | ||
|---|---|---|
| 763–765 | I may be missing some of the context, but I don't see that this memory get free()'d anywhere; is it really worth strdup()'ing these strings? | |
| 843–845 | I think the rest of the loop could be avoided with: (void)snprintf(p, sizeof(buf) - (p - buf), "%d%s", vl->vers, vl->next ? "," : ""); | |
| 1115–1118 | Would it be more elegant to do this instead:
Or to remain safer:
| |
| usr.bin/rpcinfo/rpcinfo.c | ||
|---|---|---|
| 763–765 | The objects in this list are already leaked, so I don't think it's a problem to leak some additional strings. Since we're using asprintf() below, I'd rather be consistent and have them all be heap-allocated. | |
| 1115–1118 | The first one isn't equivalent, since snprintf() returns the number of characters that it wants to write, not the number of characters it did write. The second one is a bit neater maybe, but I don't really see why it's safer. Here, I just copied what NetBSD did. | |
| usr.bin/rpcinfo/rpcinfo.c | ||
|---|---|---|
| 1115–1118 | The second one is safer than the first one for the reason you mentioned; it's not safer than what NetBSD did. | |
| usr.bin/rpcinfo/rpcinfo.c | ||
|---|---|---|
| 763–765 | I see that NetBSD did it too; fine for me. | |