systemd/0048-journald-process-binary-fields-the-same-as-text-fiel.patch

169 lines
7.6 KiB
Diff
Raw Normal View History

From 6a4bb8712d25a3e8e4700c7a3c6c9bd614c74d7f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Fri, 19 May 2017 11:59:47 -0400
Subject: [PATCH] journald: process "binary" fields the same as text fields
MESSAGE=data\n and MESSAGE\n40000000data\n are both valid serializations, so
they should be stored in the journal. Before, MESSAGE, SYSLOG_FACILITY,
SYSLOG_IDENTIFIER, PRIORITY, and OBJECT_PID would be only honoured if they were
given in the first form.
Fixed #5973.
(cherry picked from commit 4b29a7f41fa1f418520d66362fd904a504f67c02)
---
src/journal/journald-native.c | 120 ++++++++++++++++++++++++------------------
1 file changed, 70 insertions(+), 50 deletions(-)
diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c
index 83250c34e1..db3fdcf1df 100644
--- a/src/journal/journald-native.c
+++ b/src/journal/journald-native.c
@@ -81,6 +81,64 @@ static bool allow_object_pid(const struct ucred *ucred) {
return ucred && ucred->uid == 0;
}
+static void server_process_entry_meta(
+ const char *p, size_t l,
+ const struct ucred *ucred,
+ int *priority,
+ char **identifier,
+ char **message,
+ pid_t *object_pid) {
+
+ /* We need to determine the priority of this entry for the rate limiting logic */
+
+ if (l == 10 &&
+ startswith(p, "PRIORITY=") &&
+ p[9] >= '0' && p[9] <= '9')
+ *priority = (*priority & LOG_FACMASK) | (p[9] - '0');
+
+ else if (l == 17 &&
+ startswith(p, "SYSLOG_FACILITY=") &&
+ p[16] >= '0' && p[16] <= '9')
+ *priority = (*priority & LOG_PRIMASK) | ((p[16] - '0') << 3);
+
+ else if (l == 18 &&
+ startswith(p, "SYSLOG_FACILITY=") &&
+ p[16] >= '0' && p[16] <= '9' &&
+ p[17] >= '0' && p[17] <= '9')
+ *priority = (*priority & LOG_PRIMASK) | (((p[16] - '0')*10 + (p[17] - '0')) << 3);
+
+ else if (l >= 19 &&
+ startswith(p, "SYSLOG_IDENTIFIER=")) {
+ char *t;
+
+ t = strndup(p + 18, l - 18);
+ if (t) {
+ free(*identifier);
+ *identifier = t;
+ }
+
+ } else if (l >= 8 &&
+ startswith(p, "MESSAGE=")) {
+ char *t;
+
+ t = strndup(p + 8, l - 8);
+ if (t) {
+ free(*message);
+ *message = t;
+ }
+
+ } else if (l > strlen("OBJECT_PID=") &&
+ l < strlen("OBJECT_PID=") + DECIMAL_STR_MAX(pid_t) &&
+ startswith(p, "OBJECT_PID=") &&
+ allow_object_pid(ucred)) {
+ char buf[DECIMAL_STR_MAX(pid_t)];
+ memcpy(buf, p + strlen("OBJECT_PID="), l - strlen("OBJECT_PID="));
+ buf[l-strlen("OBJECT_PID=")] = '\0';
+
+ (void) parse_pid(buf, object_pid);
+ }
+}
+
static int server_process_entry(
Server *s,
const void *buffer, size_t *remaining,
@@ -148,62 +206,18 @@ static int server_process_entry(
/* If the field name starts with an
* underscore, skip the variable,
- * since that indidates a trusted
+ * since that indicates a trusted
* field */
iovec[n].iov_base = (char*) p;
iovec[n].iov_len = l;
entry_size += l;
n++;
- /* We need to determine the priority
- * of this entry for the rate limiting
- * logic */
- if (l == 10 &&
- startswith(p, "PRIORITY=") &&
- p[9] >= '0' && p[9] <= '9')
- priority = (priority & LOG_FACMASK) | (p[9] - '0');
-
- else if (l == 17 &&
- startswith(p, "SYSLOG_FACILITY=") &&
- p[16] >= '0' && p[16] <= '9')
- priority = (priority & LOG_PRIMASK) | ((p[16] - '0') << 3);
-
- else if (l == 18 &&
- startswith(p, "SYSLOG_FACILITY=") &&
- p[16] >= '0' && p[16] <= '9' &&
- p[17] >= '0' && p[17] <= '9')
- priority = (priority & LOG_PRIMASK) | (((p[16] - '0')*10 + (p[17] - '0')) << 3);
-
- else if (l >= 19 &&
- startswith(p, "SYSLOG_IDENTIFIER=")) {
- char *t;
-
- t = strndup(p + 18, l - 18);
- if (t) {
- free(identifier);
- identifier = t;
- }
-
- } else if (l >= 8 &&
- startswith(p, "MESSAGE=")) {
- char *t;
-
- t = strndup(p + 8, l - 8);
- if (t) {
- free(message);
- message = t;
- }
-
- } else if (l > strlen("OBJECT_PID=") &&
- l < strlen("OBJECT_PID=") + DECIMAL_STR_MAX(pid_t) &&
- startswith(p, "OBJECT_PID=") &&
- allow_object_pid(ucred)) {
- char buf[DECIMAL_STR_MAX(pid_t)];
- memcpy(buf, p + strlen("OBJECT_PID="), l - strlen("OBJECT_PID="));
- buf[l-strlen("OBJECT_PID=")] = '\0';
-
- (void) parse_pid(buf, &object_pid);
- }
+ server_process_entry_meta(p, l, ucred,
+ &priority,
+ &identifier,
+ &message,
+ &object_pid);
}
*remaining -= (e - p) + 1;
@@ -246,6 +260,12 @@ static int server_process_entry(
iovec[n].iov_len = (e - p) + 1 + l;
entry_size += iovec[n].iov_len;
n++;
+
+ server_process_entry_meta(k, (e - p) + 1 + l, ucred,
+ &priority,
+ &identifier,
+ &message,
+ &object_pid);
} else
free(k);