URL: https://github.com/SSSD/sssd/pull/741
Author: alexey-tikhonov
Title: #741: sbus/interface: fixed interface copy helpers
Action: opened
PR body:
"""
In `sbus_method_copy()` and other copy helpers there was code like:
```
copy = talloc_zero_array(mem_ctx, struct sbus_method, count + 1);
memcpy(copy, input, sizeof(struct sbus_method) * count + 1);
```
Copy of one byte of "sentinel" doesn't make a sense.
We can either rely on the fact that sentinel is zero-initialized struct
*and* `talloc_zero_array()` zero-initializes memory (so copying of
sentinel may be omitted at all) or just copy sentinel in a whole.
Opted for second option as more clear variant.
"""
To pull the PR as Git branch:
git remote add ghsssd https://github.com/SSSD/sssd
git fetch ghsssd pull/741/head:pr741
git checkout pr741
URL: https://github.com/SSSD/sssd/pull/740
Author: pbrezina
Title: #740: sbus: avoid using invalid stack point in SBUS_INTERFACE
Action: opened
PR body:
"""
SBUS_INTERFACE macros expanded as:
struct sbus_interface bus =
({ sbus_interface(
"org.freedesktop.DBus",
((void *)0),
(((const struct sbus_method[])
{
({
/* ... compile time check of function signature omitted */ ;
sbus_method_sync(/* ... full list of params omitted */);
}),
...
This however includes an issue that methods/properties/signals are returned
by value, however stored in sbus_interface as pointers. Once we return out
of the top-level block and assign resulting sbus_interface into 'bus' variable
those objects allocated on stack becomes invalid and can be overwritten by other
allocations on stack.
This patch overcomes this issue by changing declaration of SBUS_INTERFACE and
avoiding using this top-level block. This still keeps the declarative structure
and simplifies the code as it does not require any memory handling and
tests for successful allocations.
const struct sbus_method __ ## varname ## _m[] = methods; \
const struct sbus_signal __ ## varname ## _s[] = signals; \
const struct sbus_property __ ## varname ## _p[] = properties; \
struct sbus_interface varname = SBUS_IFACE_ ## iface( \
(__ ## varname ## _m), \
(__ ## varname ## _s), \
(__ ## varname ## _p) \
)
Resolves:
https://pagure.io/SSSD/sssd/issue/3924
"""
To pull the PR as Git branch:
git remote add ghsssd https://github.com/SSSD/sssd
git fetch ghsssd pull/740/head:pr740
git checkout pr740