Shnatsel / libdiffuzz

Custom memory allocator that helps discover reads from uninitialized memory
Apache License 2.0
163 stars 8 forks source link

Passing options by environment variables may set them too late and is not portable #8

Open Shnatsel opened 6 years ago

Shnatsel commented 6 years ago

Currently libdiffuzz switches to non-deterministic mode after reading an environment variable from a function called from link-time "constructors" section:

https://github.com/Shnatsel/libdiffuzz/blob/f0c7a8f3b27df24d389d9e003ebda01ad89eb1cf/src/lib.rs#L31-L33

This is not a great idea for two reasons:

  1. This is not portable. This is already taking different codepaths depending on whether it's on Linux/BSD or macOS. Windows is currently not supported. What's worse, there is no way to tell if this actually works on your platform or not!
  2. This may kick in too late and miss initializing some heap-allocated memory in other libraries with similar hooks, so libdiffuzz will fail to expose some errors.
Shnatsel commented 6 years ago

I'd prefer to fix this by building two different dynamic libraries, libdiffuzz and libdiffuzz-random, with the appropriate mode hardcoded in each.

There is also dynamic setup of the amount of memory to over-allocate, but that's a fairly obscure feature which can be moved into a compile-time parameter.