diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-05-18 22:27:24 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-05-19 16:42:00 +0200 |
commit | 6df28e1f847d68ad37ffe3f4ff47745b55233861 (patch) | |
tree | 2366ae0c63be949c236045e5f79b505021b8d0b5 /src/basic/fileio.c | |
parent | 871a3a33bbb3458c97e47fc828243082014fc583 (diff) | |
download | systemd-6df28e1f847d68ad37ffe3f4ff47745b55233861.tar.gz |
alloc-util: introduce MALLOC_SIZEOF_SAFE() helper
It's a wrapper around malloc_usable_size() that is supposed to be
compatible with _FORTIFY_SOURCES=1, by taking the
__builtin_object_size() data into account, the same way as the
_FORTIFY_SOURCES=1 logic does.
Fixes: #19203
Diffstat (limited to 'src/basic/fileio.c')
-rw-r--r-- | src/basic/fileio.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/basic/fileio.c b/src/basic/fileio.c index dabdf5b517..4afab84ed3 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -424,7 +424,7 @@ int read_virtual_file(const char *filename, size_t max_size, char **ret_contents if (!buf) return -ENOMEM; /* Use a bigger allocation if we got it anyway, but not more than the limit. */ - size = MIN3(malloc_usable_size(buf) - 1, max_size, READ_FULL_BYTES_MAX); + size = MIN3(MALLOC_SIZEOF_SAFE(buf) - 1, max_size, READ_FULL_BYTES_MAX); for (;;) { ssize_t k; @@ -570,7 +570,7 @@ int read_full_stream_full( buf = t; /* Unless a size has been explicitly specified, try to read as much as fits into the memory * we allocated (minus 1, to leave one byte for the safety NUL byte) */ - n = size == SIZE_MAX ? malloc_usable_size(buf) - 1 : n_next; + n = size == SIZE_MAX ? MALLOC_SIZEOF_SAFE(buf) - 1 : n_next; errno = 0; k = fread(buf + l, 1, n - l, f); |