resolved: always initialize Varlink->userdata by topimiettinen · Pull Request #18248 · systemd/systemd · GitHub
Skip to content

resolved: always initialize Varlink->userdata#18248

Closed
topimiettinen wants to merge 1 commit into
systemd:masterfrom
topimiettinen:varlink-fix-userdata
Closed

resolved: always initialize Varlink->userdata#18248
topimiettinen wants to merge 1 commit into
systemd:masterfrom
topimiettinen:varlink-fix-userdata

Conversation

@topimiettinen

Copy link
Copy Markdown
Contributor

Varlink->userdata is initialized as VarlinkServer->userdata, so for resolved it
points to a Manager, but actually the error paths expect a non-NULL pointer to
refer to a DnsQuery. So let's initialize Varlink->userdata as NULL.

Varlink->userdata is initialized as VarlinkServer->userdata, so for resolved it
points to a Manager, but actually the error paths expect a non-NULL pointer to
refer to a DnsQuery. So let's initialize Varlink->userdata as NULL.
@topimiettinen topimiettinen added bug 🐛 Programming errors, that need preferential fixing resolve labels Jan 14, 2021
@keszybz

keszybz commented Jan 15, 2021

Copy link
Copy Markdown
Member

@topimiettinen

Copy link
Copy Markdown
Contributor Author

Please correct me if I misunderstood, but there are two objects related to varlink: VarlinkServer object which produces Varlink objects. Both have a field userdata to be used by the callback functions so that they can access state information from higher level. Currently Varlink->userdata is initialized from VarlinkServer->userdata and this is wrong for resolved. If the callbacks should not modify the Varlink->userdata at all, how should they get the right data that they need? Should varlink_set_userdata() be removed completely?

I think another option could be that Varlink->userdata should be zero initialized instead. This would work for resolved, but not for the other user for Varlink->userdata which seems to be only journald. So it would need to use varlink_set_userdata() to set the Varlink->userdata to refer to a Server object.

poettering added a commit to poettering/systemd that referenced this pull request Jan 20, 2021
…onnection optional

@keszybz's right on
systemd#18248 (comment):
swapping out the userdata pointer of a live varlink connection is iffy.

Let's fix this by making the userdata inheritance from VarlinkServer
object to the Varlink connection object optional: we want it for most
cases, but not all, i.e. all those cases where the calls implemented as
varlink methods are stateless and can be answered synchronously. For the
other cases (i.e. where we want per-connection objects that wrap the
asynchronous operation as it goes on) let's not do such inheritance but
initialize the userdata pointer only once we have it. THis means the
original manager object must be manually retrieved from the
VarlinkServer object, which in turn needs to be requested from the
Varlink connection object.

The userdata inheritance is now controlled by the
VARLINK_INHERIT_USERDATA flag passed at VarlinkServer construction.

Alternative-to: systemd#18248
@poettering

Copy link
Copy Markdown
Member

My proposal to fix this:

#18328

ptal

@bluca

bluca commented Jan 20, 2021

Copy link
Copy Markdown
Member

@bluca bluca closed this Jan 20, 2021
yuwata pushed a commit that referenced this pull request Jan 20, 2021
…onnection optional

@keszybz's right on
#18248 (comment):
swapping out the userdata pointer of a live varlink connection is iffy.

Let's fix this by making the userdata inheritance from VarlinkServer
object to the Varlink connection object optional: we want it for most
cases, but not all, i.e. all those cases where the calls implemented as
varlink methods are stateless and can be answered synchronously. For the
other cases (i.e. where we want per-connection objects that wrap the
asynchronous operation as it goes on) let's not do such inheritance but
initialize the userdata pointer only once we have it. THis means the
original manager object must be manually retrieved from the
VarlinkServer object, which in turn needs to be requested from the
Varlink connection object.

The userdata inheritance is now controlled by the
VARLINK_INHERIT_USERDATA flag passed at VarlinkServer construction.

Alternative-to: #18248
borna-blazevic pushed a commit to sartura/systemd that referenced this pull request Mar 1, 2021
…onnection optional

@keszybz's right on
systemd#18248 (comment):
swapping out the userdata pointer of a live varlink connection is iffy.

Let's fix this by making the userdata inheritance from VarlinkServer
object to the Varlink connection object optional: we want it for most
cases, but not all, i.e. all those cases where the calls implemented as
varlink methods are stateless and can be answered synchronously. For the
other cases (i.e. where we want per-connection objects that wrap the
asynchronous operation as it goes on) let's not do such inheritance but
initialize the userdata pointer only once we have it. THis means the
original manager object must be manually retrieved from the
VarlinkServer object, which in turn needs to be requested from the
Varlink connection object.

The userdata inheritance is now controlled by the
VARLINK_INHERIT_USERDATA flag passed at VarlinkServer construction.

Alternative-to: systemd#18248
borna-blazevic pushed a commit to sartura/systemd that referenced this pull request Mar 1, 2021
…onnection optional

@keszybz's right on
systemd#18248 (comment):
swapping out the userdata pointer of a live varlink connection is iffy.

Let's fix this by making the userdata inheritance from VarlinkServer
object to the Varlink connection object optional: we want it for most
cases, but not all, i.e. all those cases where the calls implemented as
varlink methods are stateless and can be answered synchronously. For the
other cases (i.e. where we want per-connection objects that wrap the
asynchronous operation as it goes on) let's not do such inheritance but
initialize the userdata pointer only once we have it. THis means the
original manager object must be manually retrieved from the
VarlinkServer object, which in turn needs to be requested from the
Varlink connection object.

The userdata inheritance is now controlled by the
VARLINK_INHERIT_USERDATA flag passed at VarlinkServer construction.

Alternative-to: systemd#18248
borna-blazevic pushed a commit to sartura/systemd that referenced this pull request Mar 1, 2021
…onnection optional

@keszybz's right on
systemd#18248 (comment):
swapping out the userdata pointer of a live varlink connection is iffy.

Let's fix this by making the userdata inheritance from VarlinkServer
object to the Varlink connection object optional: we want it for most
cases, but not all, i.e. all those cases where the calls implemented as
varlink methods are stateless and can be answered synchronously. For the
other cases (i.e. where we want per-connection objects that wrap the
asynchronous operation as it goes on) let's not do such inheritance but
initialize the userdata pointer only once we have it. THis means the
original manager object must be manually retrieved from the
VarlinkServer object, which in turn needs to be requested from the
Varlink connection object.

The userdata inheritance is now controlled by the
VARLINK_INHERIT_USERDATA flag passed at VarlinkServer construction.

Alternative-to: systemd#18248
Yamakuzure pushed a commit to elogind/elogind that referenced this pull request Aug 25, 2021
…onnection optional

@keszybz's right on
systemd/systemd#18248 (comment):
swapping out the userdata pointer of a live varlink connection is iffy.

Let's fix this by making the userdata inheritance from VarlinkServer
object to the Varlink connection object optional: we want it for most
cases, but not all, i.e. all those cases where the calls implemented as
varlink methods are stateless and can be answered synchronously. For the
other cases (i.e. where we want per-connection objects that wrap the
asynchronous operation as it goes on) let's not do such inheritance but
initialize the userdata pointer only once we have it. THis means the
original manager object must be manually retrieved from the
VarlinkServer object, which in turn needs to be requested from the
Varlink connection object.

The userdata inheritance is now controlled by the
VARLINK_INHERIT_USERDATA flag passed at VarlinkServer construction.

Alternative-to: #18248
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐛 Programming errors, that need preferential fixing resolve

Development

Successfully merging this pull request may close these issues.

4 participants