diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2019-09-19 14:58:29 +0200 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2019-09-19 15:47:14 +0200 |
commit | 4cf8bebf716cad62f75251370a5909a748dd744a (patch) | |
tree | 032780fda240a8bca0799473a4dbb988ab276e17 | |
parent | 5aec4a5da32e9a1fad1a89f17b10d676d4312895 (diff) |
Do not return true from slurp() if it failed to read
Failing to read() some data into the destination buffer from the slurp()
function was not considered an error. This means that we were
potentially leaving the caller with an uninitialized destination buffer
without letting him know it's uninitialized.
It is quite unlikely that a single call to read() would ever fail right
after a successful call to open(..., O_RDONLY). However, one practical
example of this happening is when the file being opened is actually a
directory.
Fixed by propagating the error (i.e. returning false from slurp()) if
the call to read() fails.
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
-rw-r--r-- | src/general.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/general.c b/src/general.c index 1b11bd8..ca6884b 100644 --- a/src/general.c +++ b/src/general.c @@ -27,7 +27,7 @@ bool slurp(const char *filename, char *destination, int size) { destination[n] = '\0'; (void)close(fd); - return true; + return n != -1; } /* |