From patchwork Wed Nov 20 11:59:18 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: 1198071 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="HskMdTwD"; 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 47J1TW5p7wz9sR7 for ; Wed, 20 Nov 2019 22:59:59 +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=Ox4IziSo1DQfeT1sw5PQdth6dYTpdnbE7nXovzT/PWQ=; b=HskMdTwDrCzqqf fqmzKpgGhLMY7bJO+50TNlF3k+G2hGKydH15LM5Em4AAAFIE5Mwoj1YPO97Uf+88aG8xA0b+J9lnO e10tx+Q+TRGKskqHJ3Mqe2iPgiztYBIGZQQkqqQpygrlQARSduyOVq1OmciguqXs5wHe822BTndRf WEhf1S83eYOVaFqhso0OYdZb/9ELUaV76oL+PQe2NkJAhy30zBQ2MbYjWr/XMeeACtIv5ycnBSMZz 6LUVP92oYNylL5ZN5jtx8zDyLOg2pXwWsxOzLeGXG7o6qyph3rZ0mqHa+gDoJnsFSqYnGu9YvZisP ycTqwD8kuwkokoQl0zPQ==; 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 1iXOeH-0001lt-AW; Wed, 20 Nov 2019 11:59: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 1iXOe2-0001XQ-0r for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 11:59:41 +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 56A004668; Wed, 20 Nov 2019 12:59:30 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id ef88abd6; Wed, 20 Nov 2019 12:59:20 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 12:59:18 +0100 Message-Id: <20191120115926.23272-2-ynezz@true.cz> In-Reply-To: <20191120115926.23272-1-ynezz@true.cz> References: <20191120115926.23272-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191120_035938_233074_D7FE1E8D X-CRM114-Status: UNSURE ( 7.62 ) 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_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH libubox 1/9] 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57804cf007bf..7a86854841e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ INCLUDE(CheckLibraryExists) INCLUDE(CheckFunctionExists) PROJECT(ubox C) -ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations) +ADD_DEFINITIONS(-Os -Wextra -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations -Wno-unused-parameter) OPTION(BUILD_LUA "build Lua plugin" ON) OPTION(BUILD_EXAMPLES "build examples" ON) From patchwork Wed Nov 20 11:59: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: 1198073 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="p1z4vyMQ"; 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 47J1V55yxYz9sPc for ; Wed, 20 Nov 2019 23:00:29 +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=OADeK81AyE8HyhuySON5kjOMC/WXahfEJv6Ywa0t1OM=; b=p1z4vyMQunvsM7 Q4oeDqp6fpeEKNfe8xWEC97sbAYTZLd/qLt43S6soXrWF2jzniMT+VF1Cy3RGQbrXnzQq8yZkrvwt CB3775vxlCl8glyyKn/Q5cU7Mbq2pkfSUQRxaRX/InWzbuk4hV9D+Hl000wvKx0VFZyo4oycGjmEm NGI4AppZ8rMYaLG5IfctwmtQhBvTK7lvrqm5dE5FiT5TAUlIF+c7Aj8Vj6RDbmCXWQnPDDzlNdzIX fUGqY8Mc7HFyVWMf0aDV/bkBoYDnkCpWiDLNJcWj9aFcad+UMsO09NzlE08vysWWFhpcl1vp6Q2X6 9wqeR0Ds4PNCvTwEHRFQ==; 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 1iXOeq-0003jQ-02; Wed, 20 Nov 2019 12:00:28 +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 1iXOe2-0001XS-0t for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 11:59:41 +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 9B0CC4669; Wed, 20 Nov 2019 12:59:30 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 9b5bd459; Wed, 20 Nov 2019 12:59:20 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 12:59:19 +0100 Message-Id: <20191120115926.23272-3-ynezz@true.cz> In-Reply-To: <20191120115926.23272-1-ynezz@true.cz> References: <20191120115926.23272-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191120_035938_241322_3749BA3E X-CRM114-Status: GOOD ( 11.87 ) 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_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH libubox 2/9] 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 gcc-9 on x86/64 has reported following issues: base64.c:173:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] base64.c:230:18: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] base64.c:238:18: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] base64.c:242:22: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] base64.c:252:18: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] base64.c:256:22: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] base64.c:266:18: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] base64.c:315:27: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] base64.c:329:15: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] blob.c:207:11: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare] blob.c:210:11: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare] blob.c:243:31: error: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Werror=sign-compare] blob.c:246:31: error: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Werror=sign-compare] blob.h:245:37: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare] blob.h:253:37: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare] blobmsg.h:269:37: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare] blobmsg_json.c:155:10: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] examples/../blob.h:245:37: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare] examples/../blobmsg.h:269:37: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare] json_script.c:590:7: error: this statement may fall through [-Werror=implicit-fallthrough=] Signed-off-by: Petr Štetiar --- base64.c | 5 +++-- blob.c | 6 +++--- blob.h | 6 +++--- blobmsg.c | 2 +- blobmsg_json.c | 4 ++-- examples/blobmsg-example.c | 2 +- examples/json_script-example.c | 2 +- json_script.c | 17 ++++++++++------- 8 files changed, 24 insertions(+), 20 deletions(-) diff --git a/base64.c b/base64.c index 4186ce848c71..4759ede01e7c 100644 --- a/base64.c +++ b/base64.c @@ -142,7 +142,7 @@ int b64_encode(const void *_src, size_t srclength, size_t datalength = 0; u_char input[3] = {0}; u_char output[4]; - int i; + size_t i; while (2 < srclength) { input[0] = *src++; @@ -200,7 +200,8 @@ int b64_decode(const void *_src, void *dest, size_t targsize) { const char *src = _src; unsigned char *target = dest; - int tarindex, state, ch; + int state, ch; + size_t tarindex; u_char nextbyte; char *pos; diff --git a/blob.c b/blob.c index 03d5e9c27ee7..9b3d8abe330a 100644 --- a/blob.c +++ b/blob.c @@ -186,7 +186,7 @@ blob_nest_end(struct blob_buf *buf, void *cookie) buf->head = attr; } -static const int blob_type_minlen[BLOB_ATTR_LAST] = { +static const size_t blob_type_minlen[BLOB_ATTR_LAST] = { [BLOB_ATTR_STRING] = 1, [BLOB_ATTR_INT8] = sizeof(uint8_t), [BLOB_ATTR_INT16] = sizeof(uint16_t), @@ -222,12 +222,12 @@ blob_parse(struct blob_attr *attr, struct blob_attr **data, const struct blob_at { struct blob_attr *pos; int found = 0; - int rem; + size_t rem; memset(data, 0, sizeof(struct blob_attr *) * max); blob_for_each_attr(pos, attr, rem) { int id = blob_id(pos); - int len = blob_len(pos); + size_t len = blob_len(pos); if (id >= max) continue; diff --git a/blob.h b/blob.h index a092f5dabca6..d34652229b59 100644 --- a/blob.h +++ b/blob.h @@ -96,7 +96,7 @@ blob_is_extended(const struct blob_attr *attr) /* * blob_len: returns the length of the attribute's payload */ -static inline unsigned int +static inline size_t blob_len(const struct blob_attr *attr) { return (be32_to_cpu(attr->id_len) & BLOB_ATTR_LEN_MASK) - sizeof(struct blob_attr); @@ -105,7 +105,7 @@ blob_len(const struct blob_attr *attr) /* * blob_raw_len: returns the complete length of an attribute (including the header) */ -static inline unsigned int +static inline size_t blob_raw_len(const struct blob_attr *attr) { return blob_len(attr) + sizeof(struct blob_attr); @@ -114,7 +114,7 @@ blob_raw_len(const struct blob_attr *attr) /* * blob_pad_len: returns the padded length of an attribute (including the header) */ -static inline unsigned int +static inline size_t blob_pad_len(const struct blob_attr *attr) { unsigned int len = blob_raw_len(attr); diff --git a/blobmsg.c b/blobmsg.c index 8019c45b83ed..a860483bfa7e 100644 --- a/blobmsg.c +++ b/blobmsg.c @@ -67,7 +67,7 @@ int blobmsg_check_array(const struct blob_attr *attr, int type) { struct blob_attr *cur; bool name; - int rem; + size_t rem; int size = 0; switch (blobmsg_type(attr)) { diff --git a/blobmsg_json.c b/blobmsg_json.c index 59a4b3183d8c..a5980e8a2b62 100644 --- a/blobmsg_json.c +++ b/blobmsg_json.c @@ -146,7 +146,7 @@ static bool blobmsg_puts(struct strbuf *s, const char *c, int len) static void add_separator(struct strbuf *s) { const char *indent_chars = "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; - int len; + size_t len; if (!s->indent) return; @@ -279,7 +279,7 @@ static void blobmsg_format_json_list(struct strbuf *s, struct blob_attr *attr, i { struct blob_attr *pos; bool first = true; - int rem = len; + size_t rem = len; blobmsg_puts(s, (array ? "[" : "{" ), 1); s->indent_level++; diff --git a/examples/blobmsg-example.c b/examples/blobmsg-example.c index 1c8601735fd0..56cac2718123 100644 --- a/examples/blobmsg-example.c +++ b/examples/blobmsg-example.c @@ -15,7 +15,7 @@ static const char *indent_str = "\t\t\t\t\t\t\t\t\t\t\t\t\t"; static void dump_attr_data(struct blob_attr *data, int indent, int next_indent); static void -dump_table(struct blob_attr *head, int len, int indent, bool array) +dump_table(struct blob_attr *head, size_t len, int indent, bool array) { struct blob_attr *attr; struct blobmsg_hdr *hdr; diff --git a/examples/json_script-example.c b/examples/json_script-example.c index 4d252a9a6bd2..6d93059a412e 100644 --- a/examples/json_script-example.c +++ b/examples/json_script-example.c @@ -14,7 +14,7 @@ static void handle_command(struct json_script_ctx *ctx, const char *name, struct blob_attr *data, struct blob_attr *vars) { struct blob_attr *cur; - int rem; + size_t rem; fprintf(stdout, "%s", name); blobmsg_for_each_attr(cur, data, rem) diff --git a/json_script.c b/json_script.c index 87b1d71b1837..3b10b1015400 100644 --- a/json_script.c +++ b/json_script.c @@ -95,7 +95,7 @@ const char *json_script_find_var(struct json_script_ctx *ctx, struct blob_attr * const char *name) { struct blob_attr *cur; - int rem; + size_t rem; blobmsg_for_each_attr(cur, vars, rem) { if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING) @@ -164,7 +164,7 @@ static int handle_case(struct json_call *call, struct blob_attr *expr) { struct blob_attr *tb[3], *cur; const char *var; - int rem; + size_t rem; json_get_tuple(expr, tb, BLOBMSG_TYPE_STRING, BLOBMSG_TYPE_TABLE); if (!tb[1] || !tb[2]) @@ -233,7 +233,7 @@ static int expr_eq_regex(struct json_call *call, struct blob_attr *expr, bool re struct json_script_ctx *ctx = call->ctx; struct blob_attr *tb[3], *cur; const char *var; - int rem; + size_t rem; json_get_tuple(expr, tb, BLOBMSG_TYPE_STRING, 0); if (!tb[1] || !tb[2]) @@ -277,7 +277,7 @@ static int handle_expr_has(struct json_call *call, struct blob_attr *expr) { struct json_script_ctx *ctx = call->ctx; struct blob_attr *tb[3], *cur; - int rem; + size_t rem; json_get_tuple(expr, tb, 0, 0); if (!tb[1]) @@ -306,7 +306,8 @@ static int handle_expr_has(struct json_call *call, struct blob_attr *expr) static int expr_and_or(struct json_call *call, struct blob_attr *expr, bool and) { struct blob_attr *cur; - int ret, rem; + int ret; + size_t rem; int i = 0; blobmsg_for_each_attr(cur, expr, rem) { @@ -515,7 +516,8 @@ static int cmd_process_strings(struct json_call *call, struct blob_attr *attr) struct json_script_ctx *ctx = call->ctx; struct blob_attr *cur; int args = -1; - int rem, ret; + int ret; + size_t rem; void *c; blob_buf_init(&ctx->buf, 0); @@ -572,7 +574,7 @@ static int json_process_cmd(struct json_call *call, struct blob_attr *block) { struct json_script_ctx *ctx = call->ctx; struct blob_attr *cur; - int rem; + size_t rem; int ret; int i = 0; @@ -589,6 +591,7 @@ static int json_process_cmd(struct json_call *call, struct blob_attr *block) case BLOBMSG_TYPE_STRING: if (!i) return __json_process_cmd(call, block); + /* fall through */ default: ret = json_process_cmd(call, cur); if (ret < -1) From patchwork Wed Nov 20 11:59: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: 1198072 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="nj6hvIqL"; 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 47J1Tj3rcVz9sR4 for ; Wed, 20 Nov 2019 23:00:08 +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=U0Ms2dAFC1jcZdBk7TS9jD5QLqvbGinqx4oLZp/2k2Y=; b=nj6hvIqLMvQ9vz sU1wB3C6iTQITIVjTD52AKoixs/mcaJH+WMAbHdLwbZbZxjsAsWTzsV/yqZU9tJ30364Nm33pczwR cweKL9blCFbgykWEupslaMUfVn/qAnRfDOa7s0B8ZyEbEdEr3YezESD07cXQ0v5DbXj8XQKupGgBV 2ikDlYhPfcz6bZ2bkIX8qxo/iHxz/RMKCqWg/pqt6FJMRQFcS2TBx23H36Ma1MGm7imKU5vPukH2Q mWSWdSehSdrPRvBQLSDef4VEIUtvm8b6hD1ux7RwUTqSaovYH39RP90v7/GuZeVWYSchW46B0/PAO RHRerQYc3KXR8gDaEcRQ==; 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 1iXOeT-00022y-2s; Wed, 20 Nov 2019 12:00:05 +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 1iXOe2-0001XT-0m for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 11:59:41 +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 DC007466B; Wed, 20 Nov 2019 12:59:30 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 0b67843b; Wed, 20 Nov 2019 12:59:21 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 12:59:20 +0100 Message-Id: <20191120115926.23272-4-ynezz@true.cz> In-Reply-To: <20191120115926.23272-1-ynezz@true.cz> References: <20191120115926.23272-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191120_035938_228835_9633AB36 X-CRM114-Status: UNSURE ( 7.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_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH libubox 3/9] 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 10 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..e1ed5706e27d --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,7 @@ +variables: + CI_TARGET_BUILD_DEPENDS: libubox + 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 Wed Nov 20 11:59: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: 1198074 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="cSpEuJV0"; 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 47J1V73Fpyz9sR5 for ; Wed, 20 Nov 2019 23:00: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=V7Ph9CZJnoU1xE2X/ClCiHWleiPwPCLOSGlRts7VKbY=; b=cSpEuJV0cCLEtA cPj/c8BwnYZNvQYyukqchIMuFa2WunYvzyZ2VaIClPxhLcQ69v+X0kWe8mWCL0b6WbVfrkMCTnRGl JcrQ9Hljelo2wtKj074dOQuKlRgIF5JxD7a8VWk9YqlPWYmLhBHDaaF7FTjx0xBZ9RiVDu4gO2LB9 r9YlGrEPF/BUv6M3GQF3qqUZKpiVrDqVm15EKV6Hji63cyZGGItdiJWgSXrY846Gv4Xf0+Jsz3ZCv +q8MrkUd45uNc2DcPI96QwaHyt9DyXCOU/vewFGu74aKwu0e9XSPrY266SboFQ2ukoIjJ+1EOGpRv 1NcQy/BtPv9cH2fqWiSQ==; 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 1iXOeg-0002oa-4w; Wed, 20 Nov 2019 12:00: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 1iXOe2-0001XV-0s for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 11:59:41 +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 1A38D466C; Wed, 20 Nov 2019 12:59:32 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 09d12449; Wed, 20 Nov 2019 12:59:21 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 12:59:21 +0100 Message-Id: <20191120115926.23272-5-ynezz@true.cz> In-Reply-To: <20191120115926.23272-1-ynezz@true.cz> References: <20191120115926.23272-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191120_035938_365966_CE8694FD X-CRM114-Status: GOOD ( 11.96 ) 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_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH libubox 4/9] add cram based unit tests 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 For improved QA etc. for the start with initial test cases for avl, base64 and jshn. Signed-off-by: Petr Štetiar --- CMakeLists.txt | 5 +++ tests/CMakeLists.txt | 10 +++++ tests/cram/CMakeLists.txt | 27 ++++++++++++ tests/cram/test_avl.t | 10 +++++ tests/cram/test_base64.t | 17 ++++++++ tests/cram/test_jshn.t | 25 +++++++++++ tests/test-avl.c | 87 +++++++++++++++++++++++++++++++++++++++ tests/test-base64.c | 39 ++++++++++++++++++ 8 files changed, 220 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/cram/CMakeLists.txt create mode 100644 tests/cram/test_avl.t create mode 100644 tests/cram/test_base64.t create mode 100644 tests/cram/test_jshn.t create mode 100644 tests/test-avl.c create mode 100644 tests/test-base64.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a86854841e3..b80d551c112f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,11 @@ INSTALL(TARGETS ubox ubox-static ADD_SUBDIRECTORY(lua) ADD_SUBDIRECTORY(examples) +IF(UNIT_TESTING) + ENABLE_TESTING() + ADD_SUBDIRECTORY(tests) +ENDIF() + find_library(json NAMES json-c) IF(EXISTS ${json}) ADD_LIBRARY(blobmsg_json SHARED blobmsg_json.c) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000000..602c5904d2e5 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,10 @@ +ADD_SUBDIRECTORY(cram) + +MACRO(ADD_UNIT_TEST name) + ADD_EXECUTABLE(test-${name} test-${name}.c) + TARGET_LINK_LIBRARIES(test-${name} ubox) + TARGET_INCLUDE_DIRECTORIES(test-${name} PRIVATE ${PROJECT_SOURCE_DIR}) +ENDMACRO(ADD_UNIT_TEST) + +ADD_UNIT_TEST(avl) +ADD_UNIT_TEST(base64) diff --git a/tests/cram/CMakeLists.txt b/tests/cram/CMakeLists.txt new file mode 100644 index 000000000000..b84548ae0b0b --- /dev/null +++ b/tests/cram/CMakeLists.txt @@ -0,0 +1,27 @@ +FIND_PACKAGE(PythonInterp 3 REQUIRED) +FILE(GLOB test_cases "test_*.t") + +SET(PYTHON_VENV_DIR "${CMAKE_CURRENT_BINARY_DIR}/.venv") +SET(PYTHON_VENV_PIP "${PYTHON_VENV_DIR}/bin/pip") +SET(PYTHON_VENV_CRAM "${PYTHON_VENV_DIR}/bin/cram") + +ADD_CUSTOM_COMMAND( + OUTPUT ${PYTHON_VENV_CRAM} + COMMAND ${PYTHON_EXECUTABLE} -m venv ${PYTHON_VENV_DIR} + COMMAND ${PYTHON_VENV_PIP} install cram +) +ADD_CUSTOM_TARGET(prepare-cram-venv ALL DEPENDS ${PYTHON_VENV_CRAM}) + +ADD_TEST( + NAME cram + COMMAND ${PYTHON_VENV_CRAM} ${test_cases} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +MACRO(ADD_CRAM_TEST_ENV env file) + SET_PROPERTY(TEST cram APPEND PROPERTY ENVIRONMENT "${env}=$") +ENDMACRO(ADD_CRAM_TEST_ENV) + +ADD_CRAM_TEST_ENV(JSHN jshn) +ADD_CRAM_TEST_ENV(TEST_AVL test-avl) +ADD_CRAM_TEST_ENV(TEST_BASE64 test-base64) diff --git a/tests/cram/test_avl.t b/tests/cram/test_avl.t new file mode 100644 index 000000000000..661779b9b190 --- /dev/null +++ b/tests/cram/test_avl.t @@ -0,0 +1,10 @@ +check that avl is producing expected results: + + $ valgrind --quiet --leak-check=full $TEST_AVL + test_basics: insert: 0=zero 0=one 0=two 0=three 0=four 0=five 0=six 0=seven 0=eight 0=nine 0=ten 0=eleven 0=twelve + test_basics: insert duplicate: -1=zero -1=one -1=two -1=three -1=four -1=five -1=six -1=seven -1=eight -1=nine -1=ten -1=eleven -1=twelve + test_basics: first=eight last=zero + test_basics: for each element: eight eleven five four nine one seven six ten three twelve two zero + test_basics: delete 'one' element + test_basics: for each element reverse: zero two twelve three ten six seven nine four five eleven eight + test_basics: delete all elements diff --git a/tests/cram/test_base64.t b/tests/cram/test_base64.t new file mode 100644 index 000000000000..ee19dc1f9218 --- /dev/null +++ b/tests/cram/test_base64.t @@ -0,0 +1,17 @@ +check that base64 is producing expected results: + + $ valgrind --quiet --leak-check=full $TEST_BASE64 + 0 + 4 Zg== + 4 Zm8= + 4 Zm9v + 8 Zm9vYg== + 8 Zm9vYmE= + 8 Zm9vYmFy + 0 + 1 f + 2 fo + 3 foo + 4 foob + 5 fooba + 6 foobar diff --git a/tests/cram/test_jshn.t b/tests/cram/test_jshn.t new file mode 100644 index 000000000000..d228f0e648c6 --- /dev/null +++ b/tests/cram/test_jshn.t @@ -0,0 +1,25 @@ +set jshn for convenience: + + $ [ -n "$JSHN" ] && export PATH="$(dirname "$JSHN"):$PATH" + $ alias jshn="valgrind --quiet --leak-check=full jshn" + +check usage: + + $ jshn + Usage: jshn [-n] [-i] -r |-R |-w + [2] + +test bad json: + + $ jshn -r '[]' + Failed to parse message data + [1] + +test good json: + + $ jshn -r '{"foo": "bar", "baz": {"next": "meep"}}' + json_init; + json_add_string 'foo' 'bar'; + json_add_object 'baz'; + json_add_string 'next' 'meep'; + json_close_object; diff --git a/tests/test-avl.c b/tests/test-avl.c new file mode 100644 index 000000000000..18ee9b7697c5 --- /dev/null +++ b/tests/test-avl.c @@ -0,0 +1,87 @@ +#include +#include +#include + +#include "avl.h" +#include "avl-cmp.h" +#include "utils.h" + +#define OUT(fmt, ...) do { \ + fprintf(stdout, "%s: " fmt, __func__, ## __VA_ARGS__); \ +} while (0); + +struct node { + struct avl_node avl; +}; + +static void test_basics() +{ + size_t i; + struct avl_tree t; + struct node *temp; + struct node *elem; + struct node *last; + struct node *first; + const char *vals[] = { + "zero", "one", "two", "three", "four", "five", "six", + "seven", "eight", "nine", "ten", "eleven", "twelve" + }; + + avl_init(&t, avl_strcmp, false, NULL); + + OUT("insert: "); + for (i=0; iavl.key = vals[i]; + + int r = avl_insert(&t, &n->avl); + fprintf(stdout, "%d=%s ", r, (char *)n->avl.key); + } + fprintf(stdout, "\n"); + + OUT("insert duplicate: "); + for (i=0; iavl.key = vals[i]; + + int r = avl_insert(&t, &n->avl); + fprintf(stdout, "%d=%s ", r, (char *)n->avl.key); + + if (r) + free(n); + } + fprintf(stdout, "\n"); + + first = avl_first_element(&t, first, avl); + last = avl_last_element(&t, last, avl); + OUT("first=%s last=%s\n", (char*)first->avl.key, (char*)last->avl.key); + + OUT("for each element: "); + avl_for_each_element(&t, elem, avl) { + fprintf(stdout, "%s ", (char*)elem->avl.key); + } + fprintf(stdout, "\n"); + + OUT("delete 'one' element\n"); + elem = avl_find_element(&t, "one", elem, avl); + avl_delete(&t, &elem->avl); + free(elem); + + OUT("for each element reverse: "); + avl_for_each_element_reverse(&t, elem, avl) { + fprintf(stdout, "%s ", (char*)elem->avl.key); + } + fprintf(stdout, "\n"); + + OUT("delete all elements\n"); + avl_for_each_element_safe(&t, elem, avl, temp) { + avl_delete(&t, &elem->avl); + free(elem); + } +} + +int main() +{ + test_basics(); + return 0; +} diff --git a/tests/test-base64.c b/tests/test-base64.c new file mode 100644 index 000000000000..c29b4e2c73a3 --- /dev/null +++ b/tests/test-base64.c @@ -0,0 +1,39 @@ +#include +#include + +#include "utils.h" + +static void test_b64_encode(const char *src) +{ + char dst[255] = {0}; + int r = b64_encode(src, strlen(src), dst, sizeof(dst)); + fprintf(stdout, "%d %s\n", r, dst); +} + +static void test_b64_decode(const char *src) +{ + char dst[255] = {0}; + int r = b64_decode(src, dst, sizeof(dst)); + fprintf(stdout, "%d %s\n", r, dst); +} + +int main() +{ + test_b64_encode(""); + test_b64_encode("f"); + test_b64_encode("fo"); + test_b64_encode("foo"); + test_b64_encode("foob"); + test_b64_encode("fooba"); + test_b64_encode("foobar"); + + test_b64_decode(""); + test_b64_decode("Zg=="); + test_b64_decode("Zm8="); + test_b64_decode("Zm9v"); + test_b64_decode("Zm9vYg=="); + test_b64_decode("Zm9vYmE="); + test_b64_decode("Zm9vYmFy"); + + return 0; +} From patchwork Wed Nov 20 11:59: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: 1198075 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="WDAjj/Qt"; 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 47J1VR3ghpz9sR7 for ; Wed, 20 Nov 2019 23:00:45 +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=3YAY1ZsM3m7tdkuAeIyTWcpNF/e0gL8jVOZFEHzpjcU=; b=WDAjj/QtvRObt9 jdMEEEIx3Wxa5Jv3fduwdvtiMpyxW+uOX5AV0MN+lzOaeKJiMD/d41BRFcHAvVMhY44NJcS/5wXwg rk8HHP2N+t1LT03fIzKHaRidS/w6EyB3CY0ASM1j3dQ5ceHSzGUk+7Y5j4eXrxl/K9S0UAm+QyNH5 aXRIPALKhoJMMoNgr4NTFM+txlVwVjXqW5kkL6izfyjuwvO/4UQGpXt3cpvVhA0paidJeww0pdALc ofm1rMB56+xhL7cSRVlyIYqK1/KVYE9acPIGvukSVWsUso97zVvy/wUe8kLzBU6ZFAcKSJkJPvhhL HRg6elUitAxa+GJULfCA==; 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 1iXOez-0003zJ-Ju; Wed, 20 Nov 2019 12:00:37 +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 1iXOe5-0001Zc-2r for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 11:59:42 +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 45DAA466D; Wed, 20 Nov 2019 12:59:32 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id c91570d9; Wed, 20 Nov 2019 12:59:22 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 12:59:22 +0100 Message-Id: <20191120115926.23272-6-ynezz@true.cz> In-Reply-To: <20191120115926.23272-1-ynezz@true.cz> References: <20191120115926.23272-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191120_035941_302725_D156B436 X-CRM114-Status: UNSURE ( 7.57 ) 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_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH libubox 5/9] base64: b64_decode: 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 clang-10 analyzer reports following: base64.c:325:20: warning: Array access (from variable 'target') results in a null pointer dereference target[tarindex] = 0; ~~~~~~ ^ and prepared test case confirms it: Invalid write of size 1 at 0x4E4463F: b64_decode (base64.c:325) by 0x40088C: test_invalid_inputs (tests/test-base64.c:26) by 0x40088C: main (tests/test-base64.c:32) Address 0x1 is not stack'd, malloc'd or (recently) free'd Process terminating with default action of signal 11 (SIGSEGV) Access not within mapped region at address 0x1 at 0x4E4463F: b64_decode (base64.c:325) by 0x40088C: test_invalid_inputs (tests/test-base64.c:26) by 0x40088C: main (tests/test-base64.c:32) Signed-off-by: Petr Štetiar --- base64.c | 6 ++++++ tests/test-base64.c | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/base64.c b/base64.c index 4759ede01e7c..d9f4112179f3 100644 --- a/base64.c +++ b/base64.c @@ -144,6 +144,9 @@ int b64_encode(const void *_src, size_t srclength, u_char output[4]; size_t i; + if (!dest || targsize == 0) + return -1; + while (2 < srclength) { input[0] = *src++; input[1] = *src++; @@ -208,6 +211,9 @@ int b64_decode(const void *_src, void *dest, size_t targsize) state = 0; tarindex = 0; + if (!dest || targsize == 0) + return -1; + while ((ch = (unsigned char)*src++) != '\0') { if (isspace(ch)) /* Skip whitespace anywhere. */ continue; diff --git a/tests/test-base64.c b/tests/test-base64.c index c29b4e2c73a3..415fc5969c53 100644 --- a/tests/test-base64.c +++ b/tests/test-base64.c @@ -17,8 +17,23 @@ static void test_b64_decode(const char *src) fprintf(stdout, "%d %s\n", r, dst); } +static void test_invalid_inputs() +{ + b64_decode(NULL, NULL, 0); + b64_decode("Zg==", NULL, 0); + b64_decode("Zg==", NULL, 2); + + b64_encode(NULL, 0, NULL, 2); + b64_encode(NULL, 2, NULL, 2); + b64_encode("foo", 3, NULL, 2); + b64_encode("foo", 3, NULL, 0); +} + int main() { + + test_invalid_inputs(); + test_b64_encode(""); test_b64_encode("f"); test_b64_encode("fo"); From patchwork Wed Nov 20 11:59: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: 1198076 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="sNFUE9k9"; 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 47J1Vb02hhz9sPZ for ; Wed, 20 Nov 2019 23:00: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=iGnRyZcFoi5eVmXXWAecGCDC/WdCt0GwfZy8FZRg8Xo=; b=sNFUE9k9rx6JDr RXMxKBRD/J5JUXoy+Q95VqudMuT6qGDA5Z8FJtVmojpMGvm1v81LPh7ieys6pXaGDekke7GuoJ3P2 NOn2KiZXYXmFsdc8FD1yQ0l7GP2lN/Uiw01OxzeBGniSzlzBEYigurXDv6QWQ1lxH15745R3SGxkj s6w7psVwfOMK4F2e0kg/otpfPNS/oCwALTX/9lRU8Tz+woiazr8THWKi//ZxQTq+awGZsceVruJF4 P23bE0I+ZEA9GwbBptjHr/1lLTAx5V200Ps+ZuLNV0clEafaXlTBwAY4bWXBQiv/AofTkJLrjjtEK XpGJWZvBhmgtjnLSTvXQ==; 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 1iXOfC-0004Fc-A3; Wed, 20 Nov 2019 12:00:50 +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 1iXOe5-0001Zb-BT for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 11:59:43 +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 71AD54670; Wed, 20 Nov 2019 12:59:32 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 73f18cbf; Wed, 20 Nov 2019 12:59:22 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 12:59:23 +0100 Message-Id: <20191120115926.23272-7-ynezz@true.cz> In-Reply-To: <20191120115926.23272-1-ynezz@true.cz> References: <20191120115926.23272-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191120_035941_560517_CAD9FBD8 X-CRM114-Status: UNSURE ( 7.33 ) 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_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH libubox 6/9] jshn: main: fix leak of memory pointed to by 'vars' 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 leak of memory: 6,016 bytes in 1 blocks are possibly lost in loss record 1 of 1 at 0x4C31B25: calloc by 0x1098F8: main (jshn.c:353) Signed-off-by: Petr Štetiar --- jshn.c | 1 + 1 file changed, 1 insertion(+) diff --git a/jshn.c b/jshn.c index 0aa120c925dd..02b35286ea8b 100644 --- a/jshn.c +++ b/jshn.c @@ -366,6 +366,7 @@ int main(int argc, char **argv) vars[i].val = c + 1; avl_insert(&env_vars, &vars[i].avl); } + free(vars); while ((ch = getopt(argc, argv, "p:nir:R:o:w")) != -1) { switch(ch) { From patchwork Wed Nov 20 11:59: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: 1198079 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="hDOD22Ld"; 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 47J1WL0G4Xz9sPZ for ; Wed, 20 Nov 2019 23:01:34 +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=cBjYUiR1ZJIBxWvq7xY3uqadTeNpwmghvoVxYqhOGgw=; b=hDOD22LduDTh4X axMNpZpN/ijK022YTYeacurq2Bn7Ui/wtoxnpqvX3CEee7HbCNIon4UZY/Xw1S6DthSl9Bztlp9GT 8DAPADX9djcI06sAwT1PBBpHWbFWI8V8GOGOoot+jRgOIjHHwcMXKpb28JUy/TRv/ybjEE8MloiOD cg3rLUF+rt/NkcbHrPjIkmzaVwrWVG4EgFuSLFFf0NwpE+0AaRflkBxcfXJCAas0loMHxStThS9oI DDcgU+s/mHqXuZRcpT9XwhYVmK82+dXHzsBc+X3rLr218qXsmWGAIN9zQI77iEZHMPatTyE/wdTeZ 5SW8jGooeYxjVQrH5jZQ==; 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 1iXOfq-00054E-6X; Wed, 20 Nov 2019 12:01:30 +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 1iXOe6-0001a1-Ez for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 11:59: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 C526E4671; Wed, 20 Nov 2019 12:59:32 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id e15fef76; Wed, 20 Nov 2019 12:59:22 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 12:59:24 +0100 Message-Id: <20191120115926.23272-8-ynezz@true.cz> In-Reply-To: <20191120115926.23272-1-ynezz@true.cz> References: <20191120115926.23272-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191120_035942_705400_1C27CD9D X-CRM114-Status: UNSURE ( 7.70 ) 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_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH libubox 7/9] jshn: jshn_parse: fix leaks of memory pointed to by 'obj' 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 leaks of memory: 352 (72 direct, 280 indirect) bytes in 1 blocks are definitely lost in loss record 3 of 3 at 0x4C31B25: calloc by 0x5042E1F: json_object_new_array by 0x5044B02: json_tokener_parse_ex by 0x5045316: json_tokener_parse_verbose by 0x504537D: json_tokener_parse by 0x401AA9: jshn_parse (jshn.c:179) by 0x401977: main (jshn.c:378) 752 (72 direct, 680 indirect) bytes in 1 blocks are definitely lost in loss record 6 of 6 at 0x4C31B25: calloc by 0x50424CF: json_object_new_object by 0x5044B38: json_tokener_parse_ex by 0x5045316: json_tokener_parse_verbose by 0x504537D: json_tokener_parse by 0x401AA9: jshn_parse (jshn.c:179) by 0x401977: main (jshn.c:380) Signed-off-by: Petr Štetiar --- jshn.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jshn.c b/jshn.c index 02b35286ea8b..5298d52e729a 100644 --- a/jshn.c +++ b/jshn.c @@ -178,12 +178,15 @@ static int jshn_parse(const char *str) obj = json_tokener_parse(str); if (!obj || json_object_get_type(obj) != json_type_object) { + if (obj) + json_object_put(obj); fprintf(stderr, "Failed to parse message data\n"); return 1; } fprintf(stdout, "json_init;\n"); add_json_object(obj); fflush(stdout); + json_object_put(obj); return 0; } From patchwork Wed Nov 20 11:59: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: 1198077 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="AOxyUW6b"; 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 47J1Vt4vnSz9sPj for ; Wed, 20 Nov 2019 23:01:10 +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=7X3zGc6MZ1lVFEfOe457etDb0kNsEhNE5Gp7WHOOT74=; b=AOxyUW6bThKM9N dRkQENGfkfEI1+5SK2O1bA7Ziw+f4BVWXmw5+9L3yo4FbwEJ1h+nnzRbvYZPuvM2gKJ8kdJQNHCop jEtTYvuO27SPI0Gc/y5eKKAupUWhZRNZa2cLNVHf1FhyPeDzkV7zMEkRWMGs3Z+XgXlmRpzQqAsHx 0IcLKGlawk+6+SdsjhVAuJpSDqpDGuzraQ4NH7fFgfwB1kQtPVtno0iDbAO5cjdUDbMFyuTTRon2b TI4nVpSLT2Sb6wAOhV3Xorf2bYYAAjDmT8x0rPSmSzdDy4hwGZVEClZAYS4PK0GmCJ9CI6aZmA+fk u4hxUyoI94bapyggQRvg==; 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 1iXOfQ-0004Xt-6D; Wed, 20 Nov 2019 12:01:04 +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 1iXOe6-0001a0-Fc for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 11:59: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 EDB414674; Wed, 20 Nov 2019 12:59:32 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 4ba09a2c; Wed, 20 Nov 2019 12:59:23 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 12:59:25 +0100 Message-Id: <20191120115926.23272-9-ynezz@true.cz> In-Reply-To: <20191120115926.23272-1-ynezz@true.cz> References: <20191120115926.23272-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191120_035942_703339_2913201C X-CRM114-Status: UNSURE ( 7.53 ) 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_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH libubox 8/9] blobmsg_json: fix possible uninitialized struct member 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-10 analyzer reports following: blobmsg_json.c:285:2: warning: The expression is an uninitialized value. The computed value will also be garbage s->indent_level++; ^~~~~~~~~~~~~~~~~ Signed-off-by: Petr Štetiar --- blobmsg_json.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blobmsg_json.c b/blobmsg_json.c index a5980e8a2b62..18592111b4dd 100644 --- a/blobmsg_json.c +++ b/blobmsg_json.c @@ -315,7 +315,7 @@ static void setup_strbuf(struct strbuf *s, struct blob_attr *attr, blobmsg_json_ char *blobmsg_format_json_with_cb(struct blob_attr *attr, bool list, blobmsg_json_format_t cb, void *priv, int indent) { - struct strbuf s; + struct strbuf s = {0}; bool array; char *ret; @@ -349,7 +349,7 @@ char *blobmsg_format_json_with_cb(struct blob_attr *attr, bool list, blobmsg_jso char *blobmsg_format_json_value_with_cb(struct blob_attr *attr, blobmsg_json_format_t cb, void *priv, int indent) { - struct strbuf s; + struct strbuf s = {0}; char *ret; setup_strbuf(&s, attr, cb, priv, indent); From patchwork Wed Nov 20 11:59:26 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: 1198078 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="nQvUb3uH"; 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 47J1W86wKXz9s4Y for ; Wed, 20 Nov 2019 23:01:24 +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=2UKKaan/jT+1vnI3IYqeVGxUMSIcKgX+AE/1aorgE2E=; b=nQvUb3uHsDEMLN J+DnpZxB83bCfVmTm9nS3wXUOW/iw2yxQvoADJFjlc8gfdCfugTcMqsmAL9+k3bnwKE8ob8+oOZt3 Klt8Lo/hWMf8JzGAeOxoxtCzT+R9LOvzLk5sTkmv2d52v4lj9gdWShcRRigd3z+Z5Wyntm3TtEn0P 2+IJhjFpbDxbEMvsIlxYLd6IytYCV3P/1cKsA1ImP2aGwz5WEY6V9XnnGlWweEcLBu/QGm14MWrLC iAUuhe/5P3J7wt1/K6Gl9qaqoXEXIJ86yHFFd4WGIPlcGA+FRA/nUOvoAJxcmUkFSQLCHV8Nvd6DQ DTg0MNj+0/ma9cQHT5Ag==; 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 1iXOfe-0004oW-1Z; Wed, 20 Nov 2019 12:01: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 1iXOe6-0001aG-Jx for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 11:59: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 26EFD4675; Wed, 20 Nov 2019 12:59:33 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 801c8905; Wed, 20 Nov 2019 12:59:23 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 12:59:26 +0100 Message-Id: <20191120115926.23272-10-ynezz@true.cz> In-Reply-To: <20191120115926.23272-1-ynezz@true.cz> References: <20191120115926.23272-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191120_035942_812313_E832675C X-CRM114-Status: UNSURE ( 8.88 ) 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_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH libubox 9/9] avl: guard against theoretical 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 clang-10 analyzer reports following: avl.c:671:25: warning: Access to field 'parent' results in a dereference of a null pointer (loaded from field 'right') node->right->parent = parent; ~~~~~ ^ Which seems to be impossible to trigger via exported AVL public API, but it could be probably trigerred by fiddling with the AVL tree node struct members manually as they are exposed. Signed-off-by: Petr Štetiar --- avl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/avl.c b/avl.c index 8d0bf65aaa5b..e5584051ab94 100644 --- a/avl.c +++ b/avl.c @@ -668,7 +668,8 @@ avl_delete_worker(struct avl_tree *tree, struct avl_node *node) return; } - node->right->parent = parent; + if (node->right) + node->right->parent = parent; if (parent->left == node) parent->left = node->right;