|
|
a3e2b5 |
From 4339aa85279d268a671a656f142445559be771b7 Mon Sep 17 00:00:00 2001
|
|
|
a3e2b5 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
a3e2b5 |
Date: Wed, 14 Nov 2018 18:39:37 +0100
|
|
|
a3e2b5 |
Subject: [PATCH] format-table: make sure we never call memcmp() with NULL
|
|
|
a3e2b5 |
parameters
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
(cherry picked from commit 88db94fa57c9a5b1a0b926c49d3624fc84c88090)
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
Related: #1689832
|
|
|
a3e2b5 |
---
|
|
|
a3e2b5 |
src/basic/format-table.c | 2 +-
|
|
|
a3e2b5 |
src/basic/util.h | 9 +++++++++
|
|
|
a3e2b5 |
2 files changed, 10 insertions(+), 1 deletion(-)
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
diff --git a/src/basic/format-table.c b/src/basic/format-table.c
|
|
|
a3e2b5 |
index 0a1777e9a2..5517adad82 100644
|
|
|
a3e2b5 |
--- a/src/basic/format-table.c
|
|
|
a3e2b5 |
+++ b/src/basic/format-table.c
|
|
|
a3e2b5 |
@@ -291,7 +291,7 @@ static bool table_data_matches(
|
|
|
a3e2b5 |
if (k != l)
|
|
|
a3e2b5 |
return false;
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
- return memcmp(data, d->data, l) == 0;
|
|
|
a3e2b5 |
+ return memcmp_safe(data, d->data, l) == 0;
|
|
|
a3e2b5 |
}
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
static TableData *table_data_new(
|
|
|
a3e2b5 |
diff --git a/src/basic/util.h b/src/basic/util.h
|
|
|
a3e2b5 |
index 27b5a09782..b68ef25ed8 100644
|
|
|
a3e2b5 |
--- a/src/basic/util.h
|
|
|
a3e2b5 |
+++ b/src/basic/util.h
|
|
|
a3e2b5 |
@@ -123,6 +123,15 @@ static inline void memcpy_safe(void *dst, const void *src, size_t n) {
|
|
|
a3e2b5 |
memcpy(dst, src, n);
|
|
|
a3e2b5 |
}
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
+/* Normal memcmp requires s1 and s2 to be nonnull. We do nothing if n is 0. */
|
|
|
a3e2b5 |
+static inline int memcmp_safe(const void *s1, const void *s2, size_t n) {
|
|
|
a3e2b5 |
+ if (n == 0)
|
|
|
a3e2b5 |
+ return 0;
|
|
|
a3e2b5 |
+ assert(s1);
|
|
|
a3e2b5 |
+ assert(s2);
|
|
|
a3e2b5 |
+ return memcmp(s1, s2, n);
|
|
|
a3e2b5 |
+}
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
int on_ac_power(void);
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
#define memzero(x,l) (memset((x), 0, (l)))
|