naccyde / rpms / systemd

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