Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdbusplus allows serializing variant with a contained variant #88

Open
edtanous opened this issue Nov 15, 2023 · 5 comments
Open

Sdbusplus allows serializing variant with a contained variant #88

edtanous opened this issue Nov 15, 2023 · 5 comments

Comments

@edtanous
Copy link
Contributor

https://gerrit.openbmc.org/c/openbmc/bmcweb/+/67652

Exposed a minor problem in sdbusplus in that it allows serializing a double-wrapped variant container of dbus type.

v{v{d}}

Wrapping a variant within a variant on dbus is nonsensisical. This should ideally be a compile-time error when trying to instantiate a type_id of std::variant<std::variant<types...>>.

Opening this bug just for documentation at the moment.

Here is where the read call is getting instantiated.

constexpr auto dbusType = utility::tuple_to_array(types::type_id<T1>());

And this is the type_id definition for std::variant. I suspect we can put a static_assert here.
https://github.com/openbmc/sdbusplus/blob/ae01928016f2983aa44f1279a2575572514953f7/include/sdbusplus/message/types.hpp#L260C75-L260C75

@williamspatrick
Copy link
Member

Is this something that the dbus set-property does some magic where if the thing is already a variant it ignores the variant for the set-property call?

@edtanous
Copy link
Contributor Author

edtanous commented Nov 15, 2023

I would rather we just make it a compile-time failure rather than trying to ignore the extra variant. That keeps the code paths the same throughout everything, and I can't think of a good reason to call set-property with a variant, when the code itself knows the correct type.

@williamspatrick
Copy link
Member

I need to do some experimentation on this. If this is really a problem (variant in variant not allowed) then I suspect that all the client/server bindings are currently broken. If they aren’t broken, then I’m not sure what the catch would be.

@zevweiss
Copy link

FWIW, from what I recall when I accidentally tripped over this issue earlier this year, while I'm not sure why, dbus does seem to allow nested variants (both in terms of the spec and the implementation of dbus-broker). I'd also be generally inclined to have the library API make it a compile-time error since it seems like such a pointless footgun, but the fact that it is strictly speaking allowed makes me wonder if there might be some bizarro pathological case out there that's (perhaps accidentally) ended up with a nested variant baked into its interfaces and hence if it might be something a library intended for general-purpose use (i.e. not OpenBMC-specific) might want/need to support despite it being "obviously a bad idea"...

@williamspatrick
Copy link
Member

williamspatrick commented Nov 15, 2023

My thinking is, without experimentation, that it is required to be supported. Consider a property which is itself a variant. The Set-Property call has to take a variant-variant, unless there is some explicit handling that collapses the outer variant in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants