From patchwork Mon May 17 05:10:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Westphal X-Patchwork-Id: 12260833 X-Patchwork-Delegate: stephen@networkplumber.org 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 5FFF0C433ED for ; Mon, 17 May 2021 05:10:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B92361206 for ; Mon, 17 May 2021 05:10:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234049AbhEQFLh (ORCPT ); Mon, 17 May 2021 01:11:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbhEQFLg (ORCPT ); Mon, 17 May 2021 01:11:36 -0400 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:12e:520::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87CB9C061573 for ; Sun, 16 May 2021 22:10:20 -0700 (PDT) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1liVWD-0005ay-Sw; Mon, 17 May 2021 07:10:17 +0200 From: Florian Westphal To: Cc: dsahern@gmail.com, Florian Westphal Subject: [PATCH iproute2 v3] libgenl: make genl_add_mcast_grp set errno on error Date: Mon, 17 May 2021 07:10:10 +0200 Message-Id: <20210517051010.1355-1-fw@strlen.de> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com genl_add_mcast_grp doesn't set errno in all cases. On kernels that support mptcp but lack event support (all kernels <= 5.11) MPTCP_PM_EV_GRP_NAME won't be found and ip will exit with "can't subscribe to mptcp events: Success" Set errno to a meaningful value (ENOENT) when the group name isn't found and also cover other spots where it returns nonzero with errno unset. Fixes: ff619e4fd370 ("mptcp: add support for event monitoring") Signed-off-by: Florian Westphal Reviewed-by: David Ahern --- Change since v2: include errno.h Change since v1: fix libgenl instead of setting errno in the caller. lib/libgenl.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/libgenl.c b/lib/libgenl.c index 4c51d47af46b..fca07f9fe768 100644 --- a/lib/libgenl.c +++ b/lib/libgenl.c @@ -3,6 +3,7 @@ * libgenl.c GENL library */ +#include #include #include #include @@ -84,6 +85,7 @@ static int genl_parse_grps(struct rtattr *attr, const char *name, unsigned int * } } + errno = ENOENT; return -1; } @@ -108,17 +110,22 @@ int genl_add_mcast_grp(struct rtnl_handle *grth, __u16 fnum, const char *group) ghdr = NLMSG_DATA(answer); len = answer->nlmsg_len; - if (answer->nlmsg_type != GENL_ID_CTRL) + if (answer->nlmsg_type != GENL_ID_CTRL) { + errno = EINVAL; goto err_free; + } len -= NLMSG_LENGTH(GENL_HDRLEN); - if (len < 0) + if (len < 0) { + errno = EINVAL; goto err_free; + } attrs = (struct rtattr *) ((char *) ghdr + GENL_HDRLEN); parse_rtattr(tb, CTRL_ATTR_MAX, attrs, len); if (tb[CTRL_ATTR_MCAST_GROUPS] == NULL) { + errno = ENOENT; fprintf(stderr, "Missing mcast groups TLV\n"); goto err_free; }