diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-05-19 15:42:16 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-05-20 16:04:14 +0200 |
commit | 090b426b00a82cac7b4ea386b077e21ae32f1c17 (patch) | |
tree | 7ae656e693e484017cc416cf0de2bd000cc709fb /lib/fs.c | |
parent | f7f6966044a6d705fe60b091c4994931e4c8241c (diff) |
fs: avoid input buffering with small limits in fs.readfile()
If the read limit passed to fs.readfile() is smaller than BUFSIZ then
disable stdio input buffering to avoid overreading the underlying file.
This is useful when reading small amounts of data from special files
such as /dev/urandom, where a readfile call limited to 16 bytes might
actually read 4096 due to stdio buffering.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib/fs.c')
-rw-r--r-- | lib/fs.c | 3 |
1 files changed, 3 insertions, 0 deletions
@@ -1168,6 +1168,9 @@ uc_fs_readfile(uc_vm_t *vm, size_t nargs) buf = ucv_stringbuf_new(); + if (limit > -1 && limit < BUFSIZ) + setvbuf(fp, NULL, _IONBF, 0); + while (limit != 0) { blen = 1024; |