mirror of
https://github.com/systemd/systemd.git
synced 2025-03-09 12:58:26 +03:00
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.
This commit is contained in:
parent
68944f196b
commit
4b29a7f41f
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user