https://github.com/troglobit/libc-chaos
Emit random errors when calling libc functions to emulate an unstable underlying system
https://github.com/troglobit/libc-chaos
fault-injection fuzzing glibc
Last synced: 4 months ago
JSON representation
Emit random errors when calling libc functions to emulate an unstable underlying system
- Host: GitHub
- URL: https://github.com/troglobit/libc-chaos
- Owner: troglobit
- License: mit
- Created: 2017-11-13T22:53:15.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-12-14T05:57:41.000Z (over 6 years ago)
- Last Synced: 2025-01-07T06:43:19.303Z (over 1 year ago)
- Topics: fault-injection, fuzzing, glibc
- Language: C
- Size: 28.3 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# libc-chaos
This is an MIT licensed `LD_PRELOAD` hack library that introduces random
errors in certain libc I/O functions your application uses.
The main purpose is to test how your application handles an unreliable
file system. It can also be used to locate hard-to-find bugs that only
happen once in a blue moon by introducing unexpected delays.
## Status
This library is still in alpha phase supporting the following functions:
- pwrite()
- pread()
- write()
- read()
- writev()
- readv()
## Examples
Make calling `pread()` have 20% chance to return an `EIO` error:
```
ERROR_RATE=20 LD_PRELOAD=$PWD/libchaos.so PREAD_ERROR=io path/to/your/executable
```
Introduce a 3 sec delay in all `writev()` calls:
```
HANG_TIME=3 WRITEV_ERROR="hang" LD_PRELOAD=$PWD/libchaos.so path/to/your/executable
```
## Control Error Emission with Environment Variables
- `ERROR_RATE`
defines the rate in percentage at what a function call emits an error.
`0` makes it never emit an error.
- `HANG_TIME`
defines the delay a function should always introduce before returning.
- `LD_PRELOAD=XXX`
should be kept what it is. Never touch it unless you know what you do.
- `PWRITE_ERROR`
defines what error to emit when calling `pwrite()`.
Its value could be one of:
- `nospace` emits an `ENOSPC` error.
- `io` emits an `EIO` error.
- `intr` emits an `EINTR` error.
- `hang` wait `HANG_TIME` seconds before writing
- `PREAD_ERROR`
defines what error to emit when calling `pread()`.
Its value could be one of:
- `wrong_byte` change 1 byte in the buffer that is read, before
returning to caller.
- `io` emits an `EIO` error.
- `intr` emits an `EINTR` error.
- `hang` wait `HANG_TIME` seconds before reading
- `READ_ERROR`
same as above
- `WRITE_ERROR`
same as above
- `READV_ERROR`
same as above
- `WRITEV_ERROR`
same as above
## Copyright and License
Copyright (c) 2015-2016 Zhang Yanpo (张炎泼)
Copyright (c) 2017-2019 Joachim Nisson
This library was initially written by 张炎泼 (Zhang Yanpo) who
graciously released the software under the MIT license. Later
Joachim Nilsson picked it up and added a few more APIs.