From patchwork Sat Apr 10 11:19:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Aschenbrenner X-Patchwork-Id: 419465 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, 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 9DCEDC433ED for ; Sat, 10 Apr 2021 11:20:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 773F6610C8 for ; Sat, 10 Apr 2021 11:20:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234731AbhDJLUW (ORCPT ); Sat, 10 Apr 2021 07:20:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234721AbhDJLUT (ORCPT ); Sat, 10 Apr 2021 07:20:19 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B67D0C061763 for ; Sat, 10 Apr 2021 04:20:04 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id x7so8049366wrw.10 for ; Sat, 10 Apr 2021 04:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=iYEahb625v2DCYdik74nB2Ub24ROmO5mmaG2bC7Pguw=; b=RpY1ITiz7aMOv9E2uunW9JWYLB438oUBtyFi3vn/qnKrdu1aMKTHAS89waKrwpuc0d mv2ipGWDKMZ38r4O5/+XOd2YKTjO5hoLBq59bSrcu2BDPUcfVGDeTe/zjFHpsPpT8IZG UaVBhEQ7TdAtJRZHfF4Xm8nY29qQgYARut/ryoxSS0o7wDiLdjtxBRBKamVlXVq+MrGR DQuj+66zCzrwn5iwxL2u+00CIi7QnGCPdEVWlQy9OBjqLkjTLRXw6TPsm9JgTUe0jfid fK6vom9dNfOoURIANR8H4XkbdW9Os7Riuu/rrnbfq8k5oT1MJEFIyoJVdX59YEZzZ2QQ dj4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=iYEahb625v2DCYdik74nB2Ub24ROmO5mmaG2bC7Pguw=; b=kQbCgqw04NytSXYYYT/tpJTKXUKhXD8GP0/GOqUK5k8+fbJFcM8UZ6nxuqIkkQaSca kMxrNY8hAksKEfeeVx0h+Rggb73xEyhYyfj/JP+kvjWL6x2xWVxYO3d/M3XdUsTSBMdY mrp9cP8f9yHD26SecrmV6SkRPPir4g2W5FDasM6rmZZ6OPkga13qmYDXlxyfEMVhaY4m jKH/8DtM0J1Ry68zAqXjYQNIy73aLoB/OHAYJ13CJqB7rDfygC0Ujeea0AUYY3DpN+8r m3XZc2wvaOyJZwxdK2xKHFE0L770sq0mAt1A2i+jsCDwWtQwKcIXSmG7dZObQphSpfIN kPcg== X-Gm-Message-State: AOAM533xHh+Mb4sO93JwvEu8cQax7f2DLnEhGZsvIoxYQZVuQdkx7qI+ +k+VCh9tGaTiv2EJNbZnfEQsa3dXWaI= X-Google-Smtp-Source: ABdhPJwZaKRfAjI+5CoHPUFj+GyNqO/wiXJyAdxXPbeE+eOjx14eHs4RvyC6tCwvQNjELSzNDN0ljg== X-Received: by 2002:adf:e0d1:: with SMTP id m17mr21922261wri.90.1618053603534; Sat, 10 Apr 2021 04:20:03 -0700 (PDT) Received: from paula-ultrabook.fritz.box (dynamic-2a01-0c22-a41a-e200-35a1-ce2e-1cf4-ff60.c22.pool.telefonica.de. [2a01:c22:a41a:e200:35a1:ce2e:1cf4:ff60]) by smtp.gmail.com with ESMTPSA id j123sm7545118wmb.1.2021.04.10.04.20.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Apr 2021 04:20:03 -0700 (PDT) From: Benjamin Aschenbrenner To: johannes@sipsolutions.net Cc: benjamin.aschenbrenner@gmail.com, linux-wireless@vger.kernel.org Subject: [PATCH v2 1/2] iw: fix mgmt dump missing arguments segfault Date: Sat, 10 Apr 2021 13:19:36 +0200 Message-Id: <20210410111937.32813-1-benjamin.aschenbrenner@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org When expected arguments for mgmt command dump are left out iw segfaults. Example: iw dev wlp2s0 mgmt dump frame e0 This fixes it. Signed-off-by: Benjamin Aschenbrenner --- mgmt.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/mgmt.c b/mgmt.c index 338435d..677afb8 100644 --- a/mgmt.c +++ b/mgmt.c @@ -54,6 +54,9 @@ static int register_mgmt_frame(struct nl80211_state *state, size_t match_len; int ret; + if (argc < 2) + return HANDLER_RET_USAGE; + ret = sscanf(argv[0], "%x", &type); if (ret != 1) { printf("invalid frame type: %s\n", argv[0]); @@ -96,7 +99,6 @@ static int handle_mgmt_dump(struct nl80211_state *state, char **mgmt_argv; unsigned int count = 0; int err = 0; - int i; mgmt_argv = calloc(mgmt_argc, sizeof(char*)); if (!mgmt_argv) @@ -106,27 +108,42 @@ static int handle_mgmt_dump(struct nl80211_state *state, mgmt_argv[1] = "mgmt"; mgmt_argv[2] = "reg"; - for (i = 3; i < argc; i += 3) { - if (strcmp(argv[i], "count") == 0) { - count = 1 + atoi(argv[i + 1]); - if (count < 1) - count = 1; - break; - } + if (argc < 6) { + err = HANDLER_RET_USAGE; + goto out; + } - if (strcmp(argv[i], "frame") != 0) { - err = 1; + argc -= 3; + argv += 3; + while (argc >= 3) { + if (strcmp(argv[0], "frame") != 0) { + err = HANDLER_RET_USAGE; goto out; } - mgmt_argv[3] = argv[i + 1]; - mgmt_argv[4] = argv[i + 2]; + mgmt_argv[3] = argv[1]; + mgmt_argv[4] = argv[2]; + + argc -= 3; + argv += 3; err = handle_cmd(state, II_NETDEV, mgmt_argc, mgmt_argv); if (err) goto out; } + if (argc == 2 && strcmp(argv[0], "count") == 0) { + count = 1 + atoi(argv[1]); + if (count < 1) + count = 1; + + argc -= 2; + argv += 2; + } else if (argc) { + err = HANDLER_RET_USAGE; + goto out; + } + mgmt_cb = nl_cb_alloc(iw_debug ? NL_CB_DEBUG : NL_CB_DEFAULT); if (!mgmt_cb) { err = 1; From patchwork Sat Apr 10 11:19:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Aschenbrenner X-Patchwork-Id: 419140 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, 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 A7C66C43460 for ; Sat, 10 Apr 2021 11:20:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7823C610C8 for ; Sat, 10 Apr 2021 11:20:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234674AbhDJLUX (ORCPT ); Sat, 10 Apr 2021 07:20:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234647AbhDJLUW (ORCPT ); Sat, 10 Apr 2021 07:20:22 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6373C061762 for ; Sat, 10 Apr 2021 04:20:07 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id e12so8050177wro.11 for ; Sat, 10 Apr 2021 04:20:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NNk4SAcoFIrAv/6JBtW/nm47KG5kv09NGIDqM5Ffj2o=; b=C1eddsIoHRarSTa0/4YP7UJVFW4tFw/CooKAyxaG8cC+tO5Ay6+sBCKGwGiV8btTcR pz5CBXGzNNSetzE7BIeQhaFa6pJ9ot8mVblGkm/9yUnMdd68iF+Eb3YjRsckAo8NVOEs Drb2/8PqU8sg4TbqMQd969VnYM/5YOmkbdH2YFtra4QFovyuaSxFOcUcxOyEZjKKIOk1 XIg4q8pZK1EFUGWFxVS7JqV/EbZsmmdarr4SSJr+FTbjDGu39P4APUS3FaL2TNGzdqJF EVM+4sok9OpIbjwLzsXx9SaaYFvG4LyEo01z9RcjQ4An/bofBKKTlxbm24LAebYptETz Vc2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NNk4SAcoFIrAv/6JBtW/nm47KG5kv09NGIDqM5Ffj2o=; b=smF8CDegQo2lUwmCchwD+FMkth9F++z4x++YEE/vpxRrS4fHRatPl1CY0PcO0visp5 9mRpT9a2RBttYuf17CwJyojqoedAgGuZtlW/V/J2paAEszW2LNNcLLg2BHrIucXgLiOC lIfeE2CYcmVoX62A2yO74bOVAqRxiN4PxeOgCZ2gjVSfB4YZSTjqSi6Gg7V+Qz7/500+ RlZofE3FJpzXRDyG4igxo4LEHOyFkbP8AchYZ2cc9ZaAb6Np9/BDU1KfOl8Uz5zNTYbr rT9XUbKh3rvwCwrzlOUrxcOubniRmuDoSpiecQHteS1ryyw5ubKxwVaqUU/bYiGt+RQQ u7Rg== X-Gm-Message-State: AOAM530kJU9Xa9Vnl69jQNVsMfbD0FxNEnM7kVzzBNuBnuFIfyzE6DGc ivJRYnkboabWPy7FgA7aXto= X-Google-Smtp-Source: ABdhPJxGJRnNR265Hb0n9mTCdrmDoyWqystZxk3bKnFpMQCAkMRTqUc/pvU0mtUNUQJsPH9PgXnp4g== X-Received: by 2002:a05:6000:1187:: with SMTP id g7mr22053565wrx.306.1618053606741; Sat, 10 Apr 2021 04:20:06 -0700 (PDT) Received: from paula-ultrabook.fritz.box (dynamic-2a01-0c22-a41a-e200-35a1-ce2e-1cf4-ff60.c22.pool.telefonica.de. [2a01:c22:a41a:e200:35a1:ce2e:1cf4:ff60]) by smtp.gmail.com with ESMTPSA id j123sm7545118wmb.1.2021.04.10.04.20.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Apr 2021 04:20:06 -0700 (PDT) From: Benjamin Aschenbrenner To: johannes@sipsolutions.net Cc: benjamin.aschenbrenner@gmail.com, linux-wireless@vger.kernel.org Subject: [PATCH v2 2/2] iw: fix ftm_request missing arguments segfault Date: Sat, 10 Apr 2021 13:19:37 +0200 Message-Id: <20210410111937.32813-2-benjamin.aschenbrenner@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210410111937.32813-1-benjamin.aschenbrenner@gmail.com> References: <20210410111937.32813-1-benjamin.aschenbrenner@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org When expected argument is not passed to arguemts iw segfaults. Example: iw wlp2s0 measurement ftm_request This fixes it. Signed-off-by: Benjamin Aschenbrenner --- measurements.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/measurements.c b/measurements.c index 635d942..80fe785 100644 --- a/measurements.c +++ b/measurements.c @@ -282,6 +282,9 @@ static int handle_ftm_req_send(struct nl80211_state *state, struct nl_msg *msg, const char *file; int err; + if (argc < 1) + return HANDLER_RET_USAGE; + file = argv[0]; argc--; argv++;