linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Aschenbrenner <benjamin.aschenbrenner@gmail.com>
To: johannes@sipsolutions.net
Cc: linux-wireless@vger.kernel.org
Subject: [PATCH 1/2] iw: fix mgmt dump missing arguments segfault
Date: Mon, 22 Mar 2021 15:53:48 +0100	[thread overview]
Message-ID: <CAASiZWZGk=FWdy=MbM7MZnSx5GeS2X6-3xCmogsvGO5CgWKWBQ@mail.gmail.com> (raw)

From: Benjamin Aschenbrenner <benjamin.aschenbrenner@gmail.com>
Date: Mon, 22 Mar 2021 15:03:51 +0100
Subject: [PATCH 1/2] iw: fix mgmt dump missing arguments segfault

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 <benjamin.aschenbrenner@gmail.com>
---
 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;
-- 
2.30.2

                 reply	other threads:[~2021-03-22 14:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAASiZWZGk=FWdy=MbM7MZnSx5GeS2X6-3xCmogsvGO5CgWKWBQ@mail.gmail.com' \
    --to=benjamin.aschenbrenner@gmail.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).