anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0038-journal-remote-fix-saving-of-binary-fields.patch

923a60
From 608259be892c532d0afaeb81de3a5ee578d7658a Mon Sep 17 00:00:00 2001
923a60
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
923a60
Date: Mon, 2 Mar 2015 10:34:51 -0500
923a60
Subject: [PATCH] journal-remote: fix saving of binary fields
923a60
923a60
Binary fields were not processed properly, and resulting journal files
923a60
were non-conforming, resulting in an error ("Invalid field.") when reading.
923a60
923a60
https://bugs.freedesktop.org/show_bug.cgi?id=89391
923a60
(cherry picked from commit 09d801a82a46df518dd752e40bf13ac404daa2ce)
923a60
---
923a60
 src/journal-remote/journal-remote-parse.c | 31 +++++++++++++----------
923a60
 src/journal-remote/journal-remote-parse.h |  4 ++-
923a60
 2 files changed, 21 insertions(+), 14 deletions(-)
923a60
923a60
diff --git a/src/journal-remote/journal-remote-parse.c b/src/journal-remote/journal-remote-parse.c
923a60
index d9dea8deb0..afded7e380 100644
923a60
--- a/src/journal-remote/journal-remote-parse.c
923a60
+++ b/src/journal-remote/journal-remote-parse.c
923a60
@@ -344,22 +344,25 @@ int process_data(RemoteSource *source) {
923a60
                    LLLLLLLL0011223344...\n
923a60
                 */
923a60
                 sep = memchr(line, '=', n);
923a60
-                if (sep)
923a60
+                if (sep) {
923a60
                         /* chomp newline */
923a60
                         n--;
923a60
-                else
923a60
+
923a60
+                        r = iovw_put(&source->iovw, line, n);
923a60
+                        if (r < 0)
923a60
+                                return r;
923a60
+                } else {
923a60
                         /* replace \n with = */
923a60
                         line[n-1] = '=';
923a60
-                log_trace("Received: %.*s", (int) n, line);
923a60
 
923a60
-                r = iovw_put(&source->iovw, line, n);
923a60
-                if (r < 0) {
923a60
-                        log_error("Failed to put line in iovect");
923a60
-                        return r;
923a60
+                        source->field_len = n;
923a60
+                        source->state = STATE_DATA_START;
923a60
+
923a60
+                        /* we cannot put the field in iovec until we have all data */
923a60
                 }
923a60
 
923a60
-                if (!sep)
923a60
-                        source->state = STATE_DATA_START;
923a60
+                log_trace("Received: %.*s (%s)", (int) n, line, sep ? "text" : "binary");
923a60
+
923a60
                 return 0; /* continue */
923a60
         }
923a60
 
923a60
@@ -382,6 +385,7 @@ int process_data(RemoteSource *source) {
923a60
 
923a60
         case STATE_DATA: {
923a60
                 void *data;
923a60
+                char *field;
923a60
 
923a60
                 assert(source->data_size > 0);
923a60
 
923a60
@@ -396,11 +400,12 @@ int process_data(RemoteSource *source) {
923a60
 
923a60
                 assert(data);
923a60
 
923a60
-                r = iovw_put(&source->iovw, data, source->data_size);
923a60
-                if (r < 0) {
923a60
-                        log_error("failed to put binary buffer in iovect");
923a60
+                field = (char*) data - sizeof(uint64_t) - source->field_len;
923a60
+                memmove(field + sizeof(uint64_t), field, source->field_len);
923a60
+
923a60
+                r = iovw_put(&source->iovw, field + sizeof(uint64_t), source->field_len + source->data_size);
923a60
+                if (r < 0)
923a60
                         return r;
923a60
-                }
923a60
 
923a60
                 source->state = STATE_DATA_FINISH;
923a60
 
923a60
diff --git a/src/journal-remote/journal-remote-parse.h b/src/journal-remote/journal-remote-parse.h
923a60
index 8499f4eb82..22db550913 100644
923a60
--- a/src/journal-remote/journal-remote-parse.h
923a60
+++ b/src/journal-remote/journal-remote-parse.h
923a60
@@ -42,7 +42,9 @@ typedef struct RemoteSource {
923a60
         size_t offset;     /* offset to the beginning of live data in the buffer */
923a60
         size_t scanned;    /* number of bytes since the beginning of data without a newline */
923a60
         size_t filled;     /* total number of bytes in the buffer */
923a60
-        size_t data_size;  /* size of the binary data chunk being processed */
923a60
+
923a60
+        size_t field_len;  /* used for binary fields: the field name length */
923a60
+        size_t data_size;  /* and the size of the binary data chunk being processed */
923a60
 
923a60
         struct iovec_wrapper iovw;
923a60