lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <cf6ca99b-4d3b-4120-aa23-77335fc25421@intel.com>
Date: Thu, 24 Apr 2025 08:49:32 -0700
From: Jacob Keller <jacob.e.keller@...el.com>
To: Jakub Kicinski <kuba@...nel.org>, <davem@...emloft.net>
CC: <netdev@...r.kernel.org>, <edumazet@...gle.com>, <pabeni@...hat.com>,
	<andrew+netdev@...n.ch>, <horms@...nel.org>, <donald.hunter@...il.com>,
	<sdf@...ichev.me>
Subject: Re: [PATCH net-next 03/12] tools: ynl-gen: fill in missing empty attr
 lists



On 4/23/2025 7:11 PM, Jakub Kicinski wrote:
> The C codegen refers to op attribute lists all over the place,
> without checking if they are present, even tho attribute list
> is technically an optional property. Add them automatically
> at init if missing so that we don't have to make specs longer.
> 
> Signed-off-by: Jakub Kicinski <kuba@...nel.org>
> ---
>  tools/net/ynl/pyynl/ynl_gen_c.py | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
> index 90f7fe6b623b..569768bcf155 100755
> --- a/tools/net/ynl/pyynl/ynl_gen_c.py
> +++ b/tools/net/ynl/pyynl/ynl_gen_c.py
> @@ -938,6 +938,16 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
>  
>  class Operation(SpecOperation):
>      def __init__(self, family, yaml, req_value, rsp_value):
> +        # Fill in missing operation properties (for fixed hdr-only msgs)
> +        for mode in ['do', 'dump', 'event']:
> +            if mode not in yaml.keys():
> +                continue
> +            for direction in ['request', 'reply']:
> +                if direction not in yaml[mode]:
> +                    continue
> +                if 'attributes' not in yaml[mode][direction]:
> +                    yaml[mode][direction]['attributes'] = []
> +


This feels like there should be a more "pythonic" way to do this without
as much boilerplate.. but I can't actually come up with a better suggestion.

Maybe some sort of try/except with a catch for KeyError or something..
not really sure I like that more than the list approach either tho... I
guess it would be:

for mode in ['do', 'dump', 'event']:
  for direction in ['request', 'reply']:
    try:
      yaml[mode][direction].setdefault('attributes', [])
    except KeyError:
      pass


I'm not sure thats really any better than the approach here.

Reviewed-by: Jacob Keller <jacob.e.keller@...el.com>

>          super().__init__(family, yaml, req_value, rsp_value)
>  
>          self.render_name = c_lower(family.ident_name + '_' + self.name)


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ