From patchwork Thu May 28 23:21:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kubecek X-Patchwork-Id: 218277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAC9BC433DF for ; Thu, 28 May 2020 23:21:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD2A120721 for ; Thu, 28 May 2020 23:21:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437498AbgE1XVb (ORCPT ); Thu, 28 May 2020 19:21:31 -0400 Received: from mx2.suse.de ([195.135.220.15]:49124 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437475AbgE1XVT (ORCPT ); Thu, 28 May 2020 19:21:19 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 86EC2AFDF; Thu, 28 May 2020 23:21:17 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id AAA5DE32D2; Fri, 29 May 2020 01:21:17 +0200 (CEST) Message-Id: <66427ed9d01547b06bc7eb2b853a18108274f3eb.1590707335.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH ethtool 02/21] netlink: fix nest type grouping in parser To: John Linville , netdev@vger.kernel.org Cc: Andrew Lunn , Oleksij Rempel Date: Fri, 29 May 2020 01:21:17 +0200 (CEST) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Even if we are only interested in one nested attribute when using PARSER_GROUP_NEST group type, the temporary buffer must contain proper netlink header and have pointer to it and payload set up correctly for libmnl composition functions to be able to track current message size. Fixes: 9ee9d9517542 ("netlink: add basic command line parsing helpers") Reported-by: Andrew Lunn Signed-off-by: Michal Kubecek --- netlink/parser.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/netlink/parser.c b/netlink/parser.c index d790abedd482..bd3526f31113 100644 --- a/netlink/parser.c +++ b/netlink/parser.c @@ -957,6 +957,10 @@ int nl_parser(struct nl_context *nlctx, const struct param_parser *params, if (!buff) goto out_free_buffs; msgbuff = &buff->msgbuff; + ret = msg_init(nlctx, msgbuff, parser->group, + NLM_F_REQUEST | NLM_F_ACK); + if (ret < 0) + goto out_free_buffs; switch (group_style) { case PARSER_GROUP_NEST: @@ -966,10 +970,6 @@ int nl_parser(struct nl_context *nlctx, const struct param_parser *params, goto out_free_buffs; break; case PARSER_GROUP_MSG: - ret = msg_init(nlctx, msgbuff, parser->group, - NLM_F_REQUEST | NLM_F_ACK); - if (ret < 0) - goto out_free_buffs; if (ethnla_fill_header(msgbuff, ETHTOOL_A_LINKINFO_HEADER, nlctx->devname, 0))