sync patches from systemd community
This commit is contained in:
parent
d619bfe559
commit
57a6d23c09
@ -0,0 +1,115 @@
|
||||
From 49a5ae485df2a862c8da19175c4df65e5449e7ea Mon Sep 17 00:00:00 2001
|
||||
From: Siddhesh Poyarekar <siddhesh@gotplt.org>
|
||||
Date: Tue, 13 Dec 2022 16:54:36 -0500
|
||||
Subject: [PATCH] Use dummy allocator to make accesses defined as per standard
|
||||
|
||||
systemd uses malloc_usable_size() everywhere to use memory blocks
|
||||
obtained through malloc, but that is abuse since the
|
||||
malloc_usable_size() interface isn't meant for this kind of use, it is
|
||||
for diagnostics only. This is also why systemd behaviour is flaky when
|
||||
built with _FORTIFY_SOURCE.
|
||||
|
||||
One way to make this more standard (and hence safer) is to, at every
|
||||
malloc_usable_size() call, also 'reallocate' the block so that the
|
||||
compiler can see the larger size. This is done through a dummy
|
||||
reallocator whose only purpose is to tell the compiler about the larger
|
||||
usable size, it doesn't do any actual reallocation.
|
||||
|
||||
Florian Weimer pointed out that this doesn't solve the problem of an
|
||||
allocator potentially growing usable size at will, which will break the
|
||||
implicit assumption in systemd use that the value returned remains
|
||||
constant as long as the object is valid. The safest way to fix that is
|
||||
for systemd to step away from using malloc_usable_size() like this.
|
||||
|
||||
Resolves #22801.
|
||||
|
||||
---
|
||||
src/basic/alloc-util.c | 4 +++
|
||||
src/basic/alloc-util.h | 38 +++++++++++++++++++++--------
|
||||
src/fundamental/macro-fundamental.h | 1 +
|
||||
3 files changed, 33 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/src/basic/alloc-util.c b/src/basic/alloc-util.c
|
||||
index b030f45..6063943 100644
|
||||
--- a/src/basic/alloc-util.c
|
||||
+++ b/src/basic/alloc-util.c
|
||||
@@ -102,3 +102,7 @@ void* greedy_realloc0(
|
||||
|
||||
return q;
|
||||
}
|
||||
+
|
||||
+void *expand_to_usable(void *ptr, size_t newsize _unused_) {
|
||||
+ return ptr;
|
||||
+}
|
||||
diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h
|
||||
index 3c33308..e01ea72 100644
|
||||
--- a/src/basic/alloc-util.h
|
||||
+++ b/src/basic/alloc-util.h
|
||||
@@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <alloca.h>
|
||||
+#include <malloc.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -171,17 +172,34 @@ void* greedy_realloc0(void **p, size_t need, size_t size);
|
||||
# define msan_unpoison(r, s)
|
||||
#endif
|
||||
|
||||
-/* This returns the number of usable bytes in a malloc()ed region as per malloc_usable_size(), in a way that
|
||||
- * is compatible with _FORTIFY_SOURCES. If _FORTIFY_SOURCES is used many memory operations will take the
|
||||
- * object size as returned by __builtin_object_size() into account. Hence, let's return the smaller size of
|
||||
- * malloc_usable_size() and __builtin_object_size() here, so that we definitely operate in safe territory by
|
||||
- * both the compiler's and libc's standards. Note that __builtin_object_size() evaluates to SIZE_MAX if the
|
||||
- * size cannot be determined, hence the MIN() expression should be safe with dynamically sized memory,
|
||||
- * too. Moreover, when NULL is passed malloc_usable_size() is documented to return zero, and
|
||||
- * __builtin_object_size() returns SIZE_MAX too, hence we also return a sensible value of 0 in this corner
|
||||
- * case. */
|
||||
+/* Dummy allocator to tell the compiler that the new size of p is newsize. The implementation returns the
|
||||
+ * pointer as is; the only reason for its existence is as a conduit for the _alloc_ attribute. This cannot be
|
||||
+ * a static inline because gcc then loses the attributes on the function.
|
||||
+ * See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96503 */
|
||||
+void *expand_to_usable(void *p, size_t newsize) _alloc_(2) _returns_nonnull_;
|
||||
+
|
||||
+static inline size_t malloc_sizeof_safe(void **xp) {
|
||||
+ if (_unlikely_(!xp || !*xp))
|
||||
+ return 0;
|
||||
+
|
||||
+ size_t sz = malloc_usable_size(*xp);
|
||||
+ *xp = expand_to_usable(*xp, sz);
|
||||
+ /* GCC doesn't see the _returns_nonnull_ when built with ubsan, so yet another hint to make it doubly
|
||||
+ * clear that expand_to_usable won't return NULL.
|
||||
+ * See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79265 */
|
||||
+ if (!*xp)
|
||||
+ assert_not_reached("");
|
||||
+ return sz;
|
||||
+}
|
||||
+
|
||||
+/* This returns the number of usable bytes in a malloc()ed region as per malloc_usable_size(), which may
|
||||
+ * return a value larger than the size that was actually allocated. Access to that additional memory is
|
||||
+ * discouraged because it violates the C standard; a compiler cannot see that this as valid. To help the
|
||||
+ * compiler out, the MALLOC_SIZEOF_SAFE macro 'allocates' the usable size using a dummy allocator function
|
||||
+ * expand_to_usable. There is a possibility of malloc_usable_size() returning different values during the
|
||||
+ * lifetime of an object, which may cause problems, but the glibc allocator does not do that at the moment. */
|
||||
#define MALLOC_SIZEOF_SAFE(x) \
|
||||
- MIN(malloc_usable_size(x), __builtin_object_size(x, 0))
|
||||
+ malloc_sizeof_safe((void**) &__builtin_choose_expr(__builtin_constant_p(x), (void*) { NULL }, (x)))
|
||||
|
||||
/* Inspired by ELEMENTSOF() but operates on malloc()'ed memory areas: typesafely returns the number of items
|
||||
* that fit into the specified memory block */
|
||||
diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h
|
||||
index 9675186..2a2c0f8 100644
|
||||
--- a/src/fundamental/macro-fundamental.h
|
||||
+++ b/src/fundamental/macro-fundamental.h
|
||||
@@ -14,6 +14,7 @@
|
||||
#define _used_ __attribute__((__used__))
|
||||
#define _unused_ __attribute__((__unused__))
|
||||
#define _cleanup_(x) __attribute__((__cleanup__(x)))
|
||||
+#define _returns_nonnull_ __attribute__((__returns_nonnull__))
|
||||
|
||||
#define XSTRINGIFY(x) #x
|
||||
#define STRINGIFY(x) XSTRINGIFY(x)
|
||||
--
|
||||
2.33.0
|
||||
|
||||
36
backport-json-use-unsigned-for-refernce-counter.patch
Normal file
36
backport-json-use-unsigned-for-refernce-counter.patch
Normal file
@ -0,0 +1,36 @@
|
||||
From 6dd18b34cf53ab663140f43f8814904c71cc29f7 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Sun, 17 Apr 2022 06:46:25 +0900
|
||||
Subject: [PATCH] json: use unsigned for refernce counter
|
||||
|
||||
For other places, we use unsigned for reference counter.
|
||||
|
||||
---
|
||||
src/shared/json.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/shared/json.c b/src/shared/json.c
|
||||
index dff95eda26..f66b7df24c 100644
|
||||
--- a/src/shared/json.c
|
||||
+++ b/src/shared/json.c
|
||||
@@ -41,7 +41,7 @@ assert_cc(DEPTH_MAX <= UINT16_MAX);
|
||||
|
||||
typedef struct JsonSource {
|
||||
/* When we parse from a file or similar, encodes the filename, to indicate the source of a json variant */
|
||||
- size_t n_ref;
|
||||
+ unsigned n_ref;
|
||||
unsigned max_line;
|
||||
unsigned max_column;
|
||||
char name[];
|
||||
@@ -53,7 +53,7 @@ struct JsonVariant {
|
||||
/* We either maintain a reference counter for this variant itself, or we are embedded into an
|
||||
* array/object, in which case only that surrounding object is ref-counted. (If 'embedded' is false,
|
||||
* see below.) */
|
||||
- size_t n_ref;
|
||||
+ unsigned n_ref;
|
||||
|
||||
/* If this JsonVariant is part of an array/object, then this field points to the surrounding
|
||||
* JSON_VARIANT_ARRAY/JSON_VARIANT_OBJECT object. (If 'embedded' is true, see below.) */
|
||||
--
|
||||
2.33.0
|
||||
|
||||
31
backport-macro-check-over-flow-in-reference-counter.patch
Normal file
31
backport-macro-check-over-flow-in-reference-counter.patch
Normal file
@ -0,0 +1,31 @@
|
||||
From c8431e9e35a904673cf659fd238cb63b3c3896fc Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Sun, 17 Apr 2022 06:54:50 +0900
|
||||
Subject: [PATCH] macro: check over flow in reference counter
|
||||
|
||||
---
|
||||
src/basic/macro.h | 8 ++++++--
|
||||
1 file changed, 6 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/basic/macro.h b/src/basic/macro.h
|
||||
index 68d8b062e8..6e3966ff48 100644
|
||||
--- a/src/basic/macro.h
|
||||
+++ b/src/basic/macro.h
|
||||
@@ -396,8 +396,12 @@ static inline int __coverity_check_and_return__(int condition) {
|
||||
if (!p) \
|
||||
return NULL; \
|
||||
\
|
||||
- assert(p->n_ref > 0); \
|
||||
- p->n_ref++; \
|
||||
+ /* For type check. */ \
|
||||
+ unsigned *q = &p->n_ref; \
|
||||
+ assert(*q > 0); \
|
||||
+ assert(*q < UINT_MAX); \
|
||||
+ \
|
||||
+ (*q)++; \
|
||||
return p; \
|
||||
}
|
||||
|
||||
--
|
||||
2.33.0
|
||||
|
||||
32
backport-sd-bus-do-not-read-unused-value.patch
Normal file
32
backport-sd-bus-do-not-read-unused-value.patch
Normal file
@ -0,0 +1,32 @@
|
||||
From 6a7ca27740be4229b4c9f540cd610b205ca5752c Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Sun, 17 Apr 2022 07:25:09 +0900
|
||||
Subject: [PATCH] sd-bus: do not read unused value
|
||||
|
||||
---
|
||||
src/libsystemd/sd-bus/bus-track.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c
|
||||
index 135dfddc5f..1cbdb46f4c 100644
|
||||
--- a/src/libsystemd/sd-bus/bus-track.c
|
||||
+++ b/src/libsystemd/sd-bus/bus-track.c
|
||||
@@ -165,13 +165,13 @@ DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_bus_track, sd_bus_track, track_free);
|
||||
|
||||
static int on_name_owner_changed(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
sd_bus_track *track = userdata;
|
||||
- const char *name, *old, *new;
|
||||
+ const char *name;
|
||||
int r;
|
||||
|
||||
assert(message);
|
||||
assert(track);
|
||||
|
||||
- r = sd_bus_message_read(message, "sss", &name, &old, &new);
|
||||
+ r = sd_bus_message_read(message, "sss", &name, NULL, NULL);
|
||||
if (r < 0)
|
||||
return 0;
|
||||
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
From 55bfacc6c33eaf3475762e71172b2ef504be5af8 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Sun, 17 Apr 2022 07:29:24 +0900
|
||||
Subject: [PATCH] sd-bus: do not return negative errno when unknown name is
|
||||
specified
|
||||
|
||||
When 'recursive' is false, then sd_bus_track_remove_name() does not
|
||||
return negative errno when unknown name is specified. Let's follow the
|
||||
same pattern for the case that 'recursive' is true.
|
||||
|
||||
---
|
||||
src/libsystemd/sd-bus/bus-track.c | 5 +----
|
||||
1 file changed, 1 insertion(+), 4 deletions(-)
|
||||
|
||||
diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c
|
||||
index 1cbdb46f4c..c56bd03fc6 100644
|
||||
--- a/src/libsystemd/sd-bus/bus-track.c
|
||||
+++ b/src/libsystemd/sd-bus/bus-track.c
|
||||
@@ -256,12 +256,9 @@ _public_ int sd_bus_track_remove_name(sd_bus_track *track, const char *name) {
|
||||
if (!track) /* Treat a NULL track object as an empty track object */
|
||||
return 0;
|
||||
|
||||
- if (!track->recursive)
|
||||
- return bus_track_remove_name_fully(track, name);
|
||||
-
|
||||
i = hashmap_get(track->names, name);
|
||||
if (!i)
|
||||
- return -EUNATCH;
|
||||
+ return 0;
|
||||
|
||||
assert(i->n_ref >= 1);
|
||||
if (i->n_ref <= 1)
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
From b21f237d996c8c18991a68e1204f060d07dc4745 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Sun, 17 Apr 2022 07:05:07 +0900
|
||||
Subject: [PATCH] sd-bus: fix reference counter to be incremented
|
||||
|
||||
Fixes #23097.
|
||||
|
||||
---
|
||||
src/libsystemd/sd-bus/bus-track.c | 6 +++---
|
||||
1 file changed, 3 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c
|
||||
index bc36673b83..891fd0c899 100644
|
||||
--- a/src/libsystemd/sd-bus/bus-track.c
|
||||
+++ b/src/libsystemd/sd-bus/bus-track.c
|
||||
@@ -191,12 +191,12 @@ _public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) {
|
||||
i = hashmap_get(track->names, name);
|
||||
if (i) {
|
||||
if (track->recursive) {
|
||||
- unsigned k = track->n_ref + 1;
|
||||
+ unsigned k = i->n_ref + 1;
|
||||
|
||||
- if (k < track->n_ref) /* Check for overflow */
|
||||
+ if (k < i->n_ref) /* Check for overflow */
|
||||
return -EOVERFLOW;
|
||||
|
||||
- track->n_ref = k;
|
||||
+ i->n_ref = k;
|
||||
}
|
||||
|
||||
bus_track_remove_from_queue(track);
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,105 @@
|
||||
From c2d7dd35d2a8cda439384a385b0c1bec804b9b79 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Sun, 17 Apr 2022 07:20:16 +0900
|
||||
Subject: [PATCH] sd-bus: introduce ref/unref function for track_item
|
||||
|
||||
---
|
||||
src/libsystemd/sd-bus/bus-track.c | 35 ++++++++++++++-----------------
|
||||
1 file changed, 16 insertions(+), 19 deletions(-)
|
||||
|
||||
diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c
|
||||
index 891fd0c899..135dfddc5f 100644
|
||||
--- a/src/libsystemd/sd-bus/bus-track.c
|
||||
+++ b/src/libsystemd/sd-bus/bus-track.c
|
||||
@@ -40,7 +40,6 @@ struct sd_bus_track {
|
||||
"arg0='", name, "'")
|
||||
|
||||
static struct track_item* track_item_free(struct track_item *i) {
|
||||
-
|
||||
if (!i)
|
||||
return NULL;
|
||||
|
||||
@@ -49,7 +48,8 @@ static struct track_item* track_item_free(struct track_item *i) {
|
||||
return mfree(i);
|
||||
}
|
||||
|
||||
-DEFINE_TRIVIAL_CLEANUP_FUNC(struct track_item*, track_item_free);
|
||||
+DEFINE_PRIVATE_TRIVIAL_REF_UNREF_FUNC(struct track_item, track_item, track_item_free);
|
||||
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct track_item*, track_item_unref);
|
||||
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(track_item_hash_ops, char, string_hash_func, string_compare_func,
|
||||
struct track_item, track_item_free);
|
||||
|
||||
@@ -180,7 +180,7 @@ static int on_name_owner_changed(sd_bus_message *message, void *userdata, sd_bus
|
||||
}
|
||||
|
||||
_public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) {
|
||||
- _cleanup_(track_item_freep) struct track_item *n = NULL;
|
||||
+ _cleanup_(track_item_unrefp) struct track_item *n = NULL;
|
||||
struct track_item *i;
|
||||
const char *match;
|
||||
int r;
|
||||
@@ -190,14 +190,8 @@ _public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) {
|
||||
|
||||
i = hashmap_get(track->names, name);
|
||||
if (i) {
|
||||
- if (track->recursive) {
|
||||
- unsigned k = i->n_ref + 1;
|
||||
-
|
||||
- if (k < i->n_ref) /* Check for overflow */
|
||||
- return -EOVERFLOW;
|
||||
-
|
||||
- i->n_ref = k;
|
||||
- }
|
||||
+ if (track->recursive)
|
||||
+ track_item_ref(i);
|
||||
|
||||
bus_track_remove_from_queue(track);
|
||||
return 0;
|
||||
@@ -207,9 +201,14 @@ _public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
- n = new0(struct track_item, 1);
|
||||
+ n = new(struct track_item, 1);
|
||||
if (!n)
|
||||
return -ENOMEM;
|
||||
+
|
||||
+ *n = (struct track_item) {
|
||||
+ .n_ref = 1,
|
||||
+ };
|
||||
+
|
||||
n->name = strdup(name);
|
||||
if (!n->name)
|
||||
return -ENOMEM;
|
||||
@@ -241,8 +240,7 @@ _public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) {
|
||||
return r;
|
||||
}
|
||||
|
||||
- n->n_ref = 1;
|
||||
- n = NULL;
|
||||
+ TAKE_PTR(n);
|
||||
|
||||
bus_track_remove_from_queue(track);
|
||||
track->modified = true;
|
||||
@@ -264,14 +262,13 @@ _public_ int sd_bus_track_remove_name(sd_bus_track *track, const char *name) {
|
||||
i = hashmap_get(track->names, name);
|
||||
if (!i)
|
||||
return -EUNATCH;
|
||||
- if (i->n_ref <= 0)
|
||||
- return -EUNATCH;
|
||||
|
||||
- i->n_ref--;
|
||||
-
|
||||
- if (i->n_ref <= 0)
|
||||
+ assert(i->n_ref >= 1);
|
||||
+ if (i->n_ref <= 1)
|
||||
return bus_track_remove_name_fully(track, name);
|
||||
|
||||
+ track_item_unref(i);
|
||||
+
|
||||
return 1;
|
||||
}
|
||||
|
||||
--
|
||||
2.33.0
|
||||
|
||||
51
backport-sd-bus-switch-to-a-manual-overflow-check-in.patch
Normal file
51
backport-sd-bus-switch-to-a-manual-overflow-check-in.patch
Normal file
@ -0,0 +1,51 @@
|
||||
From 65d848e9b31bdc6caedcac378375943e72d1011f Mon Sep 17 00:00:00 2001
|
||||
From: Lennart Poettering <lennart@poettering.net>
|
||||
Date: Wed, 20 Apr 2022 22:30:22 +0200
|
||||
Subject: [PATCH] sd-bus: switch to a manual overflow check in
|
||||
sd_bus_track_add_name()
|
||||
|
||||
This is generally used in a directly client controllable way, hence we
|
||||
should handle ref count overflow gracefully, instead of hitting an
|
||||
assert().
|
||||
|
||||
As discussed:
|
||||
|
||||
https://github.com/systemd/systemd/pull/23099#discussion_r854341850
|
||||
---
|
||||
src/libsystemd/sd-bus/bus-track.c | 16 +++++++++++++---
|
||||
1 file changed, 13 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c
|
||||
index 4c44162108c4d..e403555f8f83c 100644
|
||||
--- a/src/libsystemd/sd-bus/bus-track.c
|
||||
+++ b/src/libsystemd/sd-bus/bus-track.c
|
||||
@@ -48,7 +48,7 @@ static struct track_item* track_item_free(struct track_item *i) {
|
||||
return mfree(i);
|
||||
}
|
||||
|
||||
-DEFINE_PRIVATE_TRIVIAL_REF_UNREF_FUNC(struct track_item, track_item, track_item_free);
|
||||
+DEFINE_PRIVATE_TRIVIAL_UNREF_FUNC(struct track_item, track_item, track_item_free);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(struct track_item*, track_item_unref);
|
||||
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(track_item_hash_ops, char, string_hash_func, string_compare_func,
|
||||
struct track_item, track_item_free);
|
||||
@@ -190,8 +190,18 @@ _public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) {
|
||||
|
||||
i = hashmap_get(track->names, name);
|
||||
if (i) {
|
||||
- if (track->recursive)
|
||||
- track_item_ref(i);
|
||||
+ if (track->recursive) {
|
||||
+ assert(i->n_ref > 0);
|
||||
+
|
||||
+ /* Manual oveflow check (instead of a DEFINE_TRIVIAL_REF_FUNC() helper or so), so
|
||||
+ * that we can return a proper error, given this is almost always called in a
|
||||
+ * directly client controllable way, and thus better should never hit an assertion
|
||||
+ * here. */
|
||||
+ if (i->n_ref >= UINT_MAX)
|
||||
+ return -EOVERFLOW;
|
||||
+
|
||||
+ i->n_ref++;
|
||||
+ }
|
||||
|
||||
bus_track_remove_from_queue(track);
|
||||
return 0;
|
||||
@ -0,0 +1,25 @@
|
||||
From c399ed923d6fa4bf731455d485cac5f00e060806 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Sun, 17 Apr 2022 08:00:20 +0900
|
||||
Subject: [PATCH] sd-bus: use hashmap_contains() and drop unnecessary cast
|
||||
|
||||
---
|
||||
src/libsystemd/sd-bus/bus-track.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c
|
||||
index c56bd03fc6..4c44162108 100644
|
||||
--- a/src/libsystemd/sd-bus/bus-track.c
|
||||
+++ b/src/libsystemd/sd-bus/bus-track.c
|
||||
@@ -287,7 +287,7 @@ _public_ const char* sd_bus_track_contains(sd_bus_track *track, const char *name
|
||||
if (!track) /* Let's consider a NULL object equivalent to an empty object */
|
||||
return NULL;
|
||||
|
||||
- return hashmap_get(track->names, (void*) name) ? name : NULL;
|
||||
+ return hashmap_contains(track->names, name) ? name : NULL;
|
||||
}
|
||||
|
||||
_public_ const char* sd_bus_track_first(sd_bus_track *track) {
|
||||
--
|
||||
2.33.0
|
||||
|
||||
97
backport-test-add-several-tests-for-track-item.patch
Normal file
97
backport-test-add-several-tests-for-track-item.patch
Normal file
@ -0,0 +1,97 @@
|
||||
From 056a18e465bedb1bd35ce0bf78831be168c636cb Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Sun, 17 Apr 2022 07:58:45 +0900
|
||||
Subject: [PATCH] test: add several tests for track item
|
||||
|
||||
---
|
||||
src/libsystemd/sd-bus/test-bus-track.c | 58 +++++++++++++++++++++++++-
|
||||
1 file changed, 57 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/libsystemd/sd-bus/test-bus-track.c b/src/libsystemd/sd-bus/test-bus-track.c
|
||||
index 238934a880..5604e84f52 100644
|
||||
--- a/src/libsystemd/sd-bus/test-bus-track.c
|
||||
+++ b/src/libsystemd/sd-bus/test-bus-track.c
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
static bool track_cb_called_x = false;
|
||||
static bool track_cb_called_y = false;
|
||||
+static bool track_destroy_called_z = false;
|
||||
|
||||
static int track_cb_x(sd_bus_track *t, void *userdata) {
|
||||
|
||||
@@ -39,9 +40,17 @@ static int track_cb_y(sd_bus_track *t, void *userdata) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static int track_cb_z(sd_bus_track *t, void *userdata) {
|
||||
+ assert_not_reached("");
|
||||
+}
|
||||
+
|
||||
+static void track_destroy_z(void *userdata) {
|
||||
+ track_destroy_called_z = true;
|
||||
+}
|
||||
+
|
||||
int main(int argc, char *argv[]) {
|
||||
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
|
||||
- _cleanup_(sd_bus_track_unrefp) sd_bus_track *x = NULL, *y = NULL;
|
||||
+ _cleanup_(sd_bus_track_unrefp) sd_bus_track *x = NULL, *y = NULL, *z = NULL;
|
||||
_cleanup_(sd_bus_unrefp) sd_bus *a = NULL, *b = NULL;
|
||||
bool use_system_bus = false;
|
||||
const char *unique;
|
||||
@@ -83,6 +92,53 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
assert_se(sd_bus_track_add_name(y, unique) >= 0);
|
||||
|
||||
+ /* Basic tests. */
|
||||
+ assert_se(sd_bus_track_new(a, &z, track_cb_z, NULL) >= 0);
|
||||
+
|
||||
+ /* non-recursive case */
|
||||
+ assert_se(sd_bus_track_set_recursive(z, false) >= 0);
|
||||
+ assert_se(sd_bus_track_get_recursive(z) == 0);
|
||||
+ assert_se(!sd_bus_track_contains(z, unique));
|
||||
+ assert_se(sd_bus_track_count_name(z, unique) == 0);
|
||||
+ assert_se(sd_bus_track_remove_name(z, unique) == 0);
|
||||
+ assert_se(sd_bus_track_add_name(z, unique) >= 0);
|
||||
+ assert_se(sd_bus_track_add_name(z, unique) >= 0);
|
||||
+ assert_se(sd_bus_track_add_name(z, unique) >= 0);
|
||||
+ assert_se(sd_bus_track_set_recursive(z, true) == -EBUSY);
|
||||
+ assert_se(sd_bus_track_contains(z, unique));
|
||||
+ assert_se(sd_bus_track_count_name(z, unique) == 1);
|
||||
+ assert_se(sd_bus_track_remove_name(z, unique) == 1);
|
||||
+ assert_se(!sd_bus_track_contains(z, unique));
|
||||
+ assert_se(sd_bus_track_count_name(z, unique) == 0);
|
||||
+ assert_se(sd_bus_track_remove_name(z, unique) == 0);
|
||||
+
|
||||
+ /* recursive case */
|
||||
+ assert_se(sd_bus_track_set_recursive(z, true) >= 0);
|
||||
+ assert_se(sd_bus_track_get_recursive(z) == 1);
|
||||
+ assert_se(!sd_bus_track_contains(z, unique));
|
||||
+ assert_se(sd_bus_track_count_name(z, unique) == 0);
|
||||
+ assert_se(sd_bus_track_remove_name(z, unique) == 0);
|
||||
+ assert_se(sd_bus_track_add_name(z, unique) >= 0);
|
||||
+ assert_se(sd_bus_track_add_name(z, unique) >= 0);
|
||||
+ assert_se(sd_bus_track_add_name(z, unique) >= 0);
|
||||
+ assert_se(sd_bus_track_set_recursive(z, false) == -EBUSY);
|
||||
+ assert_se(sd_bus_track_contains(z, unique));
|
||||
+ assert_se(sd_bus_track_count_name(z, unique) == 3);
|
||||
+ assert_se(sd_bus_track_remove_name(z, unique) == 1);
|
||||
+ assert_se(sd_bus_track_contains(z, unique));
|
||||
+ assert_se(sd_bus_track_count_name(z, unique) == 2);
|
||||
+ assert_se(sd_bus_track_remove_name(z, unique) == 1);
|
||||
+ assert_se(sd_bus_track_contains(z, unique));
|
||||
+ assert_se(sd_bus_track_count_name(z, unique) == 1);
|
||||
+ assert_se(sd_bus_track_remove_name(z, unique) == 1);
|
||||
+ assert_se(!sd_bus_track_contains(z, unique));
|
||||
+ assert_se(sd_bus_track_count_name(z, unique) == 0);
|
||||
+ assert_se(sd_bus_track_remove_name(z, unique) == 0);
|
||||
+
|
||||
+ assert_se(sd_bus_track_set_destroy_callback(z, track_destroy_z) >= 0);
|
||||
+ z = sd_bus_track_unref(z);
|
||||
+ assert_se(track_destroy_called_z);
|
||||
+
|
||||
/* Now make b's name disappear */
|
||||
sd_bus_close(b);
|
||||
|
||||
--
|
||||
2.33.0
|
||||
|
||||
99
backport-test-shorten-code-a-bit.patch
Normal file
99
backport-test-shorten-code-a-bit.patch
Normal file
@ -0,0 +1,99 @@
|
||||
From 63ec7a849039fab830961fd7fee0c1e266735fc8 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Sun, 17 Apr 2022 07:35:05 +0900
|
||||
Subject: [PATCH] test: shorten code a bit
|
||||
|
||||
---
|
||||
src/libsystemd/sd-bus/test-bus-track.c | 39 +++++++++-----------------
|
||||
1 file changed, 13 insertions(+), 26 deletions(-)
|
||||
|
||||
diff --git a/src/libsystemd/sd-bus/test-bus-track.c b/src/libsystemd/sd-bus/test-bus-track.c
|
||||
index 64aa88bb4f..238934a880 100644
|
||||
--- a/src/libsystemd/sd-bus/test-bus-track.c
|
||||
+++ b/src/libsystemd/sd-bus/test-bus-track.c
|
||||
@@ -26,7 +26,6 @@ static int track_cb_x(sd_bus_track *t, void *userdata) {
|
||||
}
|
||||
|
||||
static int track_cb_y(sd_bus_track *t, void *userdata) {
|
||||
- int r;
|
||||
|
||||
log_error("TRACK CB Y");
|
||||
|
||||
@@ -35,8 +34,7 @@ static int track_cb_y(sd_bus_track *t, void *userdata) {
|
||||
|
||||
/* We got disconnected, let's close everything */
|
||||
|
||||
- r = sd_event_exit(sd_bus_get_event(sd_bus_track_get_bus(t)), EXIT_SUCCESS);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(sd_event_exit(sd_bus_get_event(sd_bus_track_get_bus(t)), EXIT_SUCCESS) >= 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -51,8 +49,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
- r = sd_event_default(&event);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(sd_event_default(&event) >= 0);
|
||||
|
||||
r = sd_bus_open_user(&a);
|
||||
if (IN_SET(r, -ECONNREFUSED, -ENOENT, -ENOMEDIUM)) {
|
||||
@@ -63,43 +60,33 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
assert_se(r >= 0);
|
||||
|
||||
- r = sd_bus_attach_event(a, event, SD_EVENT_PRIORITY_NORMAL);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(sd_bus_attach_event(a, event, SD_EVENT_PRIORITY_NORMAL) >= 0);
|
||||
|
||||
if (use_system_bus)
|
||||
- r = sd_bus_open_system(&b);
|
||||
+ assert_se(sd_bus_open_system(&b) >= 0);
|
||||
else
|
||||
- r = sd_bus_open_user(&b);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(sd_bus_open_user(&b) >= 0);
|
||||
|
||||
- r = sd_bus_attach_event(b, event, SD_EVENT_PRIORITY_NORMAL);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(sd_bus_attach_event(b, event, SD_EVENT_PRIORITY_NORMAL) >= 0);
|
||||
|
||||
/* Watch b's name from a */
|
||||
- r = sd_bus_track_new(a, &x, track_cb_x, NULL);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(sd_bus_track_new(a, &x, track_cb_x, NULL) >= 0);
|
||||
|
||||
- r = sd_bus_get_unique_name(b, &unique);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(sd_bus_get_unique_name(b, &unique) >= 0);
|
||||
|
||||
- r = sd_bus_track_add_name(x, unique);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(sd_bus_track_add_name(x, unique) >= 0);
|
||||
|
||||
/* Watch's a's own name from a */
|
||||
- r = sd_bus_track_new(a, &y, track_cb_y, NULL);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(sd_bus_track_new(a, &y, track_cb_y, NULL) >= 0);
|
||||
|
||||
- r = sd_bus_get_unique_name(a, &unique);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(sd_bus_get_unique_name(a, &unique) >= 0);
|
||||
|
||||
- r = sd_bus_track_add_name(y, unique);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(sd_bus_track_add_name(y, unique) >= 0);
|
||||
|
||||
/* Now make b's name disappear */
|
||||
sd_bus_close(b);
|
||||
|
||||
- r = sd_event_loop(event);
|
||||
- assert_se(r >= 0);
|
||||
+ assert_se(sd_event_loop(event) >= 0);
|
||||
|
||||
assert_se(track_cb_called_x);
|
||||
assert_se(track_cb_called_y);
|
||||
--
|
||||
2.33.0
|
||||
|
||||
26
systemd.spec
26
systemd.spec
@ -21,7 +21,7 @@
|
||||
Name: systemd
|
||||
Url: https://www.freedesktop.org/wiki/Software/systemd
|
||||
Version: 249
|
||||
Release: 60
|
||||
Release: 61
|
||||
License: MIT and LGPLv2+ and GPLv2+
|
||||
Summary: System and Service Manager
|
||||
|
||||
@ -598,6 +598,17 @@ Patch6549: backport-udev-builtin-net_id-fix-potential-buffer-overflow.patch
|
||||
Patch6550: backport-hostname-Make-sure-we-pass-error-to-bus_verify_polki.patch
|
||||
Patch6551: backport-Limit-rlim_max-in-rlimit_nofile_safe-to-nr_open.patch
|
||||
Patch6552: backport-udev-raise-RLIMIT_NOFILE-as-high-as-we-can.patch
|
||||
Patch6553: backport-json-use-unsigned-for-refernce-counter.patch
|
||||
Patch6554: backport-macro-check-over-flow-in-reference-counter.patch
|
||||
Patch6555: backport-sd-bus-fix-reference-counter-to-be-incremented.patch
|
||||
Patch6556: backport-sd-bus-introduce-ref-unref-function-for-track_item.patch
|
||||
Patch6557: backport-sd-bus-do-not-read-unused-value.patch
|
||||
Patch6558: backport-sd-bus-do-not-return-negative-errno-when-unknown-nam.patch
|
||||
Patch6559: backport-sd-bus-use-hashmap_contains-and-drop-unnecessary-cas.patch
|
||||
Patch6560: backport-test-shorten-code-a-bit.patch
|
||||
Patch6561: backport-test-add-several-tests-for-track-item.patch
|
||||
Patch6562: backport-sd-bus-switch-to-a-manual-overflow-check-in.patch
|
||||
Patch6563: backport-Use-dummy-allocator-to-make-accesses-defined-as-per-standard.patch
|
||||
|
||||
Patch9001: update-rtc-with-system-clock-when-shutdown.patch
|
||||
Patch9002: udev-add-actions-while-rename-netif-failed.patch
|
||||
@ -2094,6 +2105,19 @@ grep -q -E '^KEYMAP="?fi-latin[19]"?' /etc/vconsole.conf 2>/dev/null &&
|
||||
%{_libdir}/security/pam_systemd.so
|
||||
|
||||
%changelog
|
||||
* Mon Dec 18 2023 hongjinghao <hongjinghao@huawei.com> - 249-61
|
||||
- add: backport-json-use-unsigned-for-refernce-counter.patch
|
||||
backport-macro-check-over-flow-in-reference-counter.patch
|
||||
backport-sd-bus-fix-reference-counter-to-be-incremented.patch
|
||||
backport-sd-bus-introduce-ref-unref-function-for-track_item.patch
|
||||
backport-sd-bus-do-not-read-unused-value.patch
|
||||
backport-sd-bus-do-not-return-negative-errno-when-unknown-nam.patch
|
||||
backport-sd-bus-use-hashmap_contains-and-drop-unnecessary-cas.patch
|
||||
backport-test-shorten-code-a-bit.patch
|
||||
backport-test-add-several-tests-for-track-item.patch
|
||||
backport-Use-dummy-allocator-to-make-accesses-defined-as-per-standard.patch
|
||||
backport-sd-bus-switch-to-a-manual-overflow-check-in.patch
|
||||
|
||||
* Mon Dec 18 2023 huyubiao <huyubiao@huawei.com> - 249-60
|
||||
- backport: sync patches from systemd community
|
||||
add backport-core-path-do-not-enqueue-new-job-in-.trigger_notify-.patch
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user