]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
log: Fix size calculation for number of iovecs 33884/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 31 Jul 2024 09:39:04 +0000 (11:39 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 31 Jul 2024 11:12:55 +0000 (13:12 +0200)
Each log context field can expand to up to three iovecs (key, value
and newline) so let's fix the size calculation to take this into
account.

src/basic/log.c

index 09500f9cb05201f986d12e3f153dabae8e61ccfa..571f5e43dce5b3190cb0fc184447ba66a62c1061 100644 (file)
@@ -747,7 +747,7 @@ static int write_to_journal(
         if (LOG_PRI(level) > log_target_max_level[LOG_TARGET_JOURNAL])
                 return 0;
 
-        iovec_len = MIN(6 + _log_context_num_fields * 2, IOVEC_MAX);
+        iovec_len = MIN(6 + _log_context_num_fields * 3, IOVEC_MAX);
         iovec = newa(struct iovec, iovec_len);
 
         log_do_header(header, sizeof(header), level, error, file, line, func, object_field, object, extra_field, extra);
@@ -1099,7 +1099,7 @@ int log_struct_internal(
                         int r;
                         bool fallback = false;
 
-                        iovec_len = MIN(17 + _log_context_num_fields * 2, IOVEC_MAX);
+                        iovec_len = MIN(17 + _log_context_num_fields * 3, IOVEC_MAX);
                         iovec = newa(struct iovec, iovec_len);
 
                         /* If the journal is available do structured logging.
@@ -1196,7 +1196,7 @@ int log_struct_iovec_internal(
                 struct iovec *iovec;
                 size_t n = 0, iovec_len;
 
-                iovec_len = MIN(1 + n_input_iovec * 2 + _log_context_num_fields * 2, IOVEC_MAX);
+                iovec_len = MIN(1 + n_input_iovec * 2 + _log_context_num_fields * 3, IOVEC_MAX);
                 iovec = newa(struct iovec, iovec_len);
 
                 log_do_header(header, sizeof(header), level, error, file, line, func, NULL, NULL, NULL, NULL);