[systemd-commits] src/journal src/shared

Lennart Poettering lennart at kemper.freedesktop.org
Thu Aug 9 07:50:13 PDT 2012


 src/journal/journald.c |   14 ++++++--------
 src/shared/util.c      |   20 ++++++++++++++++----
 src/shared/util.h      |    1 +
 3 files changed, 23 insertions(+), 12 deletions(-)

New commits:
commit 5b4c61cd0b7d35f5a905c83a0ee111a1876a7873
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Aug 9 16:49:28 2012 +0200

    journald: properly unescape messages from /dev/kmsg

diff --git a/src/journal/journald.c b/src/journal/journald.c
index d0c9618..765c0e3 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -1815,6 +1815,7 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) {
         usec_t usec;
         char *identifier = NULL, *pid = NULL, *e, *f, *k;
         uint64_t serial;
+        size_t pl;
 
         assert(s);
         assert(p);
@@ -1867,6 +1868,7 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) {
                 return;
         *e = 0;
 
+        pl = e - p;
         l -= (e - p) + 1;
         k = e + 1;
 
@@ -1885,16 +1887,12 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) {
 
                 *e = 0;
 
-                m = new(char, sizeof("_KERNEL_") - 1 + e - k);
+                m = cunescape_length_with_prefix(k, e - k, "_KERNEL_");
                 if (!m)
                         break;
 
-                memcpy(m, "_KERNEL_", sizeof("_KERNEL_") - 1);
-                memcpy(m + sizeof("_KERNEL_") - 1, k, e - k);
-
-                iovec[n].iov_base = m;
-                iovec[n].iov_len = sizeof("_KERNEL_") - 1 + e - k;
-                n++, z++;
+                IOVEC_SET_STRING(iovec[n++], m);
+                z++;
 
                 l -= (e - k) + 1;
                 k = e + 1;
@@ -1935,7 +1933,7 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) {
                         IOVEC_SET_STRING(iovec[n++], syslog_facility);
         }
 
-        message = strappend("MESSAGE=", p);
+        message = cunescape_length_with_prefix(p, pl, "MESSAGE=");
         if (message)
                 IOVEC_SET_STRING(iovec[n++], message);
 
diff --git a/src/shared/util.c b/src/shared/util.c
index af97595..946b7d5 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -1562,19 +1562,25 @@ char *cescape(const char *s) {
         return r;
 }
 
-char *cunescape_length(const char *s, size_t length) {
+char *cunescape_length_with_prefix(const char *s, size_t length, const char *prefix) {
         char *r, *t;
         const char *f;
+        size_t pl;
 
         assert(s);
 
-        /* Undoes C style string escaping */
+        /* Undoes C style string escaping, and optionally prefixes it. */
+
+        pl = prefix ? strlen(prefix) : 0;
 
-        r = new(char, length+1);
+        r = new(char, pl+length+1);
         if (!r)
                 return r;
 
-        for (f = s, t = r; f < s + length; f++) {
+        if (prefix)
+                memcpy(r, prefix, pl);
+
+        for (f = s, t = r + pl; f < s + length; f++) {
 
                 if (*f != '\\') {
                         *(t++) = *f;
@@ -1685,7 +1691,13 @@ finish:
         return r;
 }
 
+char *cunescape_length(const char *s, size_t length) {
+        return cunescape_length_with_prefix(s, length, NULL);
+}
+
 char *cunescape(const char *s) {
+        assert(s);
+
         return cunescape_length(s, strlen(s));
 }
 
diff --git a/src/shared/util.h b/src/shared/util.h
index b315593..d5a48eb 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -256,6 +256,7 @@ int undecchar(char c);
 char *cescape(const char *s);
 char *cunescape(const char *s);
 char *cunescape_length(const char *s, size_t length);
+char *cunescape_length_with_prefix(const char *s, size_t length, const char *prefix);
 
 char *xescape(const char *s, const char *bad);
 



More information about the systemd-commits mailing list