This is an archive of the discontinued LLVM Phabricator instance.

[Msan] Fix the if_indextoname.cc test to pass on FreeBSD
ClosedPublic

Authored by kutuzov.viktor.84 on May 2 2015, 8:55 AM.

Details

Summary

On FreeBSD if_indextoname() leverages strncpy() that unpoisons the whole name buffer, what in turn results in the assertion following the if_indextoname() call to fail:

if (!if_indextoname(1, ifname)) {
  ...
}
assert(strlen(ifname) + 1 == __msan_test_shadow(ifname, sizeof(ifname)));

Diff Detail

Event Timeline

kutuzov.viktor.84 retitled this revision from to [Msan] Fix the if_indextoname.cc test to pass on FreeBSD.
kutuzov.viktor.84 updated this object.
kutuzov.viktor.84 edited the test plan for this revision. (Show Details)
kutuzov.viktor.84 added subscribers: Unknown Object (MLST), emaste.
eugenis edited edge metadata.May 6 2015, 12:49 PM

I don't like it. strncpy zero-initializes this memory whether it's called from inside another interceptor or not.

I'd just change the assert to show that the first strlen()+1 bytes are unpoisoned, without testing the rest of the buffer.

Maybe change the if_indextoname interceptor to poison this area?

Maybe change the if_indextoname interceptor to poison this area?

I would expect all functions handling buffers of specified sizes behave consistently in this regard. I mean, given strncpy() unpoisons its destination buffer all over its size, then probably if_indextoname() should do the same.

kutuzov.viktor.84 edited edge metadata.

Updated.

eugenis accepted this revision.May 8 2015, 9:16 AM
eugenis edited edge metadata.

LGTM

This revision is now accepted and ready to land.May 8 2015, 9:16 AM
This revision was automatically updated to reflect the committed changes.