]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coredump: use loop_read() for reading coredump into memory
authorLennart Poettering <lennart@poettering.net>
Thu, 22 Jun 2023 14:48:48 +0000 (16:48 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 23 Jun 2023 07:38:12 +0000 (09:38 +0200)
Fixes: #26748
src/basic/io-util.c
src/coredump/coredump.c

index 6f6fb8068c441087ea3ffe207e7d863b7800ce61..bf1aab9e3884a8757bb9f9b5aa9483186ce98eeb 100644 (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;
index 847ac531dfb018274b442a21c6745672fd8a83cd..940c0def61e7ae54d171fa01d00c763f0d1b6e0b 100644 (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)