Page MenuHomeFreeBSD

rpcinfo: Fix buffer overflows
ClosedPublic

Authored by markj on Fri, Jul 24, 8:51 PM.
Tags
None
Referenced Files
F164966742: D58441.id182792.diff
Wed, Aug 5, 3:56 AM
Unknown Object (File)
Mon, Aug 3, 8:57 PM
Unknown Object (File)
Mon, Aug 3, 7:51 AM
Unknown Object (File)
Mon, Aug 3, 1:20 AM
Unknown Object (File)
Sun, Aug 2, 9:28 PM
Unknown Object (File)
Sun, Aug 2, 6:12 PM
Unknown Object (File)
Sat, Aug 1, 8:13 AM
Unknown Object (File)
Sat, Aug 1, 6:32 AM
Subscribers

Details

Summary

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.

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

markj requested review of this revision.Fri, Jul 24, 8:51 PM

Avoid signed/unsigned integer comparison warnings

khorben added inline comments.
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:

  1. flen = strlen(fieldbuf);
  2. cp = &fieldbuf[flen];
  3. flen += snprintf(cp, sizeof(fieldbuf) - flen, ...);

Or to remain safer:

  1. flen = strlen(fieldbuf);
  2. cp = &fieldbuf[flen];
  3. (void)snprintf(cp, sizeof(fieldbuf) - flen, ...);
  4. flen += strlen(cp);
markj added inline comments.
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.

khorben added inline comments.
usr.bin/rpcinfo/rpcinfo.c
763–765

I see that NetBSD did it too; fine for me.

This revision is now accepted and ready to land.Mon, Jul 27, 4:38 PM
This revision was automatically updated to reflect the committed changes.