From patchwork Wed Nov 20 21:43:44 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: 1198551 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="lhvCar8Q"; 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 47JGSd03Yzz9sPJ for ; Thu, 21 Nov 2019 08:45: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=OADeK81AyE8HyhuySON5kjOMC/WXahfEJv6Ywa0t1OM=; b=lhvCar8QbeFK7A JpCaX72laBpAfFsQfPvQ2gpO492bM5jbsC60mErmVoMJOmKQt0wLt1BNZwVJ8q6d5Oey6o72Ko8/3 9cSLC1s5ZO34nlrbCgRPDP+AXfQ69YbP9xpDx6gpbLu/inQiSGkyKEAqNcx20OjQ2n7anUll9SshB KeSRgIKbO6dhKJzG+iqHxzSiK8h+ZjJ5SHraul2wnnmJFUYtCx6hSx0w1OgSx1M6W8+KT2+64Iq2M 6YvygpqY/1G3PQPCrzUfLs+8WnWeeg2jiUVe7gaucgZ51w15ukBmqw09ki243z/gYiSB19PTTs5/O zvwFnleUVA8q0YQTXQDQ==; 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 1iXXmZ-0006mi-8N; Wed, 20 Nov 2019 21:45:03 +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 1iXXla-0005nM-Bj for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 21:44:05 +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 C8DD04AD5; Wed, 20 Nov 2019 22:43:59 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id df55384d; Wed, 20 Nov 2019 22:43:50 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 22:43:44 +0100 Message-Id: <20191120214353.27652-2-ynezz@true.cz> In-Reply-To: <20191120214353.27652-1-ynezz@true.cz> References: <20191120214353.27652-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_134402_559698_2A1AAE77 X-CRM114-Status: GOOD ( 12.08 ) 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 v2 libubox 01/10] 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 21:43:45 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: 1198548 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="CsLc8S67"; 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 47JGRp34YBz9sPJ for ; Thu, 21 Nov 2019 08:44: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=Ox4IziSo1DQfeT1sw5PQdth6dYTpdnbE7nXovzT/PWQ=; b=CsLc8S67RbHMOe 86JsSuwA0Ug4XaztJgq0Z5u1BTtlb9biyCB7g9a59aRE+KsxRRfIzAn3WpSIwZlQ9aA2ZbKxsWEHW SDa3W/h7Gid2EZZPZHxyROhrxlZSnbTNnvo240fMNKM2YpLY9GgZcusLQ++/LKst/0oUstFNi6xqS M2LT5UMJbkenvVHHPSxqQ0tBqKEuUZVarcw9NWuElQck78482xXeSD6b4hX3YMtPmK5Ll3w1wPKTC HPy4FWLUIm7wezV6q/wQwEr1j9HDG1QlVgKIH4sPfbNj5Rlo5YDOyr7uLWcUKV7LKbd8aHa9AyZSP 0EiStR+P57fcVGTCATKQ==; 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 1iXXlp-00061n-2e; Wed, 20 Nov 2019 21:44:17 +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 1iXXla-0005nP-HU for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 21:44:04 +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 125AA4AD6; Wed, 20 Nov 2019 22:44:01 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id a6734339; Wed, 20 Nov 2019 22:43:50 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 22:43:45 +0100 Message-Id: <20191120214353.27652-3-ynezz@true.cz> In-Reply-To: <20191120214353.27652-1-ynezz@true.cz> References: <20191120214353.27652-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_134402_726715_D1B45EB2 X-CRM114-Status: UNSURE ( 7.83 ) 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 v2 libubox 02/10] 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 21:43:46 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: 1198549 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="c8A/XZkV"; 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 47JGS52Gpkz9sPL for ; Thu, 21 Nov 2019 08:44: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=U0Ms2dAFC1jcZdBk7TS9jD5QLqvbGinqx4oLZp/2k2Y=; b=c8A/XZkVCPPw6v lJbRHOnvKgXDYP0ZvL/I3JqYmHOaUNC5VJ3iIWERjXjgynSZp9J4AxAVRUTs6bPgIcbRncY0e9SGT Z8EI9JaaGcfTBB/hYkD9g+tDI7/6iVWOQ6MOhfh4W9mUZoy5cdRSoQF92K/ktbGXekFLK6DUELrlX HfFTffLAGQZaKPF8BCQkDUwxV/awIiAi9HZDtEYENZ9sEG0Ybvd7kHwTCD1id7HUgp257Q4buF9/t pdQPm1y0CFGVirE3eBepMBfHkBfkrb8xJZLfWuEJm7KnJ6YjCYLlzCAoNtHo8s9tTpoWDZL/QBW8g 8Fjd9gx6wJZDyFQT8RxA==; 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 1iXXm4-0006Ho-TQ; Wed, 20 Nov 2019 21:44:32 +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 1iXXla-0005nS-Ip for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 21:44:05 +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 4AC874AD7; Wed, 20 Nov 2019 22:44:01 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 554315ab; Wed, 20 Nov 2019 22:43:51 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 22:43:46 +0100 Message-Id: <20191120214353.27652-4-ynezz@true.cz> In-Reply-To: <20191120214353.27652-1-ynezz@true.cz> References: <20191120214353.27652-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_134402_764630_91C51395 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 v2 libubox 03/10] 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 21:43:47 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: 1198550 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="idMriHu2"; 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 47JGST4vYFz9sPJ for ; Thu, 21 Nov 2019 08:44:57 +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=4i+xY+qIBHTzIm+HNJ8dcIVBlV7zSldmpGKwgSCemD0=; b=idMriHu2rGDccA s5vCYnYjecQ8LMp51GfnYT6Sh55GKS8eLoGCNsLOtLmyk1naTdhOFDzJ0Beh8/3sXj9uZj7kmnOtE 0VId8N4EhnwY3aVk7MXRpGbi4MORbj8zRb693MogIfAgExussVknIrHMkZPCcvyDvsRd/4yPUmt8l yj+bY06oGUgzlxtyidz9mozqXmTeuZVHJO+9pNtJkV5p0WTwycQypl7xisdSd9IMPHmGzEJSpRwwJ 80BMPDrpKSqrVibc0wbwxwJ33wsqskJwhqdNGK3s8QUPwWeWIvYl531Hyj619dAkJZYxmDEsPBPVC CXRkjMDejWBWQAu2zmhg==; 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 1iXXmK-0006Xi-KY; Wed, 20 Nov 2019 21:44:48 +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 1iXXla-0005nT-RF for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 21:44:05 +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 6F5174AD8; Wed, 20 Nov 2019 22:44:01 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 93ab4d9a; Wed, 20 Nov 2019 22:43:51 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 22:43:47 +0100 Message-Id: <20191120214353.27652-5-ynezz@true.cz> In-Reply-To: <20191120214353.27652-1-ynezz@true.cz> References: <20191120214353.27652-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_134403_182216_BC7206EF 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 v2 libubox 04/10] 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-b64.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-b64.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..6832b3f52c30 --- /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(b64) diff --git a/tests/cram/CMakeLists.txt b/tests/cram/CMakeLists.txt new file mode 100644 index 000000000000..ca00d11dd686 --- /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_B64 test-b64) 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..7e41442746d8 --- /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_B64 + 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-b64.c b/tests/test-b64.c new file mode 100644 index 000000000000..c29b4e2c73a3 --- /dev/null +++ b/tests/test-b64.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 21:43:48 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: 1198552 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="N9T6L7Z6"; 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 47JGT30MNKz9sPJ for ; Thu, 21 Nov 2019 08:45:27 +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=dui7Kp7NfLPREeBQdgODDD6OuugyGJQQM1PXFASeKHY=; b=N9T6L7Z6u5/row igT4srcStqFD84teGhfa/M5GKtXdfm0Wzf4JZ7YEMkZmfnTvNY0uWM5e1F/HIgDQMLv3FnHma48ur 1iDxCc/KXVE3/pLgAbWNO4LJcd8Pf8f2JiPajfXfMuGRY8YzlEx5v6d6fuZabEtKuiCvTCy7+1GV/ heXF7yurePa+2JotdasRn6k9hEwjgAH+cC+F4fBxOy5t15FXE7mHBftMqTqg86FbYQhjLaDoCiCoy B+8tm+OerNVX7TfXcXT0sCuKDzHhN1ZrUklC4CG/J5Gobd9CgfxqJyC1CChJsSdq+4uZoVOmy9qHF yVxSvbYly8XEGyl37J8Q==; 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 1iXXmp-0008Eo-WE; Wed, 20 Nov 2019 21:45:20 +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 1iXXld-0005p2-4g for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 21:44:06 +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 8F8AE4AD9; Wed, 20 Nov 2019 22:44:01 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 6a28f81c; Wed, 20 Nov 2019 22:43:51 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 22:43:48 +0100 Message-Id: <20191120214353.27652-6-ynezz@true.cz> In-Reply-To: <20191120214353.27652-1-ynezz@true.cz> References: <20191120214353.27652-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_134405_329018_FDDB1258 X-CRM114-Status: UNSURE ( 6.86 ) 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 v2 libubox 05/10] add assert.h component 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 seamless assert() usage in release builds without the need for fiddling with CMake C flags as CMake adds -DNDEBUG switch in release builds which disable assert(). Signed-off-by: Petr Štetiar --- assert.h | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 assert.h diff --git a/assert.h b/assert.h new file mode 100644 index 000000000000..84f54718366a --- /dev/null +++ b/assert.h @@ -0,0 +1,9 @@ +#pragma once + +#ifdef NDEBUG +#undef NDEBUG +#include +#define NDEBUG +#else +#include +#endif From patchwork Wed Nov 20 21:43:49 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: 1198555 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="GX2lr8Cd"; 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 47JGTj25Dvz9sPJ for ; Thu, 21 Nov 2019 08:46:01 +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=h/MzT65amkqXMixkmLWEnfCf+PkI8WcHwFhcW3m3gLc=; b=GX2lr8Cd5KPEhN nPh+N1CNE/fajr4DOMZ25zWIZPUEq9GUFyrTUM1VJcV/RKChZvSFnH6LopOoqJ5PHRToSsVGIpxIw 67gyacN/6XTj4lkVs5/eF44TGb3mpL63nQVCeXKhnMf+ScUN2UM9sA26Thi3cyAeas0gV1qU3NM5I 4bkrqr0k40hzQ8/VYHrUyMz9bwLJhh5JpuUShpIQPAT26ouMEjxY18KRJtgKHVafQhwcIDhF/HNjy zUW/Z7um2nBbnzE33njvz0I/Vl/IR3cmVx2VA43lWiIbHbVO3tNxc+XkidqAKBy5Wxfu7MQZx5RUX pRP8Ixa/ZUS1uNgwpwwQ==; 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 1iXXnO-0000bJ-SN; Wed, 20 Nov 2019 21:45:54 +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 1iXXld-0005p3-58 for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 21:44:07 +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 046454ADA; Wed, 20 Nov 2019 22:44:01 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id b4899f54; Wed, 20 Nov 2019 22:43:52 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 22:43:49 +0100 Message-Id: <20191120214353.27652-7-ynezz@true.cz> In-Reply-To: <20191120214353.27652-1-ynezz@true.cz> References: <20191120214353.27652-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_134405_516179_BD2BACCA X-CRM114-Status: GOOD ( 10.72 ) 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 v2 libubox 06/10] base64: 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/CMakeLists.txt | 2 ++ tests/cram/CMakeLists.txt | 2 ++ tests/cram/test_base64.t | 8 ++++++++ tests/test-b64_decode.c | 7 +++++++ tests/test-b64_encode.c | 7 +++++++ 6 files changed, 32 insertions(+) create mode 100644 tests/test-b64_decode.c create mode 100644 tests/test-b64_encode.c diff --git a/base64.c b/base64.c index 4759ede01e7c..1bf21772fbed 100644 --- a/base64.c +++ b/base64.c @@ -65,6 +65,8 @@ #include #include #include + +#include "assert.h" #include "utils.h" static const char Base64[] = @@ -144,6 +146,8 @@ int b64_encode(const void *_src, size_t srclength, u_char output[4]; size_t i; + assert(dest && targsize > 0); + while (2 < srclength) { input[0] = *src++; input[1] = *src++; @@ -208,6 +212,8 @@ int b64_decode(const void *_src, void *dest, size_t targsize) state = 0; tarindex = 0; + assert(dest && targsize > 0); + while ((ch = (unsigned char)*src++) != '\0') { if (isspace(ch)) /* Skip whitespace anywhere. */ continue; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6832b3f52c30..60d7b9839ad4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,3 +8,5 @@ ENDMACRO(ADD_UNIT_TEST) ADD_UNIT_TEST(avl) ADD_UNIT_TEST(b64) +ADD_UNIT_TEST(b64_encode) +ADD_UNIT_TEST(b64_decode) diff --git a/tests/cram/CMakeLists.txt b/tests/cram/CMakeLists.txt index ca00d11dd686..2deb4ef3dd1f 100644 --- a/tests/cram/CMakeLists.txt +++ b/tests/cram/CMakeLists.txt @@ -25,3 +25,5 @@ ENDMACRO(ADD_CRAM_TEST_ENV) ADD_CRAM_TEST_ENV(JSHN jshn) ADD_CRAM_TEST_ENV(TEST_AVL test-avl) ADD_CRAM_TEST_ENV(TEST_B64 test-b64) +ADD_CRAM_TEST_ENV(TEST_B64_ENCODE test-b64_encode) +ADD_CRAM_TEST_ENV(TEST_B64_DECODE test-b64_decode) diff --git a/tests/cram/test_base64.t b/tests/cram/test_base64.t index 7e41442746d8..f58bbaa71acb 100644 --- a/tests/cram/test_base64.t +++ b/tests/cram/test_base64.t @@ -15,3 +15,11 @@ check that base64 is producing expected results: 4 foob 5 fooba 6 foobar + + $ $TEST_B64_DECODE 2>&1 | cut -d : -f4- + b64_decode: Assertion `dest && targsize > 0' failed. + Aborted (core dumped) + + $ $TEST_B64_ENCODE 2>&1 | cut -d : -f4- + b64_encode: Assertion `dest && targsize > 0' failed. + Aborted (core dumped) diff --git a/tests/test-b64_decode.c b/tests/test-b64_decode.c new file mode 100644 index 000000000000..4798fa8da380 --- /dev/null +++ b/tests/test-b64_decode.c @@ -0,0 +1,7 @@ +#include "utils.h" + +int main() +{ + b64_decode("Zg==", NULL, 2); + return 0; +} diff --git a/tests/test-b64_encode.c b/tests/test-b64_encode.c new file mode 100644 index 000000000000..5f011e52dec6 --- /dev/null +++ b/tests/test-b64_encode.c @@ -0,0 +1,7 @@ +#include "utils.h" + +int main() +{ + b64_encode("foo", 3, NULL, 2); + return 0; +} From patchwork Wed Nov 20 21:43:50 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: 1198553 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="tWkw9O+e"; 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 47JGT916vpz9sPJ for ; Thu, 21 Nov 2019 08:45:33 +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=tWkw9O+eHGRF+s 6bx+0Jom7rePLeXwW+a3ukFQ8Ux7qVTYofSBZWvuCQm63dpgKZ/Y2VyuG9suOYgBO6Z2yqskvj95Y BAcbfLrjEiVQnBRiq9y77lnoTEW9sQtNBN8R5AOV0N1VVCBfa3vc0Hm2G3Rci7dqtkYz4p2MMstXA 8tSm3T79okF0tS/SFwmkwS4upxlGr5QUPFHvgP3+laoUYejok1NkLGXgnv+wkYO1hg/6WsRGlICLj THMSEeMdHHXQsQ2VNVz4z2FEmA7swp3XAV3HF2sCw8bSvaAbE3+559oBJ6ogF1Z5vWAyOgHkfQbfk VJyPT2sTbqmforoGhTFA==; 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 1iXXmz-0008T3-J8; Wed, 20 Nov 2019 21:45: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 1iXXld-0005p4-Bp for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 21:44:07 +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 3CBF94ADB; Wed, 20 Nov 2019 22:44:02 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 123b00af; Wed, 20 Nov 2019 22:43:52 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 22:43:50 +0100 Message-Id: <20191120214353.27652-8-ynezz@true.cz> In-Reply-To: <20191120214353.27652-1-ynezz@true.cz> References: <20191120214353.27652-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_134405_595776_25DC4402 X-CRM114-Status: UNSURE ( 7.54 ) 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 v2 libubox 07/10] 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 21:43:51 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: 1198554 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="rt4B0Ehh"; 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 47JGTP5Kjvz9sPL for ; Thu, 21 Nov 2019 08:45: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=cBjYUiR1ZJIBxWvq7xY3uqadTeNpwmghvoVxYqhOGgw=; b=rt4B0EhhPUAoD8 iEckQkpkmBSl3l3EULJ5MYL/18VVN/t3lbyOKAjlFSGs1V7nQvC/MAiVlXqcX8s0/lGkDpJSmPWiH l/v1k0thYJRC6eHYT4100UyjqWcHVE8yWY9zvoNgsd6ZihLD56r+VgrU57yf+OhH3tpJNFEsGapAx ask/yn5VdK8lAo6Zd2GOxfs7ttCutlKHsw5HuSd7/vB0hgHWFCYMRRQjPO1wVe1OqSLV3qKZSw8Zy P6NzlSvNTnF3+M4zqC8v8DF2V7DorSeL807Ba2BBSC4r/BWnPcZ498aqjrkO1FJONf3Bgn5gKTcBb +kMX5gTL6YqpwKCXybDQ==; 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 1iXXnB-0000Jn-D8; Wed, 20 Nov 2019 21:45: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 1iXXld-0005p5-C2 for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 21:44:07 +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 784794ADD; Wed, 20 Nov 2019 22:44:03 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 19982418; Wed, 20 Nov 2019 22:43:53 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 22:43:51 +0100 Message-Id: <20191120214353.27652-9-ynezz@true.cz> In-Reply-To: <20191120214353.27652-1-ynezz@true.cz> References: <20191120214353.27652-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_134405_589799_D9E6E64A X-CRM114-Status: UNSURE ( 7.91 ) 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 v2 libubox 08/10] 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 21:43:52 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: 1198556 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="rucThYuY"; 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 47JGTr2C55z9sPJ for ; Thu, 21 Nov 2019 08:46: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=7X3zGc6MZ1lVFEfOe457etDb0kNsEhNE5Gp7WHOOT74=; b=rucThYuY4v6aY6 5pFY8VVHLWf2WfYXDGrtNfkIF5S+rkSNkm8rjuXryTIskPnEgg9q0rbPSnIMayKAvH0ojpIjB4ScL alZXRgmVDN4PB+wRZuwUkF+asVld86J3p3guewjvj+TmWBHg43oUP+HbkKWcsLpzTHQlrJdip1v+j Fp/bCarLzu2XZtMNhTPNU029RMf4FzqlEtEbSb4/gzy7GoZr50/xa4dDSb963Bki+ChfawAz/mtfi Y5msvq+6GIfuYsgAO0lvZ8uqGIqtOb0PpJdZk4KmL0cMgNu2wbrHzTG/CeWkZnq+bPCOj37vMMayM dmB+aKbRFDbIQfqCgxwg==; 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 1iXXna-0000n4-0K; Wed, 20 Nov 2019 21:46: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 1iXXle-0005q3-P6 for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 21:44:08 +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 97F914ADE; Wed, 20 Nov 2019 22:44:03 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 938163f7; Wed, 20 Nov 2019 22:43:53 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 22:43:52 +0100 Message-Id: <20191120214353.27652-10-ynezz@true.cz> In-Reply-To: <20191120214353.27652-1-ynezz@true.cz> References: <20191120214353.27652-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_134406_972228_D62ACB3D X-CRM114-Status: UNSURE ( 7.65 ) 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 v2 libubox 09/10] 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 21:43:53 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: 1198557 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="h02zX+zI"; 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 47JGV91jrVz9sPJ for ; Thu, 21 Nov 2019 08:46:25 +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=d78p4AX3E2cQegodzf7wQ55B1bI4EOqTDaAuQlxK1zA=; b=h02zX+zIsJgvZ8 F/ManMstXqH2DNCCBCEbJqECQR9PTHXvMlQYE/SWJZdSiWVKzGPKp/xnW+pLG4gSt1SfYtV3pA16G Al69S1G0yzOAMK7WUIknWA+uRAjZWg3+TNzfdWxPwKYYbqB4XrA+hEZJ4li/EpcxwGyVxT4cfWvgm QrbFqp4yY13qSFSGuxbbomc0OHf0ALTGLeAgGq5+Khg8pnQGZqaU8HA5NsRk50nAFJOVPtP2Z1FMX 3GA3rbYlLBIxiEdhkoXtoywx7ZTHsWJY4S300rvCWtf+PlMGL4N2YyrkRp2gAfR2dlNBXcKiiqPyO B+2F5JNJAmDBth2xklVw==; 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 1iXXnl-00015r-Ks; Wed, 20 Nov 2019 21:46:17 +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 1iXXle-0005q2-RE for openwrt-devel@lists.openwrt.org; Wed, 20 Nov 2019 21:44:08 +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 B7BC34ADF; Wed, 20 Nov 2019 22:44:03 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 8a342ee3; Wed, 20 Nov 2019 22:43:53 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 20 Nov 2019 22:43:53 +0100 Message-Id: <20191120214353.27652-11-ynezz@true.cz> In-Reply-To: <20191120214353.27652-1-ynezz@true.cz> References: <20191120214353.27652-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_134407_045538_3B379FBC X-CRM114-Status: UNSURE ( 7.44 ) 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 v2 libubox 10/10] 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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/avl.c b/avl.c index 8d0bf65aaa5b..79ea5c798b64 100644 --- a/avl.c +++ b/avl.c @@ -45,6 +45,7 @@ #include #include "avl.h" +#include "assert.h" #include "list.h" /** @@ -668,6 +669,7 @@ avl_delete_worker(struct avl_tree *tree, struct avl_node *node) return; } + assert(node->right); node->right->parent = parent; if (parent->left == node)