From patchwork Mon Jul 18 02:24:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rosen Penev X-Patchwork-Id: 1657275 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=gGqeF1V8; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=TauCykIE; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LmQt90vctz9sFs for ; Mon, 18 Jul 2022 12:30:25 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=TLGN4gz21DVCo5+S+4FDsVvQmP8a5pWyUd1mDVLVefo=; b=gGqeF1V8WSgCTo DtknHIGnbgPmdGRaLji9rd9XiT4STFb/7x1CyAKGxF2xwW3IfSBpyPCDEkpkNU4YtSE6c6JrYTR3s g731sy8zry6kCJV1uVz8pTeBDizV0wTJyta1hl2iZSN+ZLgksElaLXvQf8TNlEpcS7OXG6/xcJlIJ R4kjbxZ4nF/YzZwQosCK2wOQ6V2fqfbRffzJcYyUM18R4bGKhd3kqEZVZE5Nv+nHNuNZ6TpfaGpp8 njpY6xkAIMeSEp5xKlq4znlA10I6OLgc0ZmYDuKlBMHn8P05/z/2CxY7ySgtEu5/TI7CKfedylB9l kw9Mwr5y+WD5NSDdQz3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oDGRI-00A7Ks-3I; Mon, 18 Jul 2022 02:24:52 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oDGRB-00A7Ip-3H for openwrt-devel@lists.openwrt.org; Mon, 18 Jul 2022 02:24:46 +0000 Received: by mail-pf1-x42a.google.com with SMTP id g126so9474655pfb.3 for ; Sun, 17 Jul 2022 19:24:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=91zIm9R+WjsV4nu05oWrx8wZLAOhJE+T9OqEWXcX2l4=; b=TauCykIEG6/8ik/QwKhhOwaPqtdwb5/vLRVK6vRU+lggqlERBa763a212Zxb6R9VGJ 8/TcWLM7TGeFuK0kPq+4gNiI+1sNrlzFCL9Tm+js1Et9t9VuAgVSEFjTtXh+dYQrtOPg u4fhgZmqISzoTsonAJilBQc/90GY4XuD7z+5zpu7Dn5/c//Naw7qKaBg2RymqwnOb9Zo 8J1QFAKkOcmnFrPT0+JKjqi8QOVBFsycx0wqkerbWVG39r+WvlqXxkcUQMqydwKwom4Y 9FufTZjsgEpEyJsbWWkWEEHiaUaih/pIKJ6JO7qmq67wx64STdvwEsrXgvdw64gnR1ko HI8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=91zIm9R+WjsV4nu05oWrx8wZLAOhJE+T9OqEWXcX2l4=; b=G01e7Rsfznxa7oCbvGoDl1OpmrdXKyKfTNDBlk80RRnhwDRZqGmAJR3dUbxUnH749p y3nut39SrwRZqf22rYfEeJxN3Yc3snhROhhEQNp2IzBp303O+44kD7YNZH/LX8C3GSYh s68v0W947RVjKQpRqzh101mLlCMuYtlMAU79kOoQw/+rBFbzxoWjWe7o6cogDVryKO7F EWFu/z6QgHuO/2fqmhjItHqAFst6QhQKbyvdm3n3i4BcMZgcHGQXG09DjLjACGL6oKhH lckhbwIfXmyKXDuWjOpUNRzb+47FrJxIzpuvM+8nduEEm/3MREE2BYsaL0Nnqdnu08Qq kOHg== X-Gm-Message-State: AJIora/496Po4zySVE4VmxAypE+wW0+fSOHSfPRMvjbyoFC9FgaFgjiF jEDPFD+9gN55Dk+aP5TRk1X+Fr649Yk= X-Google-Smtp-Source: AGRyM1s1SxkOMB2vSmslSpFqXQJgBqeQDlms4qvBpIAJ2Aerzc58vERXqjrL7nh3qBBAi0DtQze/ZA== X-Received: by 2002:a63:65c2:0:b0:419:8146:b1a7 with SMTP id z185-20020a6365c2000000b004198146b1a7mr23304084pgb.210.1658111079935; Sun, 17 Jul 2022 19:24:39 -0700 (PDT) Received: from ryzen.lan ([2601:648:8600:b53::8c6]) by smtp.gmail.com with ESMTPSA id j12-20020a170903024c00b0016c4546fbf9sm8067519plh.128.2022.07.17.19.24.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 19:24:39 -0700 (PDT) From: Rosen Penev To: openwrt-devel@lists.openwrt.org Subject: [PATCH 1/2] ubox: fix GCC fanalyzer warnings Date: Sun, 17 Jul 2022 19:24:36 -0700 Message-Id: <20220718022437.1714176-1-rosenp@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220717_192445_160670_1DC3A681 X-CRM114-Status: GOOD ( 10.59 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: memory leaks and missing NULL checks. Signed-off-by: Rosen Penev --- kmodloader.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kmodloader.c b/kmodloader.c index 63bae5e..bc5f20c 100644 --- a/kmodloader.c +++ b/kmodloader.c @@ -336,6 +336,11 @@ static int scan_loaded_modules(void) /* possibly a module outside /lib [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [rosenp[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42a listed in] [list.dnswl.org] X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org memory leaks and missing NULL checks. Signed-off-by: Rosen Penev --- kmodloader.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kmodloader.c b/kmodloader.c index 63bae5e..bc5f20c 100644 --- a/kmodloader.c +++ b/kmodloader.c @@ -336,6 +336,11 @@ static int scan_loaded_modules(void) /* possibly a module outside /lib/modules// */ n = alloc_module(m.name, NULL, 0, m.depends, m.size); } + if (!n) { + ULOG_ERR("Failed to allocate memory for module\n"); + return -1; + } + n->usage = m.usage; n->state = LOADED; } @@ -416,7 +421,8 @@ out: if (fd >= 0) close(fd); - free(aliases); + if (aliases) + free(aliases); return m; } @@ -581,6 +587,11 @@ static int insert_module(char *path, const char *options) struct stat s; int fd, ret = -1; + if (!path) { + ULOG_ERR("Path not specified\n"); + return ret; + } + if (stat(path, &s)) { ULOG_ERR("missing module %s\n", path); return ret; @@ -1162,6 +1173,8 @@ load_options(void) continue; } } + + fclose(f); } int main(int argc, char **argv) From patchwork Mon Jul 18 02:24:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rosen Penev X-Patchwork-Id: 1657274 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=YM7uW7yf; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=E/FuMLaZ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LmQt60wgxz9sFs for ; Mon, 18 Jul 2022 12:30:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lH77Pu/id2YinP4f9h/P/I0s+6zyxwqMyo+dkxgSD1U=; b=YM7uW7yfaFk8rz WDS43GtzWD9hghsmDQufytq9YgPhBiGqoKe16DKqbeeGLG+c1CDxIiY/QfBdVCGANjJT5aXhea8Po 0Iz7CBDiiZiOdUtV/Z5RnL7eYINxzuxrKriXGAHbEYi23WAqu+WRHgGWGvXiryCcAk2gEy6N2tIEZ 2iw/ZTI1KZkN6LKa2wvhhWnvtXDXowdkiT1O8htQXGe8WqSWBTCj6FywIiMkSNKzHuxHNF2UYcmRj 3EFXsF/6sfbCSZGzT36TFdWCVc8NyH+uv3vHDKBXnNkXV6zktGX6B9Nfj7CK/T+8RsOxaoHe5mdWC mTXOQztQipOHNuGjkYBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oDGRU-00A7Ok-6K; Mon, 18 Jul 2022 02:25:04 +0000 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oDGRB-00A7JI-J2 for openwrt-devel@lists.openwrt.org; Mon, 18 Jul 2022 02:24:46 +0000 Received: by mail-pg1-x52b.google.com with SMTP id h132so9370152pgc.10 for ; Sun, 17 Jul 2022 19:24:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=a35nBx5+IRMnWUJEXHjvbUo7P5A87d9woJkVeQ2GzMo=; b=E/FuMLaZFOyk7F5lrD7333pzD08skWv4AYBAIoIr5GEdLczobOI40pUaYHchM3Fmse yZysX1Mmup7m2oHGjuQ6Gl/va3knyisRc+IbscjJ8L0uvDWDcnQNWj5W7ptc/e0bwYKq W5GEH2b69QT82CbOEbeY2LmX1bQPIf21m6l1u9wCD8FraamvXT882+wEZnmDMTygnuo8 22WU2TrmPrllTYw2VHUj73rPzV9CQVsAnrMZQytMqcN793bYQaCiitUpMvR3tu2nhgPq IgwTai9PKufVSXG/kfEGJaWOolwbynpntWEVRErc+g5o6lqE9WccAC/18PZZ66dLeLMk uT/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a35nBx5+IRMnWUJEXHjvbUo7P5A87d9woJkVeQ2GzMo=; b=xx1jNrXUvzvsmRw5zyChGMfwPcjwf4KLq2e3bf4jElQdgb+TYmNJciW3SQevPT9hes ElXFeWgQf71/RJne5cAQo5nf7tEWZdjxafjTWVcFY9Mb6t7kFkSqvXfmUdbliI/kMW6A ySWqDIDgbp7HZoOKrVA/QCpLL4NfJvnDBYQCN+k+AfxoUCoM83NonrVn/dM67SFt0FEY 12XKJnI3cS4GdOke3o35KdfzKJHI8SFfmYT4h8xfnoTztbvb8TNVAeRO31kuFMKc08Hl 4sdtd+t4nGTE6S9ml3+t6anNvGZ8XjI5inVGpanqcadxazfY9xmsBwrmVmDXdPztse0j oZ0w== X-Gm-Message-State: AJIora9GHUW5LGo4AbcdxyapgMUZa7Tcd0pGCZRTCtR6mOzuH2z6z3RV OdDBPB/vnSC0irOKnhl32yZwkZvcAq4= X-Google-Smtp-Source: AGRyM1vKcHxn3yVwJiXULVEfheYxaqRGXQ0pvPbdlD9ptoWkxNbtpMi7ulkAfXDufgHGmYWKTt6QGw== X-Received: by 2002:a63:ff4c:0:b0:412:b100:786b with SMTP id s12-20020a63ff4c000000b00412b100786bmr23165323pgk.537.1658111081707; Sun, 17 Jul 2022 19:24:41 -0700 (PDT) Received: from ryzen.lan ([2601:648:8600:b53::8c6]) by smtp.gmail.com with ESMTPSA id j12-20020a170903024c00b0016c4546fbf9sm8067519plh.128.2022.07.17.19.24.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 19:24:41 -0700 (PDT) From: Rosen Penev To: openwrt-devel@lists.openwrt.org Subject: [PATCH 2/2] ubox: fix bad realloc usage Date: Sun, 17 Jul 2022 19:24:37 -0700 Message-Id: <20220718022437.1714176-2-rosenp@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220718022437.1714176-1-rosenp@gmail.com> References: <20220718022437.1714176-1-rosenp@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220717_192445_645160_53AB67F4 X-CRM114-Status: GOOD ( 10.53 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Both cppcheck and gcc's -fanalyzer complain here that realloc is being used improperly. Signed-off-by: Rosen Penev --- kmodloader.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kmodloader.c b/kmodloader.c index bc5f20c..5f8c9c1 100644 --- a/kmodloader.c +++ b/kmodloader.c @@ -356,6 +356,7 @@ static struct module* get_module_info(const char *module, const char *n [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [rosenp[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:52b listed in] [list.dnswl.org] X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Both cppcheck and gcc's -fanalyzer complain here that realloc is being used improperly. Signed-off-by: Rosen Penev --- kmodloader.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kmodloader.c b/kmodloader.c index bc5f20c..5f8c9c1 100644 --- a/kmodloader.c +++ b/kmodloader.c @@ -356,6 +356,7 @@ static struct module* get_module_info(const char *module, const char *name) unsigned int offset, size; char *map = MAP_FAILED, *strings, *dep = NULL; const char **aliases = NULL; + const char **aliasesr; int naliases = 0; struct module *m = NULL; struct stat s; @@ -398,12 +399,13 @@ static struct module* get_module_info(const char *module, const char *name) if (!strncmp(strings, "depends=", len + 1)) dep = sep; else if (!strncmp(strings, "alias=", len + 1)) { - aliases = realloc(aliases, sizeof(sep) * (naliases + 1)); - if (!aliases) { + aliasesr = realloc(aliases, sizeof(sep) * (naliases + 1)); + if (!aliasesr) { ULOG_ERR("out of memory\n"); goto out; } + aliases = aliasesr; aliases[naliases++] = sep; } strings = &sep[strlen(sep)];