From patchwork Sat May 2 17:28:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1281718 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=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=CK/eEy1N; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Dx1q1R5Hz9sSW for ; Sun, 3 May 2020 03:29:19 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id EEC7F871CF; Sat, 2 May 2020 17:29:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dpnQP4znQsV0; Sat, 2 May 2020 17:29:14 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id D0FBF8716A; Sat, 2 May 2020 17:29:13 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A4D70C088D; Sat, 2 May 2020 17:29:13 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1DCD9C016F for ; Sat, 2 May 2020 17:29:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 0C7EF881BE for ; Sat, 2 May 2020 17:29:12 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id D288aMAJ6cSV for ; Sat, 2 May 2020 17:29:11 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by whitealder.osuosl.org (Postfix) with ESMTPS id 8CB018816C for ; Sat, 2 May 2020 17:29:11 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id 18so3199644pfv.8 for ; Sat, 02 May 2020 10:29:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=EzZmw8sBaYAIns60nND+diIg1nyWN9I1og2rtTJsf5E=; b=CK/eEy1N4BIFDh6vyHH929il81tEvBgbqF2FBeKZ8rcz/4xKB0h4XW7TGAKjtJnC/5 h0xjQl82bkjSijNENU6XQD4n0BZYrDA/OHnEtG8xm7G6T5h1IB3GB8n6O9xdNvuWKbHI 9GkPLfO7q1mxHN1gWe8J9ynL7J9LmER9F04LKTSBUtzA+xCe8agi1q4I73+RmqyO+vR9 x9FXnbQKPzRiLfeaOQ8z4GAfNtfcjVa5WdgFoQTLDNC3Z40rnIRE0kYeygv/aiq5Uf/W gYTRZEBx7xNyFpJ0Jjm0CktevAWnc7FqSgMS9CIrS5hwyAZXUZwKdClNzpXYUz5pzgb3 CF8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=EzZmw8sBaYAIns60nND+diIg1nyWN9I1og2rtTJsf5E=; b=IK3avwQBbl9hzwbNLGM8Crdl1yZ4xFKyspnyVIsCOvvjP2P3MaKFtE4ORXFk9wgQGD RBvUkg7zEL5Wah1bbLPuhvsPvk2j2v5lJGh7f70ZhIEei1VQTH7sfTHIOYW95KPef/N3 Avg/N9AOJ6rc/Xdss1NSwv6w0i+0XkFv3UEHLIE0SEGvyNtftSrArGED1SUyKRli4aJs PBgWm1ZrPUIBZBxTnQXdIZpnixH0d8T9DEaHNUi6c6aVTvePd7OaW0S4hVWMTmwiN8hv /ktFwu3GhqBLrt5pmg4ormwOBz22YddA5WV8YNeepwUqGRQQPIxqXScaJPYwy69yZOJT J+mw== X-Gm-Message-State: AGi0PubHluno2yMeu/UWSPoR/+P2tksb+PVAq13g3KVzSIcWolpzeIML Eo9nrOK0+raVlLIcimDF7cAVw69j X-Google-Smtp-Source: APiQypKTmpwokVT4Y7NvQPbIr+Zrqety74u8Xp5KhUnuip9+R3HA33fmXMwJvzm/7y2wF7JNq18SPg== X-Received: by 2002:aa7:8489:: with SMTP id u9mr9937684pfn.248.1588440550829; Sat, 02 May 2020 10:29:10 -0700 (PDT) Received: from sc9-mailhost3.vmware.com (c-76-21-95-192.hsd1.ca.comcast.net. [76.21.95.192]) by smtp.gmail.com with ESMTPSA id gn20sm2637784pjb.24.2020.05.02.10.29.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 May 2020 10:29:10 -0700 (PDT) From: William Tu To: dev@openvswitch.org Date: Sat, 2 May 2020 10:28:43 -0700 Message-Id: <1588440525-71022-2-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1588440525-71022-1-git-send-email-u9012063@gmail.com> References: <1588440525-71022-1-git-send-email-u9012063@gmail.com> Subject: [ovs-dev] [PATCH 1/3] ovsdb-idlc: Fix memory leak reported by Coverity. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Coverity shows the following memory leak in this code pattern: void ovsrec_ipfix_index_set_obs_domain_id( { struct ovsdb_datum datum; // 1. alloc_fn: Storage is returned from allocation function xmalloc. // 2. var_assign: Assigning: key = storage returned from xmalloc(16UL). union ovsdb_atom *key = xmalloc(sizeof(union ovsdb_atom)); // 3. Condition n_obs_domain_id, taking false branch. if (n_obs_domain_id) { datum.n = 1; datum.keys = key; key->integer = *obs_domain_id; } else { datum.n = 0; datum.keys = NULL; } datum.values = NULL; ovsdb_idl_index_write(CONST_CAST(struct ovsdb_idl_row *, // CID 1420891 (#1 of 1): Resource leak (RESOURCE_LEAK) Fix it by moving the xmalloc to the true branch. Signed-off-by: William Tu Reviewed-by: Yifeng Sun --- ovsdb/ovsdb-idlc.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in index c285ee4b3c10..1d385e15c1e5 100755 --- a/ovsdb/ovsdb-idlc.in +++ b/ovsdb/ovsdb-idlc.in @@ -1351,9 +1351,10 @@ struct %(s)s * print(" datum.values = NULL;") txn_write_func = "ovsdb_idl_index_write" elif type.is_optional_pointer(): - print(" union ovsdb_atom *key = xmalloc(sizeof (union ovsdb_atom));") + print(" union ovsdb_atom *key;") print() print(" if (%s) {" % keyVar) + print(" key = xmalloc(sizeof (union ovsdb_atom));") print(" datum.n = 1;") print(" datum.keys = key;") print(" " + type.key.assign_c_value_casting_away_const("key->%s" % type.key.type.to_string(), keyVar)) @@ -1364,9 +1365,10 @@ struct %(s)s * print(" datum.values = NULL;") txn_write_func = "ovsdb_idl_index_write" elif type.n_max == 1: - print(" union ovsdb_atom *key = xmalloc(sizeof(union ovsdb_atom));") + print(" union ovsdb_atom *key;") print() print(" if (%s) {" % nVar) + print(" key = xmalloc(sizeof(union ovsdb_atom));") print(" datum.n = 1;") print(" datum.keys = key;") print(" " + type.key.assign_c_value_casting_away_const("key->%s" % type.key.type.to_string(), "*" + keyVar)) From patchwork Sat May 2 17:28:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1281719 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=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=IN7kSnDr; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Dx1v0rhhz9sPF for ; Sun, 3 May 2020 03:29:22 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 3AF9B88250; Sat, 2 May 2020 17:29:20 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EwriznqvZ17n; Sat, 2 May 2020 17:29:17 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id B4001881E9; Sat, 2 May 2020 17:29:14 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8A2A5C088F; Sat, 2 May 2020 17:29:14 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 138ACC016F for ; Sat, 2 May 2020 17:29:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 0731288790 for ; Sat, 2 May 2020 17:29:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Bn1hgiBgZ71J for ; Sat, 2 May 2020 17:29:12 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by hemlock.osuosl.org (Postfix) with ESMTPS id 8967988783 for ; Sat, 2 May 2020 17:29:12 +0000 (UTC) Received: by mail-pj1-f67.google.com with SMTP id y6so1503245pjc.4 for ; Sat, 02 May 2020 10:29:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=V6jozTdeuzPCvibUbSKB0/fLmEKlIXr4MLfX4s7UknU=; b=IN7kSnDrqe/ZXc0VLfuQzegNIcuZKsCDI602a3ipOCKhxCRU+7Hxd7BQkC49Qc4JWe gGkkzhrj8kJy+itOkbhPbqbUUw6ryH3BNuVaOMxNdmXla4QtlV3SMVtYe5RKcB7z9r7G XNINAetc071GHRPO9nxpd4e0Y5CyupgeHU5GVoptAPwQgwjcmKT1DJTB8FnBOpl7HQd1 O9j2XeKjYdT+M5j1xShTldbRf0zUS9jrnhRuj6EUP3NQrFTBkecC5TOomU5agYW1OCsk waBGVHvADrNWrWO7BygJCYbpkOxHbtQfiJGGIv0nfMLGv+FaD0jJu3hrkW3EHzRNqJVP 5kyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=V6jozTdeuzPCvibUbSKB0/fLmEKlIXr4MLfX4s7UknU=; b=LZH5iGKZeSGPX8KO4BV1v+jA/SAh5HUXu0ZoA3miuqiWXg3D8rpOtm9BKoJPQc8Vcz 5dlhnntBNyvXysGb86EvCqsFeEp6HveulfF9r+CcJvZ4nLLfwSLwnM6G3T7wiktqjWyg PFCHcl5FEhn4J9OTbkh35reQhWSE6/xm7Y8p0N60+cBjmU0qkeAup23zEGQ/wIyOiaNT kN27AIz78U9D3yrev2x9dP+WD2lHj+bhJxuKlC+RYzkUnkRlMCU76EocryT8UR27aBOM mX179lWdZ+hyRuDIjBBSU85l/nlpxem6j5MLcUac5ssD+iJEILUXfVJYJ3wSAcK1SZzc cb+g== X-Gm-Message-State: AGi0Puaz1Sr2RK86NM3VIat3XqgEfPuKWuOqZ04DymG7FLo2+sVcLW21 q1dIBbCiZJlm+eqOq9R4GUzy2peA X-Google-Smtp-Source: APiQypIpUrltyK0ijDXRHKGRSGkz08aUMSkJFwzZeYxHp4fbTBSoeWWeGo1MErcTnPsy0vwnTyKiDQ== X-Received: by 2002:a17:902:b709:: with SMTP id d9mr10108042pls.118.1588440551828; Sat, 02 May 2020 10:29:11 -0700 (PDT) Received: from sc9-mailhost3.vmware.com (c-76-21-95-192.hsd1.ca.comcast.net. [76.21.95.192]) by smtp.gmail.com with ESMTPSA id gn20sm2637784pjb.24.2020.05.02.10.29.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 May 2020 10:29:11 -0700 (PDT) From: William Tu To: dev@openvswitch.org Date: Sat, 2 May 2020 10:28:44 -0700 Message-Id: <1588440525-71022-3-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1588440525-71022-1-git-send-email-u9012063@gmail.com> References: <1588440525-71022-1-git-send-email-u9012063@gmail.com> Subject: [ovs-dev] [PATCH 2/3] ovsdb-idlc: Fix memory leak reported by Coverity. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" An exmplae pattern shown below: void ovsrec_ct_zone_index_set_external_ids(const struct ovsrec_ct_zone... { // 1. alloc_fn: Storage is returned from allocation function xmalloc. // 2. var_assign: Assigning: datum = storage returned from xmalloc(24UL). struct ovsdb_datum *datum = xmalloc(sizeof(struct ovsdb_datum)); // 3. Condition external_ids, taking false branch. if (external_ids) { ... } else { // 4. noescape: Resource datum is not freed or pointed-to in ovsdb_datum_init_empty. ovsdb_datum_init_empty(datum); } // 5. noescape: Resource datum is not freed or pointed-to in ovsdb_idl_index_write. ovsdb_idl_index_write(CONST_CAST(struct ovsdb_idl_row *, &row->header_), &ovsrec_ct_zone_columns[OVSREC_CT_ZONE_COL_EXTERNAL_IDS], datum, &ovsrec_table_classes[OVSREC_TABLE_CT_ZONE]); // CID 1420856 (#1 of 1): Resource leak (RESOURCE_LEAK) // 6. leaked_storage: Variable datum going out of scope leaks the storage it points to. Fix it by freeing the datum. Signed-off-by: William Tu Reviewed-by: Yifeng Sun --- ovsdb/ovsdb-idlc.in | 1 + 1 file changed, 1 insertion(+) diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in index 1d385e15c1e5..698fe25f3095 100755 --- a/ovsdb/ovsdb-idlc.in +++ b/ovsdb/ovsdb-idlc.in @@ -1306,6 +1306,7 @@ struct %(s)s * &%(s)s_columns[%(S)s_COL_%(C)s], datum, &%(p)stable_classes[%(P)sTABLE_%(T)s]); + free(datum); } """ % {'t': tableName, 'p': prefix, From patchwork Sat May 2 17:28:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1281717 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=openvswitch.org (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=NhELoA56; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Dx1q1GJmz9sPF for ; Sun, 3 May 2020 03:29:19 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 0DE8D8890E; Sat, 2 May 2020 17:29:17 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ag+sL2yX+dAM; Sat, 2 May 2020 17:29:16 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id 629F388900; Sat, 2 May 2020 17:29:16 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 47D3FC088A; Sat, 2 May 2020 17:29:16 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8330DC088C for ; Sat, 2 May 2020 17:29:14 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 7378D8717B for ; Sat, 2 May 2020 17:29:14 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NThjWzr-nja5 for ; Sat, 2 May 2020 17:29:13 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 76C3B86FCC for ; Sat, 2 May 2020 17:29:13 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id 18so3199670pfv.8 for ; Sat, 02 May 2020 10:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=onZ4Pja38VgRm3abXEr9OBQwEg9Lqgtv2CJ6uInN79g=; b=NhELoA56w3jl1+YzybdRU3bubK7e8EEP4sclkcbYFX54W9jseRQRjynh+4Xi1CudvA 2rSIPybxYfFH++svC4gzP5gnqbg00k+NxvSJEjFKBqQPiNdsI1H3g9oDm8ShynjwXfmc HaU85yC/4gSfbMB5Y6Zg7j3ISz7qs0jVe6yvc9Zn80pAoZnimdaOdW0z6hulnig54Cx/ p2G36TRuFJBVbRuk8qa9TT5pSdaaOEpJPO3iybtZ+QRxJlTALNdZP2mzuE0YQLMCsbBJ hRgJ0eLerNR76oPn4TRpqZKBRT5MAibPuCAJyeTkMGOGpKOO+MEn6KUa6VUT3ibuQMcK g4uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=onZ4Pja38VgRm3abXEr9OBQwEg9Lqgtv2CJ6uInN79g=; b=WC/sO6eOfPimCZReKsREkJrgn4Z2PHn5mYqFhNZd4hylY7OVS9TovUdZIZXFVRkQlD psZOHDPLmd/0YYc1aiNBrYuJJpC2yqQr0g2gA9urSKNOuQkgqBDg6ZPP2sAtuyUHUS8A CWJx1o8gmuOmcjEVjmhQL9xS1RlOQdDVXZlLzmFAsyz0Va34kA3h/FvlshjjgBqh82M+ W7zKM8HA07rUO4L5nO9Xw6Hl0B2AWKpaarbCKXIsUqhi8i1ZnhYY7MRH10wrV5cy9JP1 jzRMZJd+sMw5OurGXpk1mMUk0Ya4TjjjRcqNv2py3AbIPKmhxfeBy1dk9TKnt3d1LpXs 4uoA== X-Gm-Message-State: AGi0PuY9mzfYB7GxDAcn+tLFCwP2HT1GykMHbSeXswt1qUQrH8DVdW0W 5v4BPZdG8yDEPoFYCsSW9wwyH45o X-Google-Smtp-Source: APiQypLt6yOCAdCuwDPzlGyd0STR8NS8727lxs2mCMsFXje05BbiSIyLWZIwCZa++QOW85SuPdOzsg== X-Received: by 2002:a63:2403:: with SMTP id k3mr9308215pgk.295.1588440552865; Sat, 02 May 2020 10:29:12 -0700 (PDT) Received: from sc9-mailhost3.vmware.com (c-76-21-95-192.hsd1.ca.comcast.net. [76.21.95.192]) by smtp.gmail.com with ESMTPSA id gn20sm2637784pjb.24.2020.05.02.10.29.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 May 2020 10:29:12 -0700 (PDT) From: William Tu To: dev@openvswitch.org Date: Sat, 2 May 2020 10:28:45 -0700 Message-Id: <1588440525-71022-4-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1588440525-71022-1-git-send-email-u9012063@gmail.com> References: <1588440525-71022-1-git-send-email-u9012063@gmail.com> Subject: [ovs-dev] [PATCH 3/3] ovsdb-idl: Fix NULL deref reported by Coverity. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When 'datum.values' or 'datum.keys' is NULL, some code path calling into ovsdb_idl_txn_write__ triggers NULL deref. An example is below: ovsrec_open_vswitch_set_cur_cfg(const struct ovsrec_open_vswitch { struct ovsdb_datum datum; union ovsdb_atom key; datum.n = 1; datum.keys = &key; key.integer = cur_cfg; // 1. assign_zero: Assigning: datum.values = NULL. datum.values = NULL; // CID 1421356 (#1 of 1): Explicit null dereferenced (FORWARD_NULL) // 2. var_deref_model: Passing &datum to ovsdb_idl_txn_write_clone,\ // which dereferences null datum.values. ovsdb_idl_txn_write_clone(&row->header_, &ovsrec_open_vswitch_col } And with the following calls: ovsdb_idl_txn_write_clone ovsdb_idl_txn_write__ 6. deref_parm_in_call: Function ovsdb_datum_destroy dereferences datum->values ovsdb_datum_destroy And another possible NULL deref is at ovsdb_datum_equals(). Fix the two by adding additional checks. Signed-off-by: William Tu Reviewed-by: Yifeng Sun --- lib/ovsdb-data.c | 8 ++++++-- lib/ovsdb-idl.c | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c index 4828624f658d..9ce3cdeca28a 100644 --- a/lib/ovsdb-data.c +++ b/lib/ovsdb-data.c @@ -1033,8 +1033,12 @@ free_data(enum ovsdb_atomic_type type, void ovsdb_datum_destroy(struct ovsdb_datum *datum, const struct ovsdb_type *type) { - free_data(type->key.type, datum->keys, datum->n); - free_data(type->value.type, datum->values, datum->n); + if (datum->keys) { + free_data(type->key.type, datum->keys, datum->n); + } + if (datum->values) { + free_data(type->value.type, datum->values, datum->n); + } } /* Swaps the contents of 'a' and 'b', which need not have the same type. */ diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 1535ad7b5197..6614ea1617ef 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -4449,7 +4449,8 @@ ovsdb_idl_txn_write__(const struct ovsdb_idl_row *row_, * transaction only does writes of existing values, without making any real * changes, we will drop the whole transaction later in * ovsdb_idl_txn_commit().) */ - if (write_only && ovsdb_datum_equals(ovsdb_idl_read(row, column), + if (datum->keys && datum->values && + write_only && ovsdb_datum_equals(ovsdb_idl_read(row, column), datum, &column->type)) { goto discard_datum; }