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>
This commit is contained in:
parent
5aec4a5da3
commit
4cf8bebf71
@ -27,7 +27,7 @@ bool slurp(const char *filename, char *destination, int size) {
|
||||
destination[n] = '\0';
|
||||
(void)close(fd);
|
||||
|
||||
return true;
|
||||
return n != -1;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user