From patchwork Tue Jun 13 18:34:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 1794624 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: legolas.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=20221208 header.b=XfEGrTW1; dkim-atps=neutral Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qgcfz0brmz20QH for ; Wed, 14 Jun 2023 04:35:07 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 274416119C; Tue, 13 Jun 2023 18:35:04 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 274416119C Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=XfEGrTW1 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DchVbecMwuUR; Tue, 13 Jun 2023 18:35:01 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 3A72761142; Tue, 13 Jun 2023 18:35:00 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 3A72761142 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 31B00C0090; Tue, 13 Jun 2023 18:34:58 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 74F44C008C for ; Tue, 13 Jun 2023 18:34:56 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 40038605D5 for ; Tue, 13 Jun 2023 18:34:56 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 40038605D5 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id v1dbz4kwDFxQ for ; Tue, 13 Jun 2023 18:34:55 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 1EB4860F3F Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by smtp3.osuosl.org (Postfix) with ESMTPS id 1EB4860F3F for ; Tue, 13 Jun 2023 18:34:55 +0000 (UTC) Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1b3d800f671so17707965ad.0 for ; Tue, 13 Jun 2023 11:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686681294; x=1689273294; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oqYbUrtzQPwyubKv6gn9y9RI+KNlCUfmCTKf4xs7BNs=; b=XfEGrTW1rzwL7wtaVuufQu0Erhs2kBNDij9mzgNNpbPsg2XFtRh9cYUIkkkOvjiHdj mdyDAIt0I0WUmzGCZpj2IGBc1/GQhd4s4vGogo8nnc1W5Cn0SAZYa1xho5N2Gk9wjNRX jYnJNoJB/DBMvBm3Vum2+5k/c4xV78jH++8LbLzmBie2vpon+hSJK/hQ75QfUVYJA/Qi PAVjAPt9A+5wkkR2QyiSkKO+FHaoaRpfkcxYkZJtWt3mCKlLu6n/p3pChdfaSZJ8Lyi9 xnfwUFzX0StEB8g8dmKSWUt57gMwcH+yBbko1+rCdcmUZyLkAP9cjCNdzO13kobggIHB ip9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686681294; x=1689273294; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oqYbUrtzQPwyubKv6gn9y9RI+KNlCUfmCTKf4xs7BNs=; b=Ex6zEZq/ZlCoIxb24bmi45p2GeAaink9ssP7Auu+VUYrT1mW+tDzoe/lkwHSvqFVDF AOEz8LEJZ3e++0o3y49FwA90wC0BbEQbhp1R/lny2HOBcnTQCz0WwjA7L5HyQqm4h9Ib IW6mDzgL4gKQQ8SB5M+QEsq4Pyqz6rGlAG7DQsSWPoioNSgpGGrdx/MUZjXsjv59SDp6 Oc0dhgSAycKWrPtZT9zRDPYdYbt6xGoLv4ifSxghE5ihatZgbuHvJGQ9ZGORVLty2zqR JroPl7MhbDJe3Fp42DX1POTFlRErRutb0jrmIF8Krev++egpEXS46q33+wnrOnLeT+TM wxtA== X-Gm-Message-State: AC+VfDyUWdA6QiZ4T1PYy3FwpwdwhCKLo9owgRjIneZug6X6moUEeYka L/FQ7VSlfkrlMP1O1GQKo+Tzi7dzN+Iz2Q== X-Google-Smtp-Source: ACHHUZ4BYrzvkWU4z+9xuw2KLYiKdw5l4HDKLVl297kMTwuv2xMOSgunLL4dKkihukwLx3IOTD/g3w== X-Received: by 2002:a17:903:1208:b0:1b0:25d2:6f11 with SMTP id l8-20020a170903120800b001b025d26f11mr11708649plh.17.1686681294282; Tue, 13 Jun 2023 11:34:54 -0700 (PDT) Received: from JRT-PC.lan ([103.252.200.22]) by smtp.gmail.com with ESMTPSA id u3-20020a170902e80300b001b04aee1f99sm10531125plg.228.2023.06.13.11.34.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 11:34:54 -0700 (PDT) From: James Raphael Tiovalen To: dev@openvswitch.org Date: Wed, 14 Jun 2023 02:34:39 +0800 Message-Id: <20230613183443.31540-5-jamestiotio@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230613183443.31540-1-jamestiotio@gmail.com> References: <20230613183443.31540-1-jamestiotio@gmail.com> MIME-Version: 1.0 Cc: James Raphael Tiovalen Subject: [ovs-dev] [PATCH v12 4/8] ovsdb: Assert and check return values of `ovsdb_table_schema_get_column` 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: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This commit adds a few null pointer assertions and checks to some return values of `ovsdb_table_schema_get_column`. If a null pointer is encountered in these blocks, either the assertion will fail or the control flow will now be redirected to alternative paths which will output the appropriate error messages. A few ovsdb-rbac and ovsdb-server tests are also updated to verify the expected warning logs by adding said logs to the ALLOWLIST of the OVSDB_SERVER_SHUTDOWN statements. Signed-off-by: James Raphael Tiovalen Reviewed-by: Simon Horman Acked-by: Eelco Chaudron --- ovsdb/condition.c | 5 ++++- ovsdb/ovsdb-client.c | 7 +++++-- ovsdb/ovsdb-util.c | 6 ++++++ tests/ovsdb-rbac.at | 4 +++- tests/ovsdb-server.at | 8 ++++++-- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/ovsdb/condition.c b/ovsdb/condition.c index 09c89b2a0..5a3eb4e8a 100644 --- a/ovsdb/condition.c +++ b/ovsdb/condition.c @@ -47,7 +47,10 @@ ovsdb_clause_from_json(const struct ovsdb_table_schema *ts, /* Column and arg fields are not being used with boolean functions. * Use dummy values */ - clause->column = ovsdb_table_schema_get_column(ts, "_uuid"); + const struct ovsdb_column *uuid_column = + ovsdb_table_schema_get_column(ts, "_uuid"); + ovs_assert(uuid_column); + clause->column = uuid_column; clause->index = clause->column->index; ovsdb_datum_init_default(&clause->arg, &clause->column->type); return NULL; diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c index bae2c5f04..46484630d 100644 --- a/ovsdb/ovsdb-client.c +++ b/ovsdb/ovsdb-client.c @@ -1232,8 +1232,11 @@ parse_monitor_columns(char *arg, const char *server, const char *database, } free(nodes); - add_column(server, ovsdb_table_schema_get_column(table, "_version"), - columns, columns_json); + const struct ovsdb_column *version_column = + ovsdb_table_schema_get_column(table, "_version"); + + ovs_assert(version_column); + add_column(server, version_column, columns, columns_json); } if (!initial || !insert || !delete || !modify) { diff --git a/ovsdb/ovsdb-util.c b/ovsdb/ovsdb-util.c index 303191dc8..0b9e1df54 100644 --- a/ovsdb/ovsdb-util.c +++ b/ovsdb/ovsdb-util.c @@ -291,9 +291,15 @@ ovsdb_util_write_string_string_column(struct ovsdb_row *row, size_t i; column = ovsdb_table_schema_get_column(row->table->schema, column_name); + if (!column) { + VLOG_WARN("No %s column present in the %s table", + column_name, row->table->schema->name); + goto unwind; + } datum = ovsdb_util_get_datum(row, column_name, OVSDB_TYPE_STRING, OVSDB_TYPE_STRING, UINT_MAX); if (!datum) { +unwind: for (i = 0; i < n; i++) { free(keys[i]); free(values[i]); diff --git a/tests/ovsdb-rbac.at b/tests/ovsdb-rbac.at index 7de3711fb..3172e4bf5 100644 --- a/tests/ovsdb-rbac.at +++ b/tests/ovsdb-rbac.at @@ -371,5 +371,7 @@ cat stdout >> output AT_CHECK([uuidfilt stdout], [0], [[[{"count":1}]] ], [ignore]) -OVSDB_SERVER_SHUTDOWN +OVSDB_SERVER_SHUTDOWN([" + /No status column present in the Connection table/d +"]) AT_CLEANUP diff --git a/tests/ovsdb-server.at b/tests/ovsdb-server.at index b53ab8f52..8ccec80bc 100644 --- a/tests/ovsdb-server.at +++ b/tests/ovsdb-server.at @@ -428,7 +428,9 @@ AT_CHECK( [[[{"rows":[{"managers":"punix:socket1"}]},{"rows":[{"is_connected":false,"target":"punix:socket2"}]}] ]], [ignore]) -OVSDB_SERVER_SHUTDOWN +OVSDB_SERVER_SHUTDOWN([" + /No status column present in the Manager table/d +"]) AT_CLEANUP AT_SETUP([ovsdb-server/add-remote and remove-remote]) @@ -2110,7 +2112,9 @@ AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT \ cat stdout >> output AT_CHECK([uuidfilt output], [0], [[[{"details":"insert operation not allowed when database server is in read only mode","error":"not allowed"}]] ], [ignore]) -OVSDB_SERVER_SHUTDOWN +OVSDB_SERVER_SHUTDOWN([" + /No status column present in the Manager table/d +"]) AT_CLEANUP AT_SETUP([ovsdb-server replication with schema mismatch])