richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
572a44
From 072cebc2c736bec33e90299b49d82976c12b5549 Mon Sep 17 00:00:00 2001
572a44
From: Shawn Landden <shawn@churchofgit.com>
572a44
Date: Mon, 16 Dec 2013 15:41:00 -0800
572a44
Subject: [PATCH] journal: fix against (theoretical) undefined behavior
572a44
572a44
While all the libc implementations I know return NULL when memchr's size
572a44
parameter is 0, without accessing any memory, passing NULL to memchr is
572a44
still invalid:
572a44
572a44
C11 7.24.1p2: Where an argument declared as "size_t n" specifies the length
572a44
of the array for a function, n can have the value zero on a call to that
572a44
function. Unless explicitly stated otherwise in the description of a
572a44
particular function in this subclause, pointer arguments on such a call
572a44
shall still have valid values, as described in 7.1.4. On such a call, a
572a44
function that locates a character finds no occurrence, a function that
572a44
compares two character sequences returns zero, and a function that copies
572a44
characters copies zero characters.
572a44
572a44
see http://llvm.org/bugs/show_bug.cgi?id=18247
572a44
---
572a44
 src/journal/journal-file.c | 5 ++++-
572a44
 1 file changed, 4 insertions(+), 1 deletion(-)
572a44
572a44
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
572a44
index ebf72f3..2c0fd0c 100644
572a44
--- a/src/journal/journal-file.c
572a44
+++ b/src/journal/journal-file.c
572a44
@@ -1010,7 +1010,10 @@ static int journal_file_append_data(
572a44
         if (r < 0)
572a44
                 return r;
572a44
 
572a44
-        eq = memchr(data, '=', size);
572a44
+        if (!data)
572a44
+                eq = NULL;
572a44
+        else
572a44
+                eq = memchr(data, '=', size);
572a44
         if (eq && eq > data) {
572a44
                 uint64_t fp;
572a44
                 Object *fo;