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