mirror of
https://github.com/systemd/systemd.git
synced 2026-08-05 07:30:30 +00:00
recurse-dir: add assert for MALLOC_SIZEOF_SAFE lower bound
Coverity flags MALLOC_SIZEOF_SAFE(de) - offsetof(DirectoryEntries,
buffer) as a potential underflow when MALLOC_SIZEOF_SAFE returns 0.
After a successful malloc the return value is at least as large as
the requested size, but Coverity cannot trace this. Add an assert
to establish the lower bound.
CID#1548020
Follow-up for 6393b847f4
This commit is contained in:
@@ -55,6 +55,8 @@ int readdir_all(int dir_fd, RecurseDirFlags flags, DirectoryEntries **ret) {
|
||||
size_t bs;
|
||||
ssize_t n;
|
||||
|
||||
/* Silence static analyzers, MALLOC_SIZEOF_SAFE is at least as large as the allocation */
|
||||
assert(MALLOC_SIZEOF_SAFE(de) >= offsetof(DirectoryEntries, buffer));
|
||||
bs = MIN(MALLOC_SIZEOF_SAFE(de) - offsetof(DirectoryEntries, buffer), (size_t) SSIZE_MAX);
|
||||
assert(bs > de->buffer_size);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user