From patchwork Thu Dec 19 22:11:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213778 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="XXKYnRhq"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5h51KFxz9sPJ for ; Fri, 20 Dec 2019 09:11:49 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=e3wxliBkxbb73Knd7PMah5zT/gKc0XsNcRBbPt3arZ8=; b=XXKYnRhqP2Ozo0 cPVVZXJoRJBxKrukH2A1jXWoBsMVuqhMc7hr+hWG4T9rN+CgloFbsmnrxORutJE63eftgeVgk9UBA zYYZg5iRI0LhjFuQ6r4ecEhTIhAEqW2Pb24+TMOTBroDQCVRfVJPr2cd1kuuuwmdeAGTXLYeIvpnw j2KtANJHkyqJF+wZkfjjl1XWpkWzqa3jmIf17u/6u1RVNm/Geowy98DbLa273IyUM2cnXDfUuFeMl e3QBfjh+vO30ksMET0UiiS1Ug3rk0hQlbCbR9haovuDZtxwNfb77zfde/Zyck8qc0fkIWn0uVfaNX oSAH+izElCkbhROUlvog==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41K-00054r-Ty; Thu, 19 Dec 2019 22:11:46 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41H-000528-0F for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:44 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 3C20C4BB8; Thu, 19 Dec 2019 23:11:41 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id da4fa367; Thu, 19 Dec 2019 23:11:31 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:10 +0100 Message-Id: <20191219221125.22646-2-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141143_193167_6EC79BA6 X-CRM114-Status: UNSURE ( 6.23 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 01/16] cmake: enable extra compiler checks X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Let's enforce additional automatic checks enforced by the compiler in order to catch possible errors during compilation. Signed-off-by: Petr Štetiar --- CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8ef4aa58ccf..866b3ab60168 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,13 @@ cmake_minimum_required(VERSION 2.6) PROJECT(ubus C) -ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations) + +ADD_DEFINITIONS(-Wall -Werror) +IF(CMAKE_C_COMPILER_VERSION VERSION_GREATER 6) + ADD_DEFINITIONS(-Wextra -Werror=implicit-function-declaration) + ADD_DEFINITIONS(-Wformat -Werror=format-security -Werror=format-nonliteral) +ENDIF() +ADD_DEFINITIONS(-Os -std=gnu99 -g3 -Wmissing-declarations -Wno-unused-parameter) OPTION(BUILD_LUA "build Lua plugin" ON) OPTION(BUILD_EXAMPLES "build examples" ON) From patchwork Thu Dec 19 22:11:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213780 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="dQ/9ppXt"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5hf4mKXz9sPJ for ; Fri, 20 Dec 2019 09:12:18 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lBoy7hCxi/UhSHMQnIa9DxHPnd66A5zDSv9+SerXQmk=; b=dQ/9ppXtqyuiHb 5ehQsOHRLRzdTpOOc/P+1tZfhj5MoZAeUzsrzSiT4YyU26NYsKjh4crZ+9APSt1mteXFNlUr4CHEt brgNvrRI113FxySuSkMAUIYFhP46ZFcY+dBo1aQf0SRh7eb9GxJKv968TBrMT2AoRj34IWPjhe/Cd pHb03YhgJfVe/ruIrhjw032IwYMNS41kHk3K6fANI8vio9RlvWtob+f8gJw5en3wP8Lil87GEVQOA ZLDp4BF9SLxKvnPAPs5Irlh3cdJzchx+DxKvySEqMVwvOrKUXmipbLS9m7MJLUD9K7ZjKFFJcMv3a 5l7S+GGVEhjcSk8SF+JA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41o-0005lD-UU; Thu, 19 Dec 2019 22:12:16 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41H-00052e-L2 for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:45 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 5E7AE4BB9; Thu, 19 Dec 2019 23:11:42 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 028458c1; Thu, 19 Dec 2019 23:11:32 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:11 +0100 Message-Id: <20191219221125.22646-3-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141143_835579_0B3B2D01 X-CRM114-Status: UNSURE ( 8.76 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 02/16] ubusd: fix comparison of integers of different signs X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Fixes following clang-9 compiler warning: ubusd.c:36:19: error: comparison of integers of different signs: 'uint32_t' (aka 'unsigned int') and 'int' [-Werror,-Wsign-compare] if (ub->refcount == ~0) { ~~~~~~~~~~~~ ^ ~~ Signed-off-by: Petr Štetiar --- ubusd.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ubusd.c b/ubusd.c index 0f35d3e25d34..7738f50f9779 100644 --- a/ubusd.c +++ b/ubusd.c @@ -30,10 +30,12 @@ #include "ubusd.h" +#define USES_EXTERNAL_BUFFER ~0U + static struct ubus_msg_buf *ubus_msg_ref(struct ubus_msg_buf *ub) { struct ubus_msg_buf *new_ub; - if (ub->refcount == ~0) { + if (ub->refcount == USES_EXTERNAL_BUFFER) { new_ub = ubus_msg_new(ub->data, ub->len, false); if (!new_ub) return NULL; @@ -61,7 +63,7 @@ struct ubus_msg_buf *ubus_msg_new(void *data, int len, bool shared) ub->fd = -1; if (shared) { - ub->refcount = ~0; + ub->refcount = USES_EXTERNAL_BUFFER; ub->data = data; } else { ub->refcount = 1; @@ -78,7 +80,7 @@ void ubus_msg_free(struct ubus_msg_buf *ub) { switch (ub->refcount) { case 1: - case ~0: + case USES_EXTERNAL_BUFFER: if (ub->fd >= 0) close(ub->fd); From patchwork Thu Dec 19 22:11:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213781 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PPwAtXw+"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5j072m2z9sPJ for ; Fri, 20 Dec 2019 09:12:36 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8VcTPE+SoHe/QbZWIhHBVH3fcLiDpMFj+7lhUbbXZuo=; b=PPwAtXw+oj/PUm FJTRwAKVZisTSSJ0SXcpdElt70orWoIM577SqDkx88Np6NUuU5wFrLjpuaU1fBIDM9G/ryxNXACSP I0iWFXsZYLdsgzEaAR7Z1BLHlN5Bjh4UwLs84RtmR3qe/btx0O9k3ov0oErSWfphuKFYH5wI4mhAp zz3eI2s7bDW+e5+SV3VQxyfDAHrIeMrrw3MvOGSlSKeGOnlp/dSQvB9Dfvkk2Rycy5bUD7wg/ZiGg 1N5hPT+I07wfIPn12Kzt38xsGLHYZSVtRFI1okzaZVJ7T+YjjtaO+n+8X5iX1NY9px6yN5oOA3so0 TWtehYlcNJnuvaHbBxeA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii423-0006Dl-Ti; Thu, 19 Dec 2019 22:12:31 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41H-00052f-PL for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:45 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 7DE9E4BBB; Thu, 19 Dec 2019 23:11:42 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 45d6b5f7; Thu, 19 Dec 2019 23:11:32 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:12 +0100 Message-Id: <20191219221125.22646-4-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141143_967678_8FB303F8 X-CRM114-Status: UNSURE ( 8.64 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 03/16] ubusd/libubus-io: fix variable sized struct position warning X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Fixes following clang-9 compiler warnings: ubusd.c:99:18: error: field 'h' with variable sized type 'struct cmsghdr' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end] struct cmsghdr h; ^ Signed-off-by: Petr Štetiar --- libubus-io.c | 4 ++-- ubusd.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libubus-io.c b/libubus-io.c index 228af5ca279c..cdd1e6e1ed6a 100644 --- a/libubus-io.c +++ b/libubus-io.c @@ -60,8 +60,8 @@ static void wait_data(int fd, bool write) static int writev_retry(int fd, struct iovec *iov, int iov_len, int sock_fd) { static struct { - struct cmsghdr h; int fd; + struct cmsghdr h; } fd_buf = { .h = { .cmsg_len = sizeof(fd_buf), @@ -159,8 +159,8 @@ static int recv_retry(struct ubus_context *ctx, struct iovec *iov, bool wait, in int bytes, total = 0; int fd = ctx->sock.fd; static struct { - struct cmsghdr h; int fd; + struct cmsghdr h; } fd_buf = { .h = { .cmsg_type = SCM_RIGHTS, diff --git a/ubusd.c b/ubusd.c index 7738f50f9779..d6a72e73370b 100644 --- a/ubusd.c +++ b/ubusd.c @@ -96,8 +96,8 @@ static int ubus_msg_writev(int fd, struct ubus_msg_buf *ub, int offset) { static struct iovec iov[2]; static struct { - struct cmsghdr h; int fd; + struct cmsghdr h; } fd_buf = { .h = { .cmsg_len = sizeof(fd_buf), @@ -216,8 +216,8 @@ static void client_cb(struct uloop_fd *sock, unsigned int events) struct ubus_msg_buf *ub; static struct iovec iov; static struct { - struct cmsghdr h; int fd; + struct cmsghdr h; } fd_buf = { .h = { .cmsg_type = SCM_RIGHTS, From patchwork Thu Dec 19 22:11:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213782 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qnwj7fKh"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5jF3pK2z9sPL for ; Fri, 20 Dec 2019 09:12:49 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jjxsLHgtuxSlsnpHM22w4GMBOAnzPOo1+KWYsFoom+U=; b=qnwj7fKhlK0xJp AE5kSmQBuW2Gve9N2vnypxg22DVBApssz0BVrAHaoFXquofCszruQouBTIkGWWnkAMBP5lYVDDwpi wxuWXgEb/SZ73WAswhDYzg9ogfFPnHy7THTIiDtzn19HL1ZmCxcmWyF75B3lT+evX5ptwA9+m/xhk AsbjAeFoMNKzpmZ9DtWqKYWi1hGZ/DH6LVAgmc/9wozX8LMQPwOY8drflrtDLXOIMSK5sGoVV76UA r4jWOrA70ipIKWqQhfCqxWK2gAMtVCJbMJApMW/cdXfD5VO4Gx/9EBO4sq+6kmo/tVXMwsuyAcFml 1l+nPzc3EPZuJP7xTJHg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii42J-0006it-Jc; Thu, 19 Dec 2019 22:12:47 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41H-00052j-TQ for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:46 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 9DA4A4BBE; Thu, 19 Dec 2019 23:11:42 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 1454c9b1; Thu, 19 Dec 2019 23:11:33 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:13 +0100 Message-Id: <20191219221125.22646-5-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141144_249731_B980A827 X-CRM114-Status: GOOD ( 14.46 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 04/16] iron out all extra compiler warnings X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org clang-9 on x86/64 has reported following warnings/errors: libubus-acl.c:123:2: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] libubus-io.c:108:18: error: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare] libubus-io.c:395:56: error: comparison of integers of different signs: 'ssize_t' (aka 'long') and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare] libubus-req.c:441:4: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] ubusd_acl.c:119:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] ubusd_acl.c:152:5: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] ubusd_acl.c:348:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] ubusd_acl.c:352:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] ubusd_acl.c:357:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] ubusd_acl.c:362:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] ubusd_acl.c:367:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] ubusd_acl.c:447:16: error: comparison of integers of different signs: 'int' and '__size_t' (aka 'unsigned long') [-Werror,-Wsign-compare] ubusd_acl.c:502:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] ubusd.c:123:13: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] ubusd.c:170:15: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] ubusd.c:262:43: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] ubusd.c:287:30: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] ubusd_event.c:170:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] ubusd_obj.c:71:2: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] Signed-off-by: Petr Štetiar --- cli.c | 11 ++++++----- examples/server.c | 7 ++++--- libubus-acl.c | 2 +- libubus-io.c | 6 +++--- libubus-req.c | 3 ++- lua/ubus.c | 4 ++-- ubusd.c | 14 +++++++------- ubusd_acl.c | 10 +++++----- ubusd_event.c | 2 +- ubusd_obj.c | 2 +- 10 files changed, 32 insertions(+), 29 deletions(-) diff --git a/cli.c b/cli.c index 19ccbb5093ce..421f244ad9dc 100644 --- a/cli.c +++ b/cli.c @@ -47,7 +47,7 @@ static const char *format_type(void *priv, struct blob_attr *attr) [BLOBMSG_TYPE_TABLE] = "\"Table\"", }; const char *type = NULL; - int typeid; + size_t typeid; if (blob_id(attr) != BLOBMSG_TYPE_INT32) return NULL; @@ -65,7 +65,7 @@ static void receive_list_result(struct ubus_context *ctx, struct ubus_object_dat { struct blob_attr *cur; char *s; - int rem; + size_t rem; if (simple_output || !verbose) { printf("%s\n", obj->path); @@ -520,7 +520,7 @@ static int ubus_cli_monitor(struct ubus_context *ctx, int argc, char **argv) static int add_monitor_type(const char *type) { - int i; + size_t i; for (i = 0; i < ARRAY_SIZE(monitor_types); i++) { if (!monitor_types[i] || strcmp(monitor_types[i], type) != 0) @@ -575,9 +575,10 @@ int main(int argc, char **argv) { const char *progname, *ubus_socket = NULL; struct ubus_context *ctx; - char *cmd; int ret = 0; - int i, ch; + char *cmd; + size_t i; + int ch; progname = argv[0]; diff --git a/examples/server.c b/examples/server.c index e0cde0bf3a86..004eaf3a7ae1 100644 --- a/examples/server.c +++ b/examples/server.c @@ -84,7 +84,7 @@ static int test_hello(struct ubus_context *ctx, struct ubus_object *obj, { struct hello_request *hreq; struct blob_attr *tb[__HELLO_MAX]; - const char *format = "%s received a message: %s"; + const char format[] = "%s received a message: %s"; const char *msgstr = "(unknown)"; blobmsg_parse(hello_policy, ARRAY_SIZE(hello_policy), tb, blob_data(msg), blob_len(msg)); @@ -92,11 +92,12 @@ static int test_hello(struct ubus_context *ctx, struct ubus_object *obj, if (tb[HELLO_MSG]) msgstr = blobmsg_data(tb[HELLO_MSG]); - hreq = calloc(1, sizeof(*hreq) + strlen(format) + strlen(obj->name) + strlen(msgstr) + 1); + size_t len = sizeof(*hreq) + sizeof(format) + strlen(obj->name) + strlen(msgstr) + 1; + hreq = calloc(1, len); if (!hreq) return UBUS_STATUS_UNKNOWN_ERROR; - sprintf(hreq->data, format, obj->name, msgstr); + snprintf(hreq->data, len, format, obj->name, msgstr); ubus_defer_request(ctx, req, &hreq->req); hreq->timeout.cb = test_hello_reply; uloop_timeout_set(&hreq->timeout, 1000); diff --git a/libubus-acl.c b/libubus-acl.c index 0274520f7d57..aab6629d1367 100644 --- a/libubus-acl.c +++ b/libubus-acl.c @@ -102,7 +102,7 @@ static void acl_recv_cb(struct ubus_request *req, { struct blob_attr *tb[__ACL_POLICY_MAX]; struct blob_attr *cur; - int rem; + size_t rem; if (acl_blob) { struct acl_object *p, *q; diff --git a/libubus-io.c b/libubus-io.c index cdd1e6e1ed6a..120fb605e90a 100644 --- a/libubus-io.c +++ b/libubus-io.c @@ -78,7 +78,7 @@ static int writev_retry(int fd, struct iovec *iov, int iov_len, int sock_fd) int len = 0; do { - int cur_len; + ssize_t cur_len; if (sock_fd < 0) { msghdr.msg_control = NULL; @@ -105,7 +105,7 @@ static int writev_retry(int fd, struct iovec *iov, int iov_len, int sock_fd) sock_fd = -1; len += cur_len; - while (cur_len >= iov->iov_len) { + while (cur_len >= (ssize_t) iov->iov_len) { cur_len -= iov->iov_len; iov_len--; iov++; @@ -392,7 +392,7 @@ int ubus_reconnect(struct ubus_context *ctx, const char *path) goto out_close; memcpy(buf, &hdr.data, sizeof(hdr.data)); - if (read(ctx->sock.fd, blob_data(buf), blob_len(buf)) != blob_len(buf)) + if (read(ctx->sock.fd, blob_data(buf), blob_len(buf)) != (ssize_t) blob_len(buf)) goto out_free; ctx->local_id = hdr.hdr.peer; diff --git a/libubus-req.c b/libubus-req.c index 74446f3fef51..97785a1e24cd 100644 --- a/libubus-req.c +++ b/libubus-req.c @@ -428,7 +428,8 @@ static void ubus_process_notify_status(struct ubus_request *req, int id, struct struct ubus_notify_request *nreq; struct blob_attr **tb; struct blob_attr *cur; - int rem, idx = 1; + size_t rem; + int idx = 1; int ret = 0; nreq = container_of(req, struct ubus_notify_request, req); diff --git a/lua/ubus.c b/lua/ubus.c index 4da3c80e07f5..6fbbc0686af3 100644 --- a/lua/ubus.c +++ b/lua/ubus.c @@ -52,11 +52,11 @@ static int ubus_lua_parse_blob(lua_State *L, struct blob_attr *attr, bool table); static int -ubus_lua_parse_blob_array(lua_State *L, struct blob_attr *attr, int len, bool table) +ubus_lua_parse_blob_array(lua_State *L, struct blob_attr *attr, size_t len, bool table) { int rv; int idx = 1; - int rem = len; + size_t rem = len; struct blob_attr *pos; lua_newtable(L); diff --git a/ubusd.c b/ubusd.c index d6a72e73370b..c020ff416a32 100644 --- a/ubusd.c +++ b/ubusd.c @@ -92,7 +92,7 @@ void ubus_msg_free(struct ubus_msg_buf *ub) } } -static int ubus_msg_writev(int fd, struct ubus_msg_buf *ub, int offset) +static ssize_t ubus_msg_writev(int fd, struct ubus_msg_buf *ub, size_t offset) { static struct iovec iov[2]; static struct { @@ -112,7 +112,7 @@ static int ubus_msg_writev(int fd, struct ubus_msg_buf *ub, int offset) .msg_controllen = sizeof(fd_buf), }; struct ubus_msghdr hdr; - int ret; + ssize_t ret; fd_buf.fd = ub->fd; if (ub->fd < 0 || offset) { @@ -156,7 +156,7 @@ static void ubus_msg_enqueue(struct ubus_client *cl, struct ubus_msg_buf *ub) /* takes the msgbuf reference */ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub) { - int written; + ssize_t written; if (ub->hdr.type != UBUS_MSG_MONITOR) ubusd_monitor_message(cl, ub, true); @@ -167,7 +167,7 @@ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub) if (written < 0) written = 0; - if (written >= ub->len + sizeof(ub->hdr)) + if (written >= (ssize_t) (ub->len + sizeof(ub->hdr))) return; cl->txq_ofs = written; @@ -232,7 +232,7 @@ static void client_cb(struct uloop_fd *sock, unsigned int events) /* first try to tx more pending data */ while ((ub = ubus_msg_head(cl))) { - int written; + ssize_t written; written = ubus_msg_writev(sock->fd, ub, cl->txq_ofs); if (written < 0) { @@ -259,7 +259,7 @@ static void client_cb(struct uloop_fd *sock, unsigned int events) uloop_fd_add(sock, ULOOP_READ | ULOOP_EDGE_TRIGGER); retry: - if (!sock->eof && cl->pending_msg_offset < sizeof(cl->hdrbuf)) { + if (!sock->eof && cl->pending_msg_offset < (int) sizeof(cl->hdrbuf)) { int offset = cl->pending_msg_offset; int bytes; @@ -284,7 +284,7 @@ retry: cl->pending_msg_fd = fd_buf.fd; cl->pending_msg_offset += bytes; - if (cl->pending_msg_offset < sizeof(cl->hdrbuf)) + if (cl->pending_msg_offset < (int) sizeof(cl->hdrbuf)) goto out; if (blob_pad_len(&cl->hdrbuf.data) > UBUS_MAX_MSGLEN) diff --git a/ubusd_acl.c b/ubusd_acl.c index 6257f811a651..f19df9a875c7 100644 --- a/ubusd_acl.c +++ b/ubusd_acl.c @@ -116,7 +116,7 @@ ubusd_acl_check(struct ubus_client *cl, const char *obj, if (!acl->partial) continue; - if (match_len != strlen(key)) + if (match_len != (int) strlen(key)) continue; } @@ -147,7 +147,7 @@ ubusd_acl_check(struct ubus_client *cl, const char *obj, case UBUS_ACL_ACCESS: if (acl->methods) { struct blob_attr *cur; - int rem; + size_t rem; blobmsg_for_each_attr(cur, acl->methods, rem) if (blobmsg_type(cur) == BLOBMSG_TYPE_STRING) @@ -332,7 +332,7 @@ static void ubusd_acl_file_add(struct ubusd_acl_file *file) { struct blob_attr *tb[__ACL_MAX], *cur; - int rem; + size_t rem; blobmsg_parse(acl_policy, __ACL_MAX, tb, blob_data(file->blob), blob_len(file->blob)); @@ -435,7 +435,7 @@ ubusd_acl_load(void) { struct stat st; glob_t gl; - int j; + size_t j; const char *suffix = "/*.json"; char *path = alloca(strlen(ubusd_acl_dir) + strlen(suffix) + 1); @@ -499,7 +499,7 @@ ubusd_reply_add(struct ubus_object *obj) if (!acl->partial) continue; - if (match_len != strlen(key)) + if (match_len != (int) strlen(key)) continue; } diff --git a/ubusd_event.c b/ubusd_event.c index 712e7049946a..d36bcb73ddda 100644 --- a/ubusd_event.c +++ b/ubusd_event.c @@ -167,7 +167,7 @@ int ubusd_send_event(struct ubus_client *cl, const char *id, if (!ev->partial) continue; - if (match_len != strlen(key)) + if (match_len != (int) strlen(key)) continue; } diff --git a/ubusd_obj.c b/ubusd_obj.c index 08314732567e..0c9cb9ae8208 100644 --- a/ubusd_obj.c +++ b/ubusd_obj.c @@ -55,7 +55,7 @@ static struct ubus_object_type *ubus_create_obj_type(struct blob_attr *sig) { struct ubus_object_type *type; struct blob_attr *pos; - int rem; + size_t rem; type = calloc(1, sizeof(*type)); if (!type) From patchwork Thu Dec 19 22:11:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213783 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="nbWSdtgV"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5jW0CHgz9sPJ for ; Fri, 20 Dec 2019 09:13:03 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uSCqAA8+cMNuHMlFp6ieSITmxnenGkmM4f3kaYdcrBs=; b=nbWSdtgVjUHFq1 9WZM4NiY61yyporbhuWOrRQHUe4y91hxHqU667c/QTGuOQSLZDhex2ZLvH6dcA54XDxyV01ES3NAy lAY4rs4IJc3mgtiAuL8kkcuVVkv0+JzliY1xq+3CF3lXH8gIZmYeclS38Hgpx+XHPWlGicRCA2rvg 4+7mdHBiKDEQWj89pcT4uwySF/3G5pzBI6uRHkCfqFI5JLbxbkIT2W7hWDpDxQRap5bxhzE8BFN3b rBqreHleV9wU3l9Psgc+VyLI91HWb/xuAehrNY967hn/qbUX3GMbqgJcu02LxC5wCDgmxFSI+X5yP ja7geeAUAbPIws+yGggw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii42W-0006zy-8a; Thu, 19 Dec 2019 22:13:00 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41J-000542-NT for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:47 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id BFD9C4BC0; Thu, 19 Dec 2019 23:11:43 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 6e2e93fe; Thu, 19 Dec 2019 23:11:33 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:14 +0100 Message-Id: <20191219221125.22646-6-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141145_936135_2E643108 X-CRM114-Status: UNSURE ( 8.07 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 05/16] libubus: fix incompatible pointer types assigment X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Fixes following error reported by clang-9 analyzer: libubus.c:286:19: error: incompatible pointer types assigning to 'struct blob_attr *' from 'char *' [-Werror,-Wincompatible-pointer-types] ctx->msgbuf.data = (char *) calloc(UBUS_MSG_CHUNK_SIZE, sizeof(char)); Result of 'calloc' is converted to a pointer of type 'struct blob_attr', which is incompatible with sizeof operand type 'char'. Signed-off-by: Petr Štetiar --- libubus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libubus.c b/libubus.c index 260e40f2f44b..846ae83bcc12 100644 --- a/libubus.c +++ b/libubus.c @@ -283,7 +283,7 @@ int ubus_connect_ctx(struct ubus_context *ctx, const char *path) ctx->connection_lost = ubus_default_connection_lost; ctx->pending_timer.cb = ubus_process_pending_msg; - ctx->msgbuf.data = calloc(UBUS_MSG_CHUNK_SIZE, sizeof(char)); + ctx->msgbuf.data = calloc(1, UBUS_MSG_CHUNK_SIZE); if (!ctx->msgbuf.data) return -1; ctx->msgbuf_data_len = UBUS_MSG_CHUNK_SIZE; From patchwork Thu Dec 19 22:11:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213785 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="VRmPINGX"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5k30CDdz9sPJ for ; Fri, 20 Dec 2019 09:13:31 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=STG5SZ2Ay3OnlTh/zFhzhu2agPC86wPyA0E5WosdEJk=; b=VRmPINGXNKnCH5 4R0G55PJAGnkK4XDpNASPEnqyem0BHREh7EwgoxGoUcoNQCosAmoNWxzzZLPFnIKzVWjeMxrxse0d O3w+iND30QfCxXbx3kgCo7lZ2AXrkuoi8WSmN3BqUKA519zozUeptFPGCVRBnTj3Z+I3UltvZYXvM n2X1DIfGGkKavTknV+vRMSOTc20+XOae4UJwmF98ly95/4W1rFPCu59xTRPrkGufEuX6ivP3JX03U wUrS7pzItGpfSa8FTRo5uFAewPqhRewllJyDxtAO1IaUyHl5JyF6bJvIJVWmDMtzIviCH6tJjZGF3 rrR1nsHmAmPqyiBZa+wQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii42z-0007sY-A7; Thu, 19 Dec 2019 22:13:29 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41J-000543-Nx for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:48 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id E21364BC4; Thu, 19 Dec 2019 23:11:43 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id f982a799; Thu, 19 Dec 2019 23:11:34 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:15 +0100 Message-Id: <20191219221125.22646-7-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141145_962389_1D6FF54F X-CRM114-Status: UNSURE ( 7.58 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 06/16] add initial GitLab CI support X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Uses currently proof-of-concept openwrt-ci[1] in order to: * improve the quality of the codebase in various areas * decrease code review time and help merging contributions faster * get automagic feedback loop on various platforms and tools - out of tree build with OpenWrt SDK on following targets: * ath79-generic * imx6-generic * malta-be * mvebu-cortexa53 - out of tree native build on x86/64 with GCC (versions 7, 8, 9) and Clang 10 - out of tree native x86/64 static code analysis with cppcheck and scan-build from Clang 9 1. https://gitlab.com/ynezz/openwrt-ci/ Signed-off-by: Petr Štetiar --- .gitlab-ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000000..1b4d5a795865 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,7 @@ +variables: + CI_TARGET_BUILD_DEPENDS: ubus + CI_CMAKE_EXTRA_BUILD_ARGS: -DLUAPATH=/usr/lib/lua + +include: + - remote: https://gitlab.com/ynezz/openwrt-ci/raw/master/openwrt-ci/gitlab/main.yml + - remote: https://gitlab.com/ynezz/openwrt-ci/raw/master/openwrt-ci/gitlab/pipeline.yml From patchwork Thu Dec 19 22:11:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213784 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="I/gvdI3x"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5jr6yH0z9sPJ for ; Fri, 20 Dec 2019 09:13:20 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Yyem5Vvwn12fxJzu8jIBq2Gu6Ti7kDYSslC5oqr35Aw=; b=I/gvdI3xhFnKdq te9UV4UoAgmYOJkIs0KRPcSxpnwHP3Qa05JUR3mv8hP2oTlU+A+SCmIL0YqdfL3Kmp1L7qi/IYrPO KuHwvpkycelir+PFFD5nbh1lk7ifbMNldqsTsj2rJG6xuqw7duLIqxPtmhcgRinMrIEGp0zDeqqbo DxM5XMoAJSX8Z85Vxj37xdPX3cG+lLfw+9W8qNd6aVH6DoritJJMC95FPekVAhbeLvQMQiAUurwlz 3KFGNw0dZ2N6enkE4u5HzI242RjB1aroAXAiB1ko5RhnMyyYBgF5/F4bnUlvEPlmM9tuRAxvaWYYg IGuWaGNft7E6Wm7UImEw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii42k-0007Rv-V4; Thu, 19 Dec 2019 22:13:14 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41J-000545-WA for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:48 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 0DEE04BC6; Thu, 19 Dec 2019 23:11:44 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 6d5759fe; Thu, 19 Dec 2019 23:11:34 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:16 +0100 Message-Id: <20191219221125.22646-8-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141146_208439_B45FF003 X-CRM114-Status: UNSURE ( 5.38 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 07/16] examples: remove dead increments X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Fixes following error reported by clang-9 analyzer: examples/server.c:244:2: warning: Value stored to 'argc' is never read argc -= optind; ^ ~~~~~~ examples/server.c:245:2: warning: Value stored to 'argv' is never read argv += optind; ^ ~~~~~~ Signed-off-by: Petr Štetiar --- examples/client.c | 3 --- examples/server.c | 3 --- 2 files changed, 6 deletions(-) diff --git a/examples/client.c b/examples/client.c index 7ef566347e54..aae09f480af4 100644 --- a/examples/client.c +++ b/examples/client.c @@ -220,9 +220,6 @@ int main(int argc, char **argv) } } - argc -= optind; - argv += optind; - uloop_init(); ctx = ubus_connect(ubus_socket); diff --git a/examples/server.c b/examples/server.c index 004eaf3a7ae1..0913fff0d016 100644 --- a/examples/server.c +++ b/examples/server.c @@ -241,9 +241,6 @@ int main(int argc, char **argv) } } - argc -= optind; - argv += optind; - uloop_init(); signal(SIGPIPE, SIG_IGN); From patchwork Thu Dec 19 22:11:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213787 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="P3GAl/G+"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5kW3vQKz9sPJ for ; Fri, 20 Dec 2019 09:13:55 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=b2HJ+n7ZDPutvKEpBP/nRq7yIleS0Ty0mlyVJN6VGm4=; b=P3GAl/G+z0G3mZ kaPilh3VsG3KT8tyBuDNhF+dE6NIEMgfYNQSEQLNiaqlBklt8wTfKtDUf4VeCnXIl1tpaxyHVpLsK Oc2Wvo/7aReUrNiWzgGBCIQ8lWVkh3LQ9sNcOUv6k9H3WHn0Lgc/NB2uenJ5KteMzvH9lHRCfkCzS l1HL+/5jvAVEqztvIqXyAccKk9O7tTtlcVrhZuY0MBMbZkJoB6dwxoukzpZGJtS6aZt2/IVW0MAP5 03OvlkY5x+ZfVmuqOgljLP7hkZ1DTigvP10BC0ahXL63QsdByP8wUx+fOX5YaUEU0uPBJ8BN3I+Xo 6gM6771FtI10Er15V/tw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii43N-000066-79; Thu, 19 Dec 2019 22:13:53 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41K-000546-88 for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:50 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 2DEB94BC8; Thu, 19 Dec 2019 23:11:44 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 07b0a3f0; Thu, 19 Dec 2019 23:11:34 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:17 +0100 Message-Id: <20191219221125.22646-9-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141146_624604_3E0AAF0D X-CRM114-Status: GOOD ( 19.36 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 08/16] refactor ubusd.c into reusable ubusd_library X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org In order to allow reusability in unit testing & fuzzing. Signed-off-by: Petr Štetiar --- CMakeLists.txt | 5 +- libubus-internal.h | 1 + libubus-io.c | 2 +- ubusd.c | 269 +------------------------------------------- ubusd.h | 1 + ubusd_main.c | 271 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 278 insertions(+), 271 deletions(-) create mode 100644 ubusd_main.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 866b3ab60168..dc6e42847086 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,8 +41,9 @@ TARGET_LINK_LIBRARIES(ubus ${ubox_library}) find_library(json NAMES json-c json) -ADD_EXECUTABLE(ubusd ubusd.c ubusd_id.c ubusd_obj.c ubusd_proto.c ubusd_event.c ubusd_acl.c ubusd_monitor.c) -TARGET_LINK_LIBRARIES(ubusd ${ubox_library} ${blob_library} ${json}) +ADD_LIBRARY(ubusd_library STATIC ubusd.c ubusd_proto.c ubusd_id.c ubusd_obj.c ubusd_event.c ubusd_acl.c ubusd_monitor.c) +ADD_EXECUTABLE(ubusd ubusd_main.c) +TARGET_LINK_LIBRARIES(ubusd ubusd_library ${ubox_library} ${blob_library} ${json}) ADD_EXECUTABLE(cli cli.c) SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME ubus) diff --git a/libubus-internal.h b/libubus-internal.h index c4067d343817..8cf99b3bc6b1 100644 --- a/libubus-internal.h +++ b/libubus-internal.h @@ -18,6 +18,7 @@ extern struct blob_buf b; extern const struct ubus_method watch_method; struct blob_attr **ubus_parse_msg(struct blob_attr *msg); +bool ubus_validate_hdr(struct ubus_msghdr *hdr); void ubus_handle_data(struct uloop_fd *u, unsigned int events); int ubus_send_msg(struct ubus_context *ctx, uint32_t seq, struct blob_attr *msg, int cmd, uint32_t peer, int fd); diff --git a/libubus-io.c b/libubus-io.c index 120fb605e90a..81c1cd1309b1 100644 --- a/libubus-io.c +++ b/libubus-io.c @@ -215,7 +215,7 @@ static int recv_retry(struct ubus_context *ctx, struct iovec *iov, bool wait, in return total; } -static bool ubus_validate_hdr(struct ubus_msghdr *hdr) +bool ubus_validate_hdr(struct ubus_msghdr *hdr) { struct blob_attr *data = (struct blob_attr *) (hdr + 1); diff --git a/ubusd.c b/ubusd.c index c020ff416a32..0d43977c0bde 100644 --- a/ubusd.c +++ b/ubusd.c @@ -12,21 +12,9 @@ */ #include -#include -#include #ifdef FreeBSD #include #endif -#include -#include -#include -#include -#include - -#include -#include -#include -#include #include "ubusd.h" @@ -92,7 +80,7 @@ void ubus_msg_free(struct ubus_msg_buf *ub) } } -static ssize_t ubus_msg_writev(int fd, struct ubus_msg_buf *ub, size_t offset) +ssize_t ubus_msg_writev(int fd, struct ubus_msg_buf *ub, size_t offset) { static struct iovec iov[2]; static struct { @@ -177,258 +165,3 @@ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub) } ubus_msg_enqueue(cl, ub); } - -static struct ubus_msg_buf *ubus_msg_head(struct ubus_client *cl) -{ - return cl->tx_queue[cl->txq_cur]; -} - -static void ubus_msg_dequeue(struct ubus_client *cl) -{ - struct ubus_msg_buf *ub = ubus_msg_head(cl); - - if (!ub) - return; - - ubus_msg_free(ub); - cl->txq_ofs = 0; - cl->tx_queue[cl->txq_cur] = NULL; - cl->txq_cur = (cl->txq_cur + 1) % ARRAY_SIZE(cl->tx_queue); -} - -static void handle_client_disconnect(struct ubus_client *cl) -{ - while (ubus_msg_head(cl)) - ubus_msg_dequeue(cl); - - ubusd_monitor_disconnect(cl); - ubusd_proto_free_client(cl); - if (cl->pending_msg_fd >= 0) - close(cl->pending_msg_fd); - uloop_fd_delete(&cl->sock); - close(cl->sock.fd); - free(cl); -} - -static void client_cb(struct uloop_fd *sock, unsigned int events) -{ - struct ubus_client *cl = container_of(sock, struct ubus_client, sock); - struct ubus_msg_buf *ub; - static struct iovec iov; - static struct { - int fd; - struct cmsghdr h; - } fd_buf = { - .h = { - .cmsg_type = SCM_RIGHTS, - .cmsg_level = SOL_SOCKET, - .cmsg_len = sizeof(fd_buf), - } - }; - struct msghdr msghdr = { - .msg_iov = &iov, - .msg_iovlen = 1, - }; - - /* first try to tx more pending data */ - while ((ub = ubus_msg_head(cl))) { - ssize_t written; - - written = ubus_msg_writev(sock->fd, ub, cl->txq_ofs); - if (written < 0) { - switch(errno) { - case EINTR: - case EAGAIN: - break; - default: - goto disconnect; - } - break; - } - - cl->txq_ofs += written; - if (cl->txq_ofs < ub->len + sizeof(ub->hdr)) - break; - - ubus_msg_dequeue(cl); - } - - /* prevent further ULOOP_WRITE events if we don't have data - * to send anymore */ - if (!ubus_msg_head(cl) && (events & ULOOP_WRITE)) - uloop_fd_add(sock, ULOOP_READ | ULOOP_EDGE_TRIGGER); - -retry: - if (!sock->eof && cl->pending_msg_offset < (int) sizeof(cl->hdrbuf)) { - int offset = cl->pending_msg_offset; - int bytes; - - fd_buf.fd = -1; - - iov.iov_base = ((char *) &cl->hdrbuf) + offset; - iov.iov_len = sizeof(cl->hdrbuf) - offset; - - if (cl->pending_msg_fd < 0) { - msghdr.msg_control = &fd_buf; - msghdr.msg_controllen = sizeof(fd_buf); - } else { - msghdr.msg_control = NULL; - msghdr.msg_controllen = 0; - } - - bytes = recvmsg(sock->fd, &msghdr, 0); - if (bytes < 0) - goto out; - - if (fd_buf.fd >= 0) - cl->pending_msg_fd = fd_buf.fd; - - cl->pending_msg_offset += bytes; - if (cl->pending_msg_offset < (int) sizeof(cl->hdrbuf)) - goto out; - - if (blob_pad_len(&cl->hdrbuf.data) > UBUS_MAX_MSGLEN) - goto disconnect; - - cl->pending_msg = ubus_msg_new(NULL, blob_raw_len(&cl->hdrbuf.data), false); - if (!cl->pending_msg) - goto disconnect; - - cl->hdrbuf.hdr.seq = be16_to_cpu(cl->hdrbuf.hdr.seq); - cl->hdrbuf.hdr.peer = be32_to_cpu(cl->hdrbuf.hdr.peer); - - memcpy(&cl->pending_msg->hdr, &cl->hdrbuf.hdr, sizeof(cl->hdrbuf.hdr)); - memcpy(cl->pending_msg->data, &cl->hdrbuf.data, sizeof(cl->hdrbuf.data)); - } - - ub = cl->pending_msg; - if (ub) { - int offset = cl->pending_msg_offset - sizeof(ub->hdr); - int len = blob_raw_len(ub->data) - offset; - int bytes = 0; - - if (len > 0) { - bytes = read(sock->fd, (char *) ub->data + offset, len); - if (bytes <= 0) - goto out; - } - - if (bytes < len) { - cl->pending_msg_offset += bytes; - goto out; - } - - /* accept message */ - ub->fd = cl->pending_msg_fd; - cl->pending_msg_fd = -1; - cl->pending_msg_offset = 0; - cl->pending_msg = NULL; - ubusd_monitor_message(cl, ub, false); - ubusd_proto_receive_message(cl, ub); - goto retry; - } - -out: - if (!sock->eof || ubus_msg_head(cl)) - return; - -disconnect: - handle_client_disconnect(cl); -} - -static bool get_next_connection(int fd) -{ - struct ubus_client *cl; - int client_fd; - - client_fd = accept(fd, NULL, 0); - if (client_fd < 0) { - switch (errno) { - case ECONNABORTED: - case EINTR: - return true; - default: - return false; - } - } - - cl = ubusd_proto_new_client(client_fd, client_cb); - if (cl) - uloop_fd_add(&cl->sock, ULOOP_READ | ULOOP_EDGE_TRIGGER); - else - close(client_fd); - - return true; -} - -static void server_cb(struct uloop_fd *fd, unsigned int events) -{ - bool next; - - do { - next = get_next_connection(fd->fd); - } while (next); -} - -static struct uloop_fd server_fd = { - .cb = server_cb, -}; - -static int usage(const char *progname) -{ - fprintf(stderr, "Usage: %s []\n" - "Options: \n" - " -A : Set the path to ACL files\n" - " -s : Set the unix domain socket to listen on\n" - "\n", progname); - return 1; -} - -static void sighup_handler(int sig) -{ - ubusd_acl_load(); -} - -int main(int argc, char **argv) -{ - const char *ubus_socket = UBUS_UNIX_SOCKET; - int ret = 0; - int ch; - - signal(SIGPIPE, SIG_IGN); - signal(SIGHUP, sighup_handler); - - openlog("ubusd", LOG_PID, LOG_DAEMON); - uloop_init(); - - while ((ch = getopt(argc, argv, "A:s:")) != -1) { - switch (ch) { - case 's': - ubus_socket = optarg; - break; - case 'A': - ubusd_acl_dir = optarg; - break; - default: - return usage(argv[0]); - } - } - - unlink(ubus_socket); - umask(0111); - server_fd.fd = usock(USOCK_UNIX | USOCK_SERVER | USOCK_NONBLOCK, ubus_socket, NULL); - if (server_fd.fd < 0) { - perror("usock"); - ret = -1; - goto out; - } - uloop_fd_add(&server_fd, ULOOP_READ | ULOOP_EDGE_TRIGGER); - ubusd_acl_load(); - - uloop_run(); - unlink(ubus_socket); - -out: - uloop_done(); - return ret; -} diff --git a/ubusd.h b/ubusd.h index 4d879201e2f5..867cde9a384b 100644 --- a/ubusd.h +++ b/ubusd.h @@ -70,6 +70,7 @@ extern const char *ubusd_acl_dir; struct ubus_msg_buf *ubus_msg_new(void *data, int len, bool shared); void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub); +ssize_t ubus_msg_writev(int fd, struct ubus_msg_buf *ub, size_t offset); void ubus_msg_free(struct ubus_msg_buf *ub); struct blob_attr **ubus_parse_msg(struct blob_attr *msg); diff --git a/ubusd_main.c b/ubusd_main.c new file mode 100644 index 000000000000..81868c1482bc --- /dev/null +++ b/ubusd_main.c @@ -0,0 +1,271 @@ +/* + * Copyright (C) 2011-2014 Felix Fietkau + * + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#include +#include +#ifdef FreeBSD +#include +#endif +#include + +#include + +#include "ubusd.h" + +static struct ubus_msg_buf *ubus_msg_head(struct ubus_client *cl) +{ + return cl->tx_queue[cl->txq_cur]; +} + +static void ubus_msg_dequeue(struct ubus_client *cl) +{ + struct ubus_msg_buf *ub = ubus_msg_head(cl); + + if (!ub) + return; + + ubus_msg_free(ub); + cl->txq_ofs = 0; + cl->tx_queue[cl->txq_cur] = NULL; + cl->txq_cur = (cl->txq_cur + 1) % ARRAY_SIZE(cl->tx_queue); +} + +static void handle_client_disconnect(struct ubus_client *cl) +{ + while (ubus_msg_head(cl)) + ubus_msg_dequeue(cl); + + ubusd_monitor_disconnect(cl); + ubusd_proto_free_client(cl); + if (cl->pending_msg_fd >= 0) + close(cl->pending_msg_fd); + uloop_fd_delete(&cl->sock); + close(cl->sock.fd); + free(cl); +} + +static void client_cb(struct uloop_fd *sock, unsigned int events) +{ + struct ubus_client *cl = container_of(sock, struct ubus_client, sock); + struct ubus_msg_buf *ub; + static struct iovec iov; + static struct { + int fd; + struct cmsghdr h; + } fd_buf = { + .h = { + .cmsg_type = SCM_RIGHTS, + .cmsg_level = SOL_SOCKET, + .cmsg_len = sizeof(fd_buf), + } + }; + struct msghdr msghdr = { + .msg_iov = &iov, + .msg_iovlen = 1, + }; + + /* first try to tx more pending data */ + while ((ub = ubus_msg_head(cl))) { + ssize_t written; + + written = ubus_msg_writev(sock->fd, ub, cl->txq_ofs); + if (written < 0) { + switch(errno) { + case EINTR: + case EAGAIN: + break; + default: + goto disconnect; + } + break; + } + + cl->txq_ofs += written; + if (cl->txq_ofs < ub->len + sizeof(ub->hdr)) + break; + + ubus_msg_dequeue(cl); + } + + /* prevent further ULOOP_WRITE events if we don't have data + * to send anymore */ + if (!ubus_msg_head(cl) && (events & ULOOP_WRITE)) + uloop_fd_add(sock, ULOOP_READ | ULOOP_EDGE_TRIGGER); + +retry: + if (!sock->eof && cl->pending_msg_offset < (int) sizeof(cl->hdrbuf)) { + int offset = cl->pending_msg_offset; + int bytes; + + fd_buf.fd = -1; + + iov.iov_base = ((char *) &cl->hdrbuf) + offset; + iov.iov_len = sizeof(cl->hdrbuf) - offset; + + if (cl->pending_msg_fd < 0) { + msghdr.msg_control = &fd_buf; + msghdr.msg_controllen = sizeof(fd_buf); + } else { + msghdr.msg_control = NULL; + msghdr.msg_controllen = 0; + } + + bytes = recvmsg(sock->fd, &msghdr, 0); + if (bytes < 0) + goto out; + + if (fd_buf.fd >= 0) + cl->pending_msg_fd = fd_buf.fd; + + cl->pending_msg_offset += bytes; + if (cl->pending_msg_offset < (int) sizeof(cl->hdrbuf)) + goto out; + + if (blob_pad_len(&cl->hdrbuf.data) > UBUS_MAX_MSGLEN) + goto disconnect; + + cl->pending_msg = ubus_msg_new(NULL, blob_raw_len(&cl->hdrbuf.data), false); + if (!cl->pending_msg) + goto disconnect; + + cl->hdrbuf.hdr.seq = be16_to_cpu(cl->hdrbuf.hdr.seq); + cl->hdrbuf.hdr.peer = be32_to_cpu(cl->hdrbuf.hdr.peer); + + memcpy(&cl->pending_msg->hdr, &cl->hdrbuf.hdr, sizeof(cl->hdrbuf.hdr)); + memcpy(cl->pending_msg->data, &cl->hdrbuf.data, sizeof(cl->hdrbuf.data)); + } + + ub = cl->pending_msg; + if (ub) { + int offset = cl->pending_msg_offset - sizeof(ub->hdr); + int len = blob_raw_len(ub->data) - offset; + int bytes = 0; + + if (len > 0) { + bytes = read(sock->fd, (char *) ub->data + offset, len); + if (bytes <= 0) + goto out; + } + + if (bytes < len) { + cl->pending_msg_offset += bytes; + goto out; + } + + /* accept message */ + ub->fd = cl->pending_msg_fd; + cl->pending_msg_fd = -1; + cl->pending_msg_offset = 0; + cl->pending_msg = NULL; + ubusd_monitor_message(cl, ub, false); + ubusd_proto_receive_message(cl, ub); + goto retry; + } + +out: + if (!sock->eof || ubus_msg_head(cl)) + return; + +disconnect: + handle_client_disconnect(cl); +} + +static bool get_next_connection(int fd) +{ + struct ubus_client *cl; + int client_fd; + + client_fd = accept(fd, NULL, 0); + if (client_fd < 0) { + switch (errno) { + case ECONNABORTED: + case EINTR: + return true; + default: + return false; + } + } + + cl = ubusd_proto_new_client(client_fd, client_cb); + if (cl) + uloop_fd_add(&cl->sock, ULOOP_READ | ULOOP_EDGE_TRIGGER); + else + close(client_fd); + + return true; +} + +static void server_cb(struct uloop_fd *fd, unsigned int events) +{ + bool next; + + do { + next = get_next_connection(fd->fd); + } while (next); +} + +static struct uloop_fd server_fd = { + .cb = server_cb, +}; + +static int usage(const char *progname) +{ + fprintf(stderr, "Usage: %s []\n" + "Options: \n" + " -A : Set the path to ACL files\n" + " -s : Set the unix domain socket to listen on\n" + "\n", progname); + return 1; +} + +static void sighup_handler(int sig) +{ + ubusd_acl_load(); +} + +int main(int argc, char **argv) +{ + const char *ubus_socket = UBUS_UNIX_SOCKET; + int ret = 0; + int ch; + + signal(SIGPIPE, SIG_IGN); + signal(SIGHUP, sighup_handler); + + openlog("ubusd", LOG_PID, LOG_DAEMON); + uloop_init(); + + while ((ch = getopt(argc, argv, "A:s:")) != -1) { + switch (ch) { + case 's': + ubus_socket = optarg; + break; + case 'A': + ubusd_acl_dir = optarg; + break; + default: + return usage(argv[0]); + } + } + + unlink(ubus_socket); + umask(0111); + server_fd.fd = usock(USOCK_UNIX | USOCK_SERVER | USOCK_NONBLOCK, ubus_socket, NULL); + if (server_fd.fd < 0) { + perror("usock"); + ret = -1; + goto out; + } + uloop_fd_add(&server_fd, ULOOP_READ | ULOOP_EDGE_TRIGGER); + ubusd_acl_load(); + + uloop_run(); + unlink(ubus_socket); + +out: + uloop_done(); + return ret; +} From patchwork Thu Dec 19 22:11:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213788 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qoD0Gexo"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5kt31bPz9sPJ for ; Fri, 20 Dec 2019 09:14:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XNgFNALV3xGYeW29ijQqJMJlNndvSnXhCATT6R/Q7MY=; b=qoD0GexoWV7EQB 2g3R0Hw3ztI1MNQj5k9QRbGsfpRTuGL3touNkLMmkxgq1d/Dd+U4zxPzQNnoODAx6VU4mRZsKLcBM H1oQZLcEwmsbsSIB74Qr/Hn9T3x9sLKE2XxdyuApoD2oT7yz6zdkd8boaGwUTGhXpfJqzpVMEb5HJ zQ/doojQYLjUhoX7A+pWX8EC1Nm0+lfhtcvu4ALADBbv4J3yDvN1fxVRkfADN1pOKWw3vjsJjZUgq 7OtDCjU7EUsW5ToSWn7k3vvDvf2U8714R/lNAkdIAV3W/Jn5n1Y4mMbVBGElXYPy7wmGvtPWhxu/I 7otNKSbYBhzkjepVbCUw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii43a-0000XI-7P; Thu, 19 Dec 2019 22:14:06 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41L-00054u-Ch for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:51 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id A7ABA4BCC; Thu, 19 Dec 2019 23:11:45 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id c1d5be37; Thu, 19 Dec 2019 23:11:35 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:19 +0100 Message-Id: <20191219221125.22646-11-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141147_609926_F66EC3ED X-CRM114-Status: UNSURE ( 8.25 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 10/16] lua: workaround false positive dereference of null pointer X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org scan-build from clang-9 has reported following: ubus.c:837:16: warning: Access to field 'rnotify' results in a dereference of a null pointer (loaded from variable 'sub') sub->rnotify = luaL_ref(L, -2); Which is false positive as the lua_error() does a long jump and therefore never returns and this long jump probably confuses the static analyzer. So this patch workarounds this false positive by helping static analyzer by using common Lua idiom which is to return lua_error()'s return value. Ref: https://www.lua.org/manual/5.1/manual.html#lua_error Addresses-Coverity-ID: 1412355 ("Dereference after null check") Signed-off-by: Petr Štetiar --- lua/ubus.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lua/ubus.c b/lua/ubus.c index 6fbbc0686af3..fb50418d27b0 100644 --- a/lua/ubus.c +++ b/lua/ubus.c @@ -557,8 +557,7 @@ static int ubus_lua_add(lua_State *L) /* verify top level object */ if (lua_istable(L, 1)) { lua_pushstring(L, "you need to pass a table"); - lua_error(L); - return 0; + return lua_error(L); } /* scan each object */ @@ -598,7 +597,7 @@ ubus_lua_notify( lua_State *L ) if( !lua_islightuserdata( L, 2 ) ){ lua_pushfstring( L, "Invald 2nd parameter, expected ubus obj ref" ); - lua_error( L ); + return lua_error( L ); } obj = lua_touserdata( L, 2 ); @@ -606,7 +605,7 @@ ubus_lua_notify( lua_State *L ) blob_buf_init(&c->buf, 0); if( !ubus_lua_format_blob_array( L, &c->buf, true ) ){ lua_pushfstring( L, "Invalid 4th parameter, expected table of arguments" ); - lua_error( L ); + return lua_error( L ); } ubus_notify( c->ctx, obj, method, c->buf.head, -1 ); @@ -812,7 +811,7 @@ ubus_sub_notify_handler(struct ubus_context *ctx, struct ubus_object *obj, -static void +static int ubus_lua_do_subscribe( struct ubus_context *ctx, lua_State *L, const char* target, int idxnotify, int idxremove ) { @@ -822,13 +821,13 @@ ubus_lua_do_subscribe( struct ubus_context *ctx, lua_State *L, const char* targe if( ( status = ubus_lookup_id( ctx, target, &id ) ) ){ lua_pushfstring( L, "Unable find target, status=%d", status ); - lua_error( L ); + return lua_error( L ); } sub = calloc( 1, sizeof( struct ubus_lua_subscriber ) ); if( !sub ){ lua_pushstring( L, "Out of memory" ); - lua_error( L ); + return lua_error( L ); } if( idxnotify ){ @@ -849,13 +848,15 @@ ubus_lua_do_subscribe( struct ubus_context *ctx, lua_State *L, const char* targe if( ( status = ubus_register_subscriber( ctx, &sub->s ) ) ){ lua_pushfstring( L, "Failed to register subscriber, status=%d", status ); - lua_error( L ); + return lua_error( L ); } if( ( status = ubus_subscribe( ctx, &sub->s, id) ) ){ lua_pushfstring( L, "Failed to register subscriber, status=%d", status ); - lua_error( L ); + return lua_error( L ); } + + return 0; } static int From patchwork Thu Dec 19 22:11:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213786 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ipMmLrgM"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5kL2Gcbz9sPJ for ; Fri, 20 Dec 2019 09:13:46 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GBg4oNgwzDpQWggqlBmW4HURAYIhoeHDRwlPBsHClRs=; b=ipMmLrgMyFnRKH LaqS9jGUB8ipexQ4J3pej4KiHGS8K1gOd+91H6xBp499OQt2xUFXzT+YzyUaYFy7/6xg4gSl0UJM1 Cic/6UnI2p9hd8jo9Bxk/+EoyJ+V1TKOGps2U2p1rgQFTeb5rKolbZNfOxvtZaRaRQf51UYnAFAtn svFqeWI2HuohZOb68EeLbMRaXCGk5rZdfCLKjRySbIIX2EfY8LRTGDy0b08CfHChNXJy2W6I1yzHk aeg0Xci/YqG5wGiPTHQJ6Z7rgC/4ArstDneXcO0s1ECgiZmmnqoWngXkuqxGP52lOQr+RUrjeJOJr K8Vq3rLsnqQ/NPlDg0Aw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii43B-00088d-CX; Thu, 19 Dec 2019 22:13:41 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41L-00054t-CH for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:49 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id E03904BCD; Thu, 19 Dec 2019 23:11:45 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 6f4e2f23; Thu, 19 Dec 2019 23:11:36 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:20 +0100 Message-Id: <20191219221125.22646-12-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141147_570433_164DB2DF X-CRM114-Status: UNSURE ( 6.78 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 11/16] lua: ubus_lua_do_subscribe: fix copy&paste error X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Fix copy&paste error in Lua ubus subscriber removal callback. Addresses-Coverity-ID: 1412311 ("Copy-paste error") Signed-off-by: Petr Štetiar --- lua/ubus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/ubus.c b/lua/ubus.c index fb50418d27b0..86dcc5007b3a 100644 --- a/lua/ubus.c +++ b/lua/ubus.c @@ -840,8 +840,8 @@ ubus_lua_do_subscribe( struct ubus_context *ctx, lua_State *L, const char* targe if( idxremove ){ lua_getglobal(L, "__ubus_cb_subscribe"); - lua_pushvalue(L, idxnotify); - sub->rnotify = luaL_ref(L, -2); + lua_pushvalue(L, idxremove); + sub->rremove = luaL_ref(L, -2); lua_pop(L, 1); sub->s.remove_cb = ubus_sub_remove_handler; } From patchwork Thu Dec 19 22:11:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213791 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GFF1PJar"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5lK3K84z9sPL for ; Fri, 20 Dec 2019 09:14:37 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ymTXrmcmsEDQk+ozNUITreK2s+CwKthDy9Gd3IlKgT8=; b=GFF1PJar4+PIwy 7rVh00aZDLzwhSLsyrV0oumJbVCXMFmO8xHPEcgPYNphQohU1xRBaEnZgJZtzHvNCEEKNeZeX36Tw lgxhSmWyeSoYi5Dl6apl6Oj4GLS3u8vZmzHa4NaP2Xo8CambjTHrLHLJ4etVa9GoP4Knr5lesvv0C 2Jg1y4SsWdVxjWaCRd8UgmJimKcpEBJZ9f/V73Y/sX8lFIyX2sljlfwg0wj40Ut4s6psodbvBdmm8 3gBAKefEn69VxkBE0LT/tcPzPchLCuigQ09t7PTPIREsOGsX9PDOuLKhGmtmg/fQ6XRKOgEbTeJAe d8HTJFcFesI2CWlmThWA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii43z-0001Lq-Lo; Thu, 19 Dec 2019 22:14:31 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41L-000554-Ie for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:51 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 25DCE4BD0; Thu, 19 Dec 2019 23:11:46 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 0c98974c; Thu, 19 Dec 2019 23:11:36 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:21 +0100 Message-Id: <20191219221125.22646-13-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141147_945949_976935D5 X-CRM114-Status: UNSURE ( 9.13 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 12/16] workaround possibly false positive uses of memory after it is freed X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org scan-build from clang-9 has reported following: libubox/list.h:83:22: warning: Use of memory after it is freed entry->next->prev = entry->prev; ^~~~~~~~~~~ ubusd_event.c:42:3: warning: Use of memory after it is freed ubusd_delete_event_source(ev); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Which might be a false positives, but in order to make the code pass the static analyzer checks, rewrite the while loops on lists with the safe list iterator. Signed-off-by: Petr Štetiar --- libubus-req.c | 6 ++---- libubus.c | 8 +++++--- ubusd_event.c | 5 ++--- ubusd_obj.c | 5 ++--- ubusd_proto.c | 6 +++--- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/libubus-req.c b/libubus-req.c index 97785a1e24cd..fd9a548839e4 100644 --- a/libubus-req.c +++ b/libubus-req.c @@ -40,11 +40,9 @@ static void req_data_cb(struct ubus_request *req, int type, struct blob_attr *da static void __ubus_process_req_data(struct ubus_request *req) { - struct ubus_pending_data *data; + struct ubus_pending_data *data, *tmp; - while (!list_empty(&req->pending)) { - data = list_first_entry(&req->pending, - struct ubus_pending_data, list); + list_for_each_entry_safe(data, tmp, &req->pending, list) { list_del(&data->list); if (!req->cancelled) req_data_cb(req, data->type, data->data); diff --git a/libubus.c b/libubus.c index 846ae83bcc12..b405891416c2 100644 --- a/libubus.c +++ b/libubus.c @@ -115,10 +115,12 @@ ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd) static void ubus_process_pending_msg(struct uloop_timeout *timeout) { struct ubus_context *ctx = container_of(timeout, struct ubus_context, pending_timer); - struct ubus_pending_msg *pending; + struct ubus_pending_msg *pending, *tmp; + + list_for_each_entry_safe(pending, tmp, &ctx->pending, list) { + if (ctx->stack_depth) + break; - while (!ctx->stack_depth && !list_empty(&ctx->pending)) { - pending = list_first_entry(&ctx->pending, struct ubus_pending_msg, list); list_del(&pending->list); ubus_process_msg(ctx, &pending->hdr, -1); free(pending); diff --git a/ubusd_event.c b/ubusd_event.c index d36bcb73ddda..ef433f81a71e 100644 --- a/ubusd_event.c +++ b/ubusd_event.c @@ -35,10 +35,9 @@ static void ubusd_delete_event_source(struct event_source *evs) void ubusd_event_cleanup_object(struct ubus_object *obj) { - struct event_source *ev; + struct event_source *ev, *tmp; - while (!list_empty(&obj->events)) { - ev = list_first_entry(&obj->events, struct event_source, list); + list_for_each_entry_safe(ev, tmp, &obj->events, list) { ubusd_delete_event_source(ev); } } diff --git a/ubusd_obj.c b/ubusd_obj.c index 0c9cb9ae8208..dd44882e08d5 100644 --- a/ubusd_obj.c +++ b/ubusd_obj.c @@ -20,13 +20,12 @@ struct avl_tree path; static void ubus_unref_object_type(struct ubus_object_type *type) { - struct ubus_method *m; + struct ubus_method *m, *tmp; if (--type->refcount > 0) return; - while (!list_empty(&type->methods)) { - m = list_first_entry(&type->methods, struct ubus_method, list); + list_for_each_entry_safe(m, tmp, &type->methods, list) { list_del(&m->list); free(m); } diff --git a/ubusd_proto.c b/ubusd_proto.c index 2d04b5a7da6e..4dd89ddb4939 100644 --- a/ubusd_proto.c +++ b/ubusd_proto.c @@ -519,12 +519,12 @@ free: void ubusd_proto_free_client(struct ubus_client *cl) { - struct ubus_object *obj; + struct ubus_object *obj, *tmp; - while (!list_empty(&cl->objects)) { - obj = list_first_entry(&cl->objects, struct ubus_object, list); + list_for_each_entry_safe(obj, tmp, &cl->objects, list) { ubusd_free_object(obj); } + ubus_msg_free(cl->retmsg); blob_buf_free(&cl->b); From patchwork Thu Dec 19 22:11:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213792 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="kgWvcg1i"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5lX4mZFz9sPL for ; Fri, 20 Dec 2019 09:14:48 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=itQKOEIAvgVyEtmuj0kti/UO4T+TC4E/oMVO5VA6U/0=; b=kgWvcg1i5cfwAf D2YwtVTsnIlHM8i7ESaOnAKjuR/e6+EysVP/HjMwuyPREUxZP5Ycndv1x3qxJ07l6jGTVGtIjTLg3 mVyvqA2zt53MEQj/gn+o26IA2xrVxS5mjoA89MZaDPxzs5ZbKarCQEYwMSOJ6NLzA2ZV3o7Qsx8bg jqyiIq6JIPNYjs+y42UcOGz3gJcNREcCDBPeyEVSjQ0uPR1WJfikfMHJ0/pHZjnww/IzJZkM26LvE TTP42+RN3Ryu90pM7KkecvHDxrLJIfP/kTNz0ugUZ5PQxDEu0PIWlobYyf0mlXRxmCzEjj6mfmUgs 8J6+oxAmLHSrTOjpHu/g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii44E-0001fW-Qk; Thu, 19 Dec 2019 22:14:46 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41L-00055N-R8 for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:51 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 5EADC4BD2; Thu, 19 Dec 2019 23:11:46 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 491a31bb; Thu, 19 Dec 2019 23:11:37 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:22 +0100 Message-Id: <20191219221125.22646-14-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141148_071806_70A3D887 X-CRM114-Status: UNSURE ( 6.77 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 13/16] ubus_common: remove duplicate ARRAY_SIZE and add missing include X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org ARRAY_SIZE is available from libubox/utils.h. Signed-off-by: Petr Štetiar --- ubus_common.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ubus_common.h b/ubus_common.h index 5e4d0ad94f8f..502e5c484a75 100644 --- a/ubus_common.h +++ b/ubus_common.h @@ -14,13 +14,11 @@ #ifndef __UBUS_COMMON_H #define __UBUS_COMMON_H +#include + #define UBUS_SIGNATURE_METHOD (BLOBMSG_TYPE_LAST + 1) #define UBUS_SIGNATURE_END (BLOBMSG_TYPE_LAST + 2) -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -#endif - static inline bool ubus_strmatch_len(const char *s1, const char *s2, int *len) { for (*len = 0; s1[*len] == s2[*len]; (*len)++) From patchwork Thu Dec 19 22:11:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213789 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="C8U6v8vC"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5l014Q1z9sPJ for ; Fri, 20 Dec 2019 09:14:20 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9ArOWCP0U2XF5kZarQWnDDxU/HW42NEmJyyGo+jnN70=; b=C8U6v8vCGTUpE4 i9stm9kU9QXtibae5rYLnxqbe8V0IKcpo1uXJ8ekLts+Viz2mfBK+5gybODVbIwrNfHbDg1MzYlpx lcWJrjF75Pq2lUm38xrVLdWOOjJi9x3mAfKUKONxP3tqq9qJ8fdtCaaG0oN/SAMoNi8ElqxZ5omek HnQjRtNkhzMSTFVjtmY6OCP/IR1L1XJp1bv9+j+CEn2kCCmph5VP/0v/I7NcEaLKEUkPqigACh9cz Gd4TEyfXzww9EP/gX59unTJNuG98ISuKU7azZ+H4Ory1j8pPVI+pTQFgjNKqrwx5ZNPfwKw6Its6l M/W7aOqiiqaCPlyqOD0A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii43m-0000q7-FI; Thu, 19 Dec 2019 22:14:18 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41N-00056b-42 for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:51 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 978C54BD3; Thu, 19 Dec 2019 23:11:47 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 86e41df0; Thu, 19 Dec 2019 23:11:37 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:23 +0100 Message-Id: <20191219221125.22646-15-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141149_376966_F55B165B X-CRM114-Status: UNSURE ( 9.20 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 14/16] ubusd_monitor: fix possible null pointer dereference X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This dereference could possibly happen if the calloc call fails as the return value is unchecked. While at it refactor the code little bit to make it easier to follow, use safe list iterator and provide return value for ubusd_monitor_connect. Signed-off-by: Petr Štetiar --- ubusd_monitor.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/ubusd_monitor.c b/ubusd_monitor.c index fcbc6a4b10c0..501e06d0716c 100644 --- a/ubusd_monitor.c +++ b/ubusd_monitor.c @@ -29,7 +29,7 @@ ubusd_monitor_free(struct ubus_monitor *m) free(m); } -static void +static bool ubusd_monitor_connect(struct ubus_client *cl, struct ubus_msg_buf *ub) { struct ubus_monitor *m; @@ -37,22 +37,40 @@ ubusd_monitor_connect(struct ubus_client *cl, struct ubus_msg_buf *ub) ubusd_monitor_disconnect(cl); m = calloc(1, sizeof(*m)); + if (!m) + return false; + m->cl = cl; list_add(&m->list, &monitors); + + return true; } -void -ubusd_monitor_disconnect(struct ubus_client *cl) +static struct ubus_monitor* +ubusd_monitor_find(struct ubus_client *cl) { - struct ubus_monitor *m; + struct ubus_monitor *m, *tmp; - list_for_each_entry(m, &monitors, list) { + list_for_each_entry_safe(m, tmp, &monitors, list) { if (m->cl != cl) continue; - ubusd_monitor_free(m); - return; + return m; } + + return NULL; +} + +void +ubusd_monitor_disconnect(struct ubus_client *cl) +{ + struct ubus_monitor *m; + + m = ubusd_monitor_find(cl); + if (!m) + return; + + ubusd_monitor_free(m); } void @@ -92,13 +110,15 @@ ubusd_monitor_recv(struct ubus_client *cl, struct ubus_msg_buf *ub, return UBUS_STATUS_PERMISSION_DENIED; if (!strcmp(method, "add")) { - ubusd_monitor_connect(cl, ub); - return 0; + if (!ubusd_monitor_connect(cl, ub)) + return UBUS_STATUS_UNKNOWN_ERROR; + + return UBUS_STATUS_OK; } if (!strcmp(method, "remove")) { ubusd_monitor_disconnect(cl); - return 0; + return UBUS_STATUS_OK; } return UBUS_STATUS_METHOD_NOT_FOUND; From patchwork Thu Dec 19 22:11:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213794 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Wvip70Tl"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5mB3lfCz9sPJ for ; Fri, 20 Dec 2019 09:15:22 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RkBHdFeRilPuVWe71ujPKBAZ4PuvcJanOCBz07bNNgA=; b=Wvip70TlutY0em wNic/j7MHyLprAKwFmJPvAQZGbb6fRmaBo0sd90JP6+MJgbOppK9/1kA9322iHgvtx/mkZLSDvr9t jT5fqiLFDEbSErlfFeDtYhoeyObn/xVucSav8chEx0kCeuhOY/QzruwfTIych9xh+8mCZDZU8TOxY mc+8yvNKjuyaFBWZDeTtwUqh0TAqFNqSftJG5DLnbM4eNOK0dSQ3H+I/xZoJ3DQuVplPterEFuMEm yKdjmjvvpEuZCMnlxfxp1VBEa0B/oXZnfMEBTOjCOIbH4slDMfEO5qcfKIHcnMJx5SIj3C7l5xmNr SwHra9R0vXBn3ktzi7Lg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii44i-0003hh-PI; Thu, 19 Dec 2019 22:15:16 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41N-000578-6f for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:53 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id B6E3C4BD4; Thu, 19 Dec 2019 23:11:47 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 34ac4c80; Thu, 19 Dec 2019 23:11:37 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:24 +0100 Message-Id: <20191219221125.22646-16-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141149_454843_0CB2D6EF X-CRM114-Status: UNSURE ( 7.89 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 15/16] ubus_monitor: workaround possibly false positive uses of memory after it is freed X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org scan-build from clang-9 has reported following: libubox/list.h:141:2: warning: Use of memory after it is freed _list_add(_new, head, head->next); Signed-off-by: Petr Štetiar --- ubusd_monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ubusd_monitor.c b/ubusd_monitor.c index 501e06d0716c..bba741e86987 100644 --- a/ubusd_monitor.c +++ b/ubusd_monitor.c @@ -41,7 +41,7 @@ ubusd_monitor_connect(struct ubus_client *cl, struct ubus_msg_buf *ub) return false; m->cl = cl; - list_add(&m->list, &monitors); + list_add_tail(&m->list, &monitors); return true; } From patchwork Thu Dec 19 22:11:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213793 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IbuqKzU5"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47f5ls2BQnz9sPJ for ; Fri, 20 Dec 2019 09:15:05 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0W8I9nV4uPZpBU3lOVGzqn2VZjVs7YPazAVidi67xAY=; b=IbuqKzU5pi2vY3 oxq4TFtKWn91tNpGUAzxmpMLimEVu2FbaNbYwWWYc/M+WpEz4P1qLH4fj3eN7/xH/tolj2PAuve1q 6B8MHEbkVZU8yaTNxS1+JOjHxf4yRdUhn8eCNE3NnzCLhaXIUloUgY4ES+1Rg+b+rMn0TvpoHVlfG slFWJRxDy71kE3MURWG9y1y/GreqclSI/hiWNhsgddLfGeIJMjc6UIJ/vtHK3mJBTENGrqKrPF0iS tKeIT+bj+wpYHgqlANkzoR8UMzpdqNdUhZ440zqC9I6sC5QuVLzcZAIarDd0iCtuRykS3lqfNvKxl 0qL0UacznmPqFFQAutSQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii44T-0002GL-NV; Thu, 19 Dec 2019 22:15:02 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41N-00057J-D0 for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:54 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id F03154BD5; Thu, 19 Dec 2019 23:11:47 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 06dd6a15; Thu, 19 Dec 2019 23:11:38 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:25 +0100 Message-Id: <20191219221125.22646-17-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141149_867967_BA965D60 X-CRM114-Status: GOOD ( 13.21 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 16/16] fix blob parsing vulnerability by using blob_parse_untrusted X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org blob_parse expects blobs from trusted inputs, but it can be supplied with possibly malicious blobs from untrusted inputs as well, which might lead to undefined behaviour and/or crash of ubus daemon. In order to prevent such conditions, switch to blob_parse_untrusted which should hopefully handle such untrusted inputs appropriately. Signed-off-by: Petr Štetiar --- cli.c | 2 +- libubus-internal.h | 2 +- libubus-io.c | 4 ++-- libubus-obj.c | 6 +++--- libubus-req.c | 6 +++--- libubus.c | 4 ++-- tests/fuzz/test-fuzz.c | 2 +- ubusd.h | 2 +- ubusd_acl.c | 2 +- ubusd_proto.c | 6 +++--- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cli.c b/cli.c index 421f244ad9dc..f566279b4f6d 100644 --- a/cli.c +++ b/cli.c @@ -472,7 +472,7 @@ ubus_cli_monitor_cb(struct ubus_context *ctx, uint32_t seq, struct blob_attr *ms bool send; char *data; - blob_parse(msg, tb, policy, UBUS_MONITOR_MAX); + blob_parse_untrusted(msg, blob_raw_len(msg), tb, policy, UBUS_MONITOR_MAX); if (!tb[UBUS_MONITOR_CLIENT] || !tb[UBUS_MONITOR_PEER] || diff --git a/libubus-internal.h b/libubus-internal.h index 8cf99b3bc6b1..24477a032144 100644 --- a/libubus-internal.h +++ b/libubus-internal.h @@ -17,7 +17,7 @@ extern struct blob_buf b; extern const struct ubus_method watch_method; -struct blob_attr **ubus_parse_msg(struct blob_attr *msg); +struct blob_attr **ubus_parse_msg(struct blob_attr *msg, size_t len); bool ubus_validate_hdr(struct ubus_msghdr *hdr); void ubus_handle_data(struct uloop_fd *u, unsigned int events); int ubus_send_msg(struct ubus_context *ctx, uint32_t seq, diff --git a/libubus-io.c b/libubus-io.c index 81c1cd1309b1..ba1016d0fa09 100644 --- a/libubus-io.c +++ b/libubus-io.c @@ -43,9 +43,9 @@ static const struct blob_attr_info ubus_policy[UBUS_ATTR_MAX] = { static struct blob_attr *attrbuf[UBUS_ATTR_MAX]; -__hidden struct blob_attr **ubus_parse_msg(struct blob_attr *msg) +__hidden struct blob_attr **ubus_parse_msg(struct blob_attr *msg, size_t len) { - blob_parse(msg, attrbuf, ubus_policy, UBUS_ATTR_MAX); + blob_parse_untrusted(msg, len, attrbuf, ubus_policy, UBUS_ATTR_MAX); return attrbuf; } diff --git a/libubus-obj.c b/libubus-obj.c index 2580b2442c4b..29cbb2b98e6e 100644 --- a/libubus-obj.c +++ b/libubus-obj.c @@ -121,7 +121,7 @@ void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_ struct ubus_object *obj; uint32_t objid; void *prev_data = NULL; - attrbuf = ubus_parse_msg(buf->data); + attrbuf = ubus_parse_msg(buf->data, blob_raw_len(buf->data)); if (!attrbuf[UBUS_ATTR_OBJID]) return; @@ -160,7 +160,7 @@ void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_ static void ubus_add_object_cb(struct ubus_request *req, int type, struct blob_attr *msg) { struct ubus_object *obj = req->priv; - struct blob_attr **attrbuf = ubus_parse_msg(msg); + struct blob_attr **attrbuf = ubus_parse_msg(msg, blob_raw_len(msg)); if (!attrbuf[UBUS_ATTR_OBJID]) return; @@ -240,7 +240,7 @@ int ubus_add_object(struct ubus_context *ctx, struct ubus_object *obj) static void ubus_remove_object_cb(struct ubus_request *req, int type, struct blob_attr *msg) { struct ubus_object *obj = req->priv; - struct blob_attr **attrbuf = ubus_parse_msg(msg); + struct blob_attr **attrbuf = ubus_parse_msg(msg, blob_raw_len(msg)); if (!attrbuf[UBUS_ATTR_OBJID]) return; diff --git a/libubus-req.c b/libubus-req.c index fd9a548839e4..ae9d1925ecdf 100644 --- a/libubus-req.c +++ b/libubus-req.c @@ -31,7 +31,7 @@ static void req_data_cb(struct ubus_request *req, int type, struct blob_attr *da if (!req->data_cb) return; - attr = ubus_parse_msg(data); + attr = ubus_parse_msg(data, blob_raw_len(data)); if (!attr[UBUS_ATTR_DATA]) return; @@ -328,7 +328,7 @@ int ubus_notify(struct ubus_context *ctx, struct ubus_object *obj, static bool ubus_get_status(struct ubus_msghdr_buf *buf, int *ret) { - struct blob_attr **attrbuf = ubus_parse_msg(buf->data); + struct blob_attr **attrbuf = ubus_parse_msg(buf->data, blob_raw_len(buf->data)); if (!attrbuf[UBUS_ATTR_STATUS]) return false; @@ -435,7 +435,7 @@ static void ubus_process_notify_status(struct ubus_request *req, int id, struct if (!id) { /* first id: ubusd's status message with a list of ids */ - tb = ubus_parse_msg(buf->data); + tb = ubus_parse_msg(buf->data, blob_raw_len(buf->data)); if (tb[UBUS_ATTR_SUBSCRIBERS]) { blob_for_each_attr(cur, tb[UBUS_ATTR_SUBSCRIBERS], rem) { if (!blob_check_type(blob_data(cur), blob_len(cur), BLOB_ATTR_INT32)) diff --git a/libubus.c b/libubus.c index b405891416c2..91f317c59867 100644 --- a/libubus.c +++ b/libubus.c @@ -139,7 +139,7 @@ static void ubus_lookup_cb(struct ubus_request *ureq, int type, struct blob_attr struct blob_attr **attr; req = container_of(ureq, struct ubus_lookup_request, req); - attr = ubus_parse_msg(msg); + attr = ubus_parse_msg(msg, blob_raw_len(msg)); if (!attr[UBUS_ATTR_OBJID] || !attr[UBUS_ATTR_OBJPATH] || !attr[UBUS_ATTR_OBJTYPE]) @@ -175,7 +175,7 @@ static void ubus_lookup_id_cb(struct ubus_request *req, int type, struct blob_at struct blob_attr **attr; uint32_t *id = req->priv; - attr = ubus_parse_msg(msg); + attr = ubus_parse_msg(msg, blob_raw_len(msg)); if (!attr[UBUS_ATTR_OBJID]) return; diff --git a/tests/fuzz/test-fuzz.c b/tests/fuzz/test-fuzz.c index 9922ff9de609..7a7a1ebe8b11 100644 --- a/tests/fuzz/test-fuzz.c +++ b/tests/fuzz/test-fuzz.c @@ -28,7 +28,7 @@ static void _ubus_parse_msg(const uint8_t *data, size_t size) if (blob_pad_len(attr) > UBUS_MAX_MSGLEN) return; - ubus_parse_msg(attr); + ubus_parse_msg(attr, size); } int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) diff --git a/ubusd.h b/ubusd.h index 867cde9a384b..923e43dd92da 100644 --- a/ubusd.h +++ b/ubusd.h @@ -72,7 +72,7 @@ struct ubus_msg_buf *ubus_msg_new(void *data, int len, bool shared); void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub); ssize_t ubus_msg_writev(int fd, struct ubus_msg_buf *ub, size_t offset); void ubus_msg_free(struct ubus_msg_buf *ub); -struct blob_attr **ubus_parse_msg(struct blob_attr *msg); +struct blob_attr **ubus_parse_msg(struct blob_attr *msg, size_t len); struct ubus_client *ubusd_proto_new_client(int fd, uloop_fd_handler cb); void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub); diff --git a/ubusd_acl.c b/ubusd_acl.c index f19df9a875c7..e426a4af95ef 100644 --- a/ubusd_acl.c +++ b/ubusd_acl.c @@ -549,7 +549,7 @@ static int ubusd_reply_query(struct ubus_client *cl, struct ubus_msg_buf *ub, st static int ubusd_acl_recv(struct ubus_client *cl, struct ubus_msg_buf *ub, const char *method, struct blob_attr *msg) { if (!strcmp(method, "query")) - return ubusd_reply_query(cl, ub, ubus_parse_msg(ub->data), msg); + return ubusd_reply_query(cl, ub, ubus_parse_msg(ub->data, blob_raw_len(ub->data)), msg); return UBUS_STATUS_INVALID_COMMAND; } diff --git a/ubusd_proto.c b/ubusd_proto.c index 4dd89ddb4939..4746605f4960 100644 --- a/ubusd_proto.c +++ b/ubusd_proto.c @@ -34,9 +34,9 @@ static const struct blob_attr_info ubus_policy[UBUS_ATTR_MAX] = { [UBUS_ATTR_GROUP] = { .type = BLOB_ATTR_STRING }, }; -struct blob_attr **ubus_parse_msg(struct blob_attr *msg) +struct blob_attr **ubus_parse_msg(struct blob_attr *msg, size_t len) { - blob_parse(msg, attrbuf, ubus_policy, UBUS_ATTR_MAX); + blob_parse_untrusted(msg, len, attrbuf, ubus_policy, UBUS_ATTR_MAX); return attrbuf; } @@ -454,7 +454,7 @@ void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub /* Note: no callback should free the `ub` buffer that's always done right after the callback finishes */ if (cb) - ret = cb(cl, ub, ubus_parse_msg(ub->data)); + ret = cb(cl, ub, ubus_parse_msg(ub->data, blob_raw_len(ub->data))); else ret = UBUS_STATUS_INVALID_COMMAND;