tree-wide: check results of PAGE_ALIGN()
Fixes CID#1491282, CID#1491283, CID#1491285, CID#1491288.
This commit is contained in:
@@ -27,8 +27,11 @@
|
||||
#include "memory-util.h"
|
||||
|
||||
void close_and_munmap(int fd, void *address, size_t size) {
|
||||
if (size > 0)
|
||||
assert_se(munmap(address, PAGE_ALIGN(size)) >= 0);
|
||||
if (size > 0) {
|
||||
size = PAGE_ALIGN(size);
|
||||
assert(size < SIZE_MAX);
|
||||
assert_se(munmap(address, size) >= 0);
|
||||
}
|
||||
|
||||
safe_close(fd);
|
||||
}
|
||||
|
||||
@@ -2490,6 +2490,8 @@ int bus_body_part_map(struct bus_body_part *part) {
|
||||
|
||||
shift = PAGE_OFFSET(part->memfd_offset);
|
||||
psz = PAGE_ALIGN(part->size + shift);
|
||||
if (psz >= SIZE_MAX)
|
||||
return -EFBIG;
|
||||
|
||||
if (part->memfd >= 0)
|
||||
p = mmap(NULL, psz, PROT_READ, MAP_PRIVATE, part->memfd, part->memfd_offset - shift);
|
||||
|
||||
@@ -379,7 +379,9 @@ int journal_file_fss_load(JournalFile *f) {
|
||||
if (le64toh(header->start_usec) <= 0 || le64toh(header->interval_usec) <= 0)
|
||||
return -EBADMSG;
|
||||
|
||||
f->fss_file = mmap(NULL, PAGE_ALIGN(f->fss_file_size), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
size_t sz = PAGE_ALIGN(f->fss_file_size);
|
||||
assert(sz < SIZE_MAX);
|
||||
f->fss_file = mmap(NULL, sz, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (f->fss_file == MAP_FAILED) {
|
||||
f->fss_file = NULL;
|
||||
return -errno;
|
||||
|
||||
@@ -302,9 +302,11 @@ JournalFile* journal_file_close(JournalFile *f) {
|
||||
#endif
|
||||
|
||||
#if HAVE_GCRYPT
|
||||
if (f->fss_file)
|
||||
munmap(f->fss_file, PAGE_ALIGN(f->fss_file_size));
|
||||
else
|
||||
if (f->fss_file) {
|
||||
size_t sz = PAGE_ALIGN(f->fss_file_size);
|
||||
assert(sz < SIZE_MAX);
|
||||
munmap(f->fss_file, sz);
|
||||
} else
|
||||
free(f->fsprg_state);
|
||||
|
||||
free(f->fsprg_seed);
|
||||
|
||||
Reference in New Issue
Block a user