From: Wojciech Jowsa <[email protected]> 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 <[email protected]> --- 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 <rpcd/plugin.h> +#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), -- 2.25.1 _______________________________________________ openwrt-devel mailing list [email protected] https://lists.openwrt.org/mailman/listinfo/openwrt-devel
