mirror of
https://github.com/topjohnwu/Magisk
synced 2024-11-13 20:54:12 +01:00
utils/file.c: NULL terminate all files read into memory
Some functions, like `patch_init_rc()`, treat buffers read into memory as a string instead of a byte buffer. Since the buffers weren't NULL-terminated, this resulted in out-of-bounds reads and caused crashes in certain conditions. THis commit updates fd_full_read() to always NULL-terminate the buffers so that they can be treated as strings when working with text files. Signed-off-by: Andrew Gunnerson <andrewgunnerson@gmail.com>
This commit is contained in:
parent
40b6fe03c2
commit
5ad4702a5b
@ -401,8 +401,9 @@ int mmap_rw(const char *filename, void **buf, size_t *size) {
|
||||
void fd_full_read(int fd, void **buf, size_t *size) {
|
||||
*size = lseek(fd, 0, SEEK_END);
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
*buf = xmalloc(*size);
|
||||
*buf = xmalloc(*size + 1);
|
||||
xxread(fd, *buf, *size);
|
||||
((char *) *buf)[*size] = '\0';
|
||||
}
|
||||
|
||||
void full_read(const char *filename, void **buf, size_t *size) {
|
||||
|
Loading…
Reference in New Issue
Block a user