From patchwork Fri May 7 11:38:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wojciech Jowsa X-Patchwork-Id: 1475475 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=f3ieusHX; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=AjVxAi2o; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fc7nZ56H7z9sXV for ; Fri, 7 May 2021 21:41:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=nw8yb7uIKdPsuj3KOlC1svTTi6k+7+cr2A1C3a8AgkM=; b=f3ieusHXX8Fior+BzioTKPhgs8 Mkv5czLBQDwRviZbH9LrkhYkwu1YUnzeH4cY+4g8zT89VDr1F3QIw87ZfnRTv3vy+f+lEC2ntAoG0 88zOU1leMIIgxSJOBaUL0R8NVPU3KpNH6b2SQei5HFOgfB9RWC3dL3l3aks30+FwZgIASbvB8P2g2 KbRhbmD/aZlGJ4ty0+kZn8aqgebQNDlxNWlZb6K3IyaAhgbpUev9Hhya8bMDYusVM01bD4Uxg/vKM aDhUwANvqTYKP71vKH4raxAYV/VXwzFjDee3qS8cGYqY7OL/BeTy1/2Ns14bujjvFndTgbbY13zkc C/7/ygfg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1leyp8-006yuZ-1H; Fri, 07 May 2021 11:39:14 +0000 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1leyp3-006ysC-BI for openwrt-devel@lists.openwrt.org; Fri, 07 May 2021 11:39:11 +0000 Received: by mail-lj1-x234.google.com with SMTP id w4so11138610ljw.9 for ; Fri, 07 May 2021 04:39:08 -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=DX6s1DvejEKUeQANvJTQSpcErYoWRuLsj5kaMG2CGyU=; b=AjVxAi2ozbPCDac5YQGBsInvGRvNoq58d7A6H1Erct3EX2dA403BViDNe97yvnQi+Y 7+7Ua434PztbR7Sk9Zh5pH2YXslwwij3X0JRYYkJ5GEBM9fbXWDomGikPqO0JxRGS2Hi NF14frfa7ax06YM78UJFN/LZqDVWKXoO3SQjzUQDmZfEYmr76fjeteZFmioUzYkAcFfU 2G9zUfkLshHDT7ofuidzMOhH+rasbjkKO8iI4VelKQCTjq4AVIjrW/nILeAadYQDD0AD GWJuPfWzidfscicxuFj6t7roaNG8IkCuLS8Vnh+g9//TbxUzqrShPKKSWHCXHTj/qUxl Gljw== 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=DX6s1DvejEKUeQANvJTQSpcErYoWRuLsj5kaMG2CGyU=; b=sAP+AnTrWttBmECIqKYmLUaMOPBItNe+tWsAvdzuvBB+k4XKoljAl7KIEc1xxtumvF vXscUEv3esUgWNLPhe0XzM3i4JNez1kPmd2/aZgqRRGbE48AT0wVzN588lYeIQ/pJRz5 vLHFjAIA0N6eFkD5s1BJY1I9e9cewzlka/y5D75h8q848/ux4ZJKMo69WpI4FeKZU44R ZvDEhx4kEopSmPACp9BOlYU28eTdd6jvRCyW7F6AErvfNVJ7gnRhPi6MNQamNKGLYzM7 hnefEchYhJR+rNiHynaaCMVE4kL5BPD55OPbRzjt2+iPSAKpRUZZTZ4ia0BXfLGJqj57 OTqQ== X-Gm-Message-State: AOAM530zTqLJk1sSbQRLCVerBKl7QJTkqSLAyjJbbYHG+g+T8uUjrG0q rsm5cAQn9H3Bdw4nbri55slSnfjuciAoHA== X-Google-Smtp-Source: ABdhPJzlXgzSzs4uJR13CQ/2CwlBBo+JYWOcWE1cMHnwKnuXXmRyDpfHZJPwOxNYtihMxwBt6oAJkA== X-Received: by 2002:a05:651c:102e:: with SMTP id w14mr7654154ljm.238.1620387547212; Fri, 07 May 2021 04:39:07 -0700 (PDT) Received: from wjow-XPS-15-9570.lan ([31.179.130.194]) by smtp.gmail.com with ESMTPSA id r16sm1812184ljj.108.2021.05.07.04.39.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 04:39:06 -0700 (PDT) From: Wojciech Jowsa To: openwrt-devel@lists.openwrt.org Cc: Wojciech Jowsa , Wojciech Jowsa Subject: [PATCH] iwinfo: add buffer_size argument to scan method Date: Fri, 7 May 2021 13:38:56 +0200 Message-Id: <20210507113856.28810-1-wojciech.jowsa@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210507_123909_523421_113A9E6A X-CRM114-Status: GOOD ( 13.47 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Wojciech Jowsa iwinfo crashes when scan is perforemed in the area where there are more then 500 wifi networks available. It is because a buffer with the fixed size is used. Increasing the size of the buffer fixes th [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:234 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wojciech.jowsa[at]gmail.com] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Wojciech Jowsa iwinfo crashes when scan is perforemed in the area where there are more then 500 wifi networks available. It is because a buffer with the fixed size is used. Increasing the size of the buffer fixes this problem. The size can be passed by the argument to the iwinfo scan call. Signed-off-by: Wojciech Jowsa --- iwinfo.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/iwinfo.c b/iwinfo.c index ba4fc1e..ce48725 100644 --- a/iwinfo.c +++ b/iwinfo.c @@ -29,6 +29,7 @@ #include +#define IWINFO_BUFSIZE_MAX 1024 * 1024 static struct blob_buf buf; static const struct iwinfo_ops *iw; @@ -63,6 +64,17 @@ static const struct blobmsg_policy rpc_uci_policy[__RPC_U_MAX] = { [RPC_U_SECTION] = { .name = "section", .type = BLOBMSG_TYPE_STRING }, }; +enum { + RPC_S_DEVICE, + RPC_S_BUFFSIZE, + __RPC_S_MAX, +}; + +static const struct blobmsg_policy rpc_scan_policy[__RPC_S_MAX] = { + [RPC_S_DEVICE] = { .name = "device", .type = BLOBMSG_TYPE_STRING }, + [RPC_S_BUFFSIZE] = { .name = "buffer_size", .type = BLOBMSG_TYPE_INT32 } +}; + static int __rpc_iwinfo_open(struct blob_attr *device) { @@ -454,12 +466,24 @@ rpc_iwinfo_scan(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - int i, rv, len; + int i, rv, len, buffer_size = IWINFO_BUFSIZE; void *c, *d, *t; char mac[18]; - char res[IWINFO_BUFSIZE]; + struct blob_attr *tb[__RPC_S_MAX]; struct iwinfo_scanlist_entry *e; + blobmsg_parse(rpc_scan_policy, __RPC_S_MAX, tb, + blob_data(msg), blob_len(msg)); + + if(tb[RPC_S_BUFFSIZE]) { + buffer_size = blobmsg_get_u32(tb[RPC_S_BUFFSIZE]); + if (buffer_size > IWINFO_BUFSIZE_MAX) { + buffer_size = IWINFO_BUFSIZE_MAX; + } + } + + char res[buffer_size]; + rv = rpc_iwinfo_open(msg); if (rv) @@ -965,7 +989,7 @@ rpc_iwinfo_api_init(const struct rpc_daemon_ops *o, struct ubus_context *ctx) static const struct ubus_method iwinfo_methods[] = { UBUS_METHOD_NOARG("devices", rpc_iwinfo_devices), UBUS_METHOD("info", rpc_iwinfo_info, rpc_device_policy), - UBUS_METHOD("scan", rpc_iwinfo_scan, rpc_device_policy), + UBUS_METHOD("scan", rpc_iwinfo_scan, rpc_scan_policy), UBUS_METHOD("assoclist", rpc_iwinfo_assoclist, rpc_assoclist_policy), UBUS_METHOD("freqlist", rpc_iwinfo_freqlist, rpc_device_policy), UBUS_METHOD("txpowerlist", rpc_iwinfo_txpowerlist, rpc_device_policy),