|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From 0f99f74a14ef193c1ebde687c5cc76e1d67b85ef Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Date: Tue, 26 Aug 2014 23:54:31 -0400
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Subject: [PATCH] sd-journal: verify that object start with the field name
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
If the journal is corrupted, we might return an object that does
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
not start with the expected field name and/or is shorter than it
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
should.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/journal/journal-file.c | 1 -
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/journal/sd-journal.c | 15 +++++++++++++++
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
2 files changed, 15 insertions(+), 1 deletion(-)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index 986e94de39..7286e14ddb 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/journal/journal-file.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/journal/journal-file.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -425,7 +425,6 @@ int journal_file_move_to_object(JournalFile *f, int type, uint64_t offset, Objec
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (!VALID64(offset))
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return -EFAULT;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
r = journal_file_move_to(f, type_to_context(type), false, offset, sizeof(ObjectHeader), &t);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index 80ff8fef57..693707cb34 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/journal/sd-journal.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/journal/sd-journal.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -2571,6 +2571,21 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ /* Check if we have at least the field name and "=". */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (ol <= k) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ log_debug("%s:offset " OFSfmt ": object has size %zu, expected at least %zu",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ j->unique_file->path, j->unique_offset,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ ol, k + 1);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return -EBADMSG;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (memcmp(odata, j->unique_field, k) || ((const char*) odata)[k] != '=') {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ log_debug("%s:offset " OFSfmt ": object does not start with \"%s=\"",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ j->unique_file->path, j->unique_offset,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ j->unique_field);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return -EBADMSG;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
/* OK, now let's see if we already returned this data
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* object by checking if it exists in the earlier
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* traversed files. */
|