linux-stable/tools/net/ynl
Jiri Pirko d0bcc15cba tools: ynl: don't access uninitialized attr_space variable
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: bf8b832374 ("tools/net/ynl: Support sub-messages in nested attribute spaces")
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2024-02-19 09:45:40 +00:00
..
generated tools: ynl: auto-gen for all genetlink families 2024-02-02 21:16:38 -08:00
lib tools: ynl: don't access uninitialized attr_space variable 2024-02-19 09:45:40 +00:00
samples tools: ynl: generate code for ovs families 2024-02-02 21:16:38 -08:00
cli.py tools/net/ynl: Add --output-json arg to ynl cli 2024-01-31 21:19:18 -08:00
ethtool.py tools: ynl: Rename ethtool to ethtool.py 2023-04-13 22:18:29 -07:00
Makefile tools: ynl: order building samples after generated code 2023-11-29 16:07:00 -08:00
Makefile.deps tools: ynl: include dpll and mptcp_pm in C codegen 2024-02-02 21:15:52 -08:00
requirements.txt tools: ynl: add the Python requirements.txt file 2023-03-24 19:11:02 -07:00
ynl-gen-c.py tools: ynl-gen: print prototypes for recursive stuff 2023-12-14 17:51:21 -08:00
ynl-gen-rst.py tools/net/ynl: Add type info to struct members in generated docs 2024-01-31 21:19:19 -08:00
ynl-regen.sh tools: ynl: don't skip regeneration from make targets 2023-11-29 16:07:00 -08:00