Skip to contentSkip to conversation

tools: ynl: don't access uninitialized attr_space variable

PATCH Applied Jiri Pirko 2 participants 2 messages Feb 15, 2024 – Feb 19, 2024

Subsystems (3)
lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

PATCH v2 1/1 tools: ynl: don't access uninitialized attr_space variable

From: Jiri Pirko <[email protected]>

If message contains unknown attribute and user passes "--process-unknown" command line option, _decode() gets called with space arg set to None. In that case, attr_space variable is not initialized used which leads to following trace:

Traceback (most recent call last):
File "./tools/net/ynl/cli.py", line 77, in <module>

    main()
  File "./tools/net/ynl/cli.py", line 68, in main
    reply = ynl.dump(args.dump, attrs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "tools/net/ynl/lib/ynl.py", line 909, in dump
    return self._op(method, vals, [], dump=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "tools/net/ynl/lib/ynl.py", line 894, in _op
rsp_msg = self._decode(decoded.raw_attrs, op.attr_set.name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "tools/net/ynl/lib/ynl.py", line 639, in _decode
self._rsp_add(rsp, attr_name, None, self._decode_unknown(attr))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "tools/net/ynl/lib/ynl.py", line 569, in _decode_unknown
return self._decode(NlAttrs(attr.raw), None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "tools/net/ynl/lib/ynl.py", line 630, in _decode
search_attrs = SpaceAttrs(attr_space, rsp, outer_attrs)
^^^^^^^^^^
UnboundLocalError: cannot access local variable 'attr_space' where it is not associated with a value

Fix this by moving search_attrs assignment under the if statement above it to make sure attr_space is initialized.

Fixes bf8b832374fb ("tools/net/ynl: Support sub-messages in nested attribute spaces")

---
v1->v2:
- avoid attr_space set in else case
- alter the patch subject and patch description to better describe the fix.

---
 tools/net/ynl/lib/ynl.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/net/ynl/lib/ynl.py +2 -2
index 03c7ca6aaae9..f45ee5f29bed 100644
@@ -588,10 +588,10 @@ class YnlFamily(SpecFamily):
         return decoded
 
     def _decode(self, attrs, space, outer_attrs = None):
+        rsp = dict()
         if space:
             attr_space = self.attr_sets[space]
-        rsp = dict()
-        search_attrs = SpaceAttrs(attr_space, rsp, outer_attrs)
+            search_attrs = SpaceAttrs(attr_space, rsp, outer_attrs)
 
         for attr in attrs:
             try:
Signature · 1 line
2.43.0
#1 lore raw
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 8 lines · On Thu, 15 Feb 2024 13:27:26 +0100 you wrote:

From: Jiri Pirko <[email protected]>

If message contains unknown attribute and user passes "--process-unknown" command line option, _decode() gets called with space arg set to None. In that case, attr_space variable is not initialized used which leads to following trace:

[...]

Here is the summary with links:
- [net-next,v2] tools: ynl: don't access uninitialized attr_space variable

    https://git.kernel.org/netdev/net-next/c/d0bcc15cbae8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html