1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-19 22:50:17 +03:00

coredump: use loop_read() for reading coredump into memory

Fixes: #26748
This commit is contained in:
Lennart Poettering 2023-06-22 16:48:48 +02:00
parent 6270b2e67e
commit a73c74db66
2 changed files with 7 additions and 7 deletions

View File

@ -54,8 +54,7 @@ ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
assert(fd >= 0);
/* If called with nbytes == 0, let's call read() at least
* once, to validate the operation */
/* If called with nbytes == 0, let's call read() at least once, to validate the operation */
if (nbytes > (size_t) SSIZE_MAX)
return -EINVAL;

View File

@ -604,14 +604,15 @@ static int allocate_journal_field(int fd, size_t size, char **ret, size_t *ret_s
return log_warning_errno(errno, "Failed to seek: %m");
field = malloc(9 + size);
if (!field) {
log_warning("Failed to allocate memory for coredump, coredump will not be stored.");
return -ENOMEM;
}
if (!field)
return log_warning_errno(SYNTHETIC_ERRNO(ENOMEM),
"Failed to allocate memory for coredump, coredump will not be stored.");
memcpy(field, "COREDUMP=", 9);
n = read(fd, field + 9, size);
/* NB: simple read() would fail for overly large coredumps, since read() on Linux can only deal with
* 0x7ffff000 bytes max. Hence call things in a loop. */
n = loop_read(fd, field + 9, size, /* do_poll= */ false);
if (n < 0)
return log_error_errno((int) n, "Failed to read core data: %m");
if ((size_t) n < size)