From patchwork Tue Jun 13 18:34:36 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: 1794621 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::138; helo=smtp1.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=e8KrEWKn; dkim-atps=neutral Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (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 4Qgcfs4w0Bz20Vx for ; Wed, 14 Jun 2023 04:35:01 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id BAA8D82310; Tue, 13 Jun 2023 18:34:58 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org BAA8D82310 Authentication-Results: smtp1.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=e8KrEWKn X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KkI6492ZH5oC; Tue, 13 Jun 2023 18:34:56 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 1CE34821D9; Tue, 13 Jun 2023 18:34:55 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 1CE34821D9 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D1206C0093; Tue, 13 Jun 2023 18:34:53 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6DF13C0029 for ; Tue, 13 Jun 2023 18:34:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 3A3AB60F18 for ; Tue, 13 Jun 2023 18:34:52 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 3A3AB60F18 Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=e8KrEWKn 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 4uBjbsINoqYK for ; Tue, 13 Jun 2023 18:34:51 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 3C19C605D5 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by smtp3.osuosl.org (Postfix) with ESMTPS id 3C19C605D5 for ; Tue, 13 Jun 2023 18:34:51 +0000 (UTC) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1b3b3f67ad6so29253285ad.3 for ; Tue, 13 Jun 2023 11:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686681290; x=1689273290; 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=2GNRgPNvHwQMwWJB82FlAA3/ziMBTqTKTpJ7x/B+WLo=; b=e8KrEWKn4021tF1R5HYLlLkCrb8JPppjxBJ7G2tkT+gvjJBP0N+cth3mY5CyUwiJ3w qc4qV9JjJCjJCWMpvktlF5qgfJjCwDKID1Cj0t0ScI/KQN00ib7Cq/sJgI+AqNY6SBhD w32ue8tLs3dWDLFUmnZ6scJFMvHzWmBtKqthUmJvFJQSH3jrYm0BvFc/Ash3tzW2mk5z sEtq+MizSW595bPzb8tynx3zNPOEDKsuwg3VblRhZyzapthiEzprIgd2cj2bcwbUv+we +Nzda3UrDPIvsj/8UJP8y8nL/QhlE79qCEL+YEwJ4oBZubG/MA/OPenYelMCHTHiFjTy Y1Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686681290; x=1689273290; 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=2GNRgPNvHwQMwWJB82FlAA3/ziMBTqTKTpJ7x/B+WLo=; b=Qd+Z0YO9R+jqrrYr3DTsS6wmxi2ZR8q/J3AzVhz9QSC8IyAOpyiOPlxU5/0EbpqF0g IB/WvwFGULz/mR6j5MTzV1Yi0g40DFx8ehAfFAHLsxPvzkkatTEsMKBICORK0jOvtEva wPVFjxSiGVhL6vMJZ3A2X4lT77SoPXAP8lEMYa+c6V9akirCGTuADUyvkahB0sTYr1wl Jpx4/I//Ratxi+yI/9yYg7GoYrDxJOnBAHSIITKmIXJUGL0sVaiC3jXwNEI6KstFXUqj 9duJlFT9Fno0KkToZ14M80hh1J95omdlMFKgsW0FS8c15F9WgJ8skxCf5TQFWJkOGV61 WCHA== X-Gm-Message-State: AC+VfDwVeTgd+YOTfVXOX7Pp/kfVioPK3h5PSW7DbBwViZbcY1JtutPY vrlzDt6fpxMZU4G94flKI1js7/C7yQBFWA== X-Google-Smtp-Source: ACHHUZ7X76S3kZdy9m6PYOh3qVTLOCOsMPidavBKqJHXwE+plqNuWKiu9JIHyNDAJoSPUHdrYcov+Q== X-Received: by 2002:a17:902:8502:b0:1ae:8892:7d27 with SMTP id bj2-20020a170902850200b001ae88927d27mr10058214plb.42.1686681290374; Tue, 13 Jun 2023 11:34:50 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 11:34:50 -0700 (PDT) From: James Raphael Tiovalen To: dev@openvswitch.org Date: Wed, 14 Jun 2023 02:34:36 +0800 Message-Id: <20230613183443.31540-2-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: Simon Horman , James Raphael Tiovalen Subject: [ovs-dev] [PATCH v12 1/8] lib: Add non-null assertions to some return values of `dp_packet_data` 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 some `ovs_assert()` checks to some return values of `dp_packet_data()` to ensure that they are not NULL and to prevent null-pointer dereferences, which might lead to unwanted crashes. We use assertions since it should be impossible for these calls to `dp_packet_data()` to return NULL. Signed-off-by: James Raphael Tiovalen Reviewed-by: Simon Horman --- lib/dp-packet.c | 15 ++++++++++----- lib/netdev-native-tnl.c | 17 +++++++++++------ lib/pcap-file.c | 4 +++- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/dp-packet.c b/lib/dp-packet.c index ae8ab5800..445cb4761 100644 --- a/lib/dp-packet.c +++ b/lib/dp-packet.c @@ -183,9 +183,12 @@ dp_packet_clone_with_headroom(const struct dp_packet *buffer, size_t headroom) struct dp_packet *new_buffer; uint32_t mark; - new_buffer = dp_packet_clone_data_with_headroom(dp_packet_data(buffer), - dp_packet_size(buffer), - headroom); + const void *data_dp = dp_packet_data(buffer); + ovs_assert(data_dp); + + new_buffer = dp_packet_clone_data_with_headroom(data_dp, + dp_packet_size(buffer), + headroom); /* Copy the following fields into the returned buffer: l2_pad_size, * l2_5_ofs, l3_ofs, l4_ofs, cutlen, packet_type and md. */ memcpy(&new_buffer->l2_pad_size, &buffer->l2_pad_size, @@ -322,8 +325,10 @@ dp_packet_shift(struct dp_packet *b, int delta) : true); if (delta != 0) { - char *dst = (char *) dp_packet_data(b) + delta; - memmove(dst, dp_packet_data(b), dp_packet_size(b)); + const void *data_dp = dp_packet_data(b); + ovs_assert(data_dp); + char *dst = (char *) data_dp + delta; + memmove(dst, data_dp, dp_packet_size(b)); dp_packet_set_data(b, dst); } } diff --git a/lib/netdev-native-tnl.c b/lib/netdev-native-tnl.c index c2c6ca559..7781b162d 100644 --- a/lib/netdev-native-tnl.c +++ b/lib/netdev-native-tnl.c @@ -43,6 +43,7 @@ #include "seq.h" #include "unaligned.h" #include "unixctl.h" +#include "util.h" #include "openvswitch/vlog.h" VLOG_DEFINE_THIS_MODULE(native_tnl); @@ -222,12 +223,13 @@ netdev_tnl_calc_udp_csum(struct udp_header *udp, struct dp_packet *packet, { uint32_t csum; - if (netdev_tnl_is_header_ipv6(dp_packet_data(packet))) { - csum = packet_csum_pseudoheader6(netdev_tnl_ipv6_hdr( - dp_packet_data(packet))); + void *data_dp = dp_packet_data(packet); + ovs_assert(data_dp); + + if (netdev_tnl_is_header_ipv6(data_dp)) { + csum = packet_csum_pseudoheader6(netdev_tnl_ipv6_hdr(data_dp)); } else { - csum = packet_csum_pseudoheader(netdev_tnl_ip_hdr( - dp_packet_data(packet))); + csum = packet_csum_pseudoheader(netdev_tnl_ip_hdr(data_dp)); } csum = csum_continue(csum, udp, ip_tot_size); @@ -428,7 +430,10 @@ netdev_gre_pop_header(struct dp_packet *packet) struct flow_tnl *tnl = &md->tunnel; int hlen = sizeof(struct eth_header) + 4; - hlen += netdev_tnl_is_header_ipv6(dp_packet_data(packet)) ? + const void *data_dp = dp_packet_data(packet); + ovs_assert(data_dp); + + hlen += netdev_tnl_is_header_ipv6(data_dp) ? IPV6_HEADER_LEN : IP_HEADER_LEN; pkt_metadata_init_tnl(md); diff --git a/lib/pcap-file.c b/lib/pcap-file.c index 3ed7ea488..9f4e2e1e2 100644 --- a/lib/pcap-file.c +++ b/lib/pcap-file.c @@ -284,6 +284,8 @@ ovs_pcap_write(struct pcap_file *p_file, struct dp_packet *buf) struct timeval tv; ovs_assert(dp_packet_is_eth(buf)); + const void *data_dp = dp_packet_data(buf); + ovs_assert(data_dp); xgettimeofday(&tv); prh.ts_sec = tv.tv_sec; @@ -291,7 +293,7 @@ ovs_pcap_write(struct pcap_file *p_file, struct dp_packet *buf) prh.incl_len = dp_packet_size(buf); prh.orig_len = dp_packet_size(buf); ignore(fwrite(&prh, sizeof prh, 1, p_file->file)); - ignore(fwrite(dp_packet_data(buf), dp_packet_size(buf), 1, p_file->file)); + ignore(fwrite(data_dp, dp_packet_size(buf), 1, p_file->file)); fflush(p_file->file); } From patchwork Tue Jun 13 18:34:37 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: 1794623 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::137; helo=smtp4.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=YZsTaPhV; dkim-atps=neutral Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (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 4Qgcfx076rz20Vx for ; Wed, 14 Jun 2023 04:35:05 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id C190B415BB; Tue, 13 Jun 2023 18:35:00 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org C190B415BB Authentication-Results: smtp4.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=YZsTaPhV X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4uDs-4hckukX; Tue, 13 Jun 2023 18:34:58 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id B32DD409AE; Tue, 13 Jun 2023 18:34:56 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org B32DD409AE Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 868D6C007A; Tue, 13 Jun 2023 18:34:55 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 92727C0097 for ; Tue, 13 Jun 2023 18:34:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 5F5B3405A2 for ; Tue, 13 Jun 2023 18:34:54 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 5F5B3405A2 Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=YZsTaPhV X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id a-bvryD4oiUl for ; Tue, 13 Jun 2023 18:34:52 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 80628404D4 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by smtp2.osuosl.org (Postfix) with ESMTPS id 80628404D4 for ; Tue, 13 Jun 2023 18:34:52 +0000 (UTC) Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1b3c8f454b0so17736185ad.1 for ; Tue, 13 Jun 2023 11:34:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686681292; x=1689273292; 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=7VOniHAGUpJBG8zP168pR17xtJV0AB0QQ9AAHTflB04=; b=YZsTaPhVNuNX+qnuTo6BKBJV1HjKf8MRQ0p4qJZrBhEPe67aS4JkBFB9zUkWe+hEgd g2e3zqpJuZjtyDAHyT/Hye/Gjb+dYs4Vzd1TdOqavDhl/BXWR/k5a1XBPKC7y4RvbGnb gNENkKBkSRSuKM16DxXSPOohDfCYihzsCGbdOx0p8arWXHOh6vU45q5+/FKQtSWDv2OM 5TS0DgdgRi4P7tGfEOJxkGvoyC4wAHcCS1Vr+TETb7hH+h6wTBIblP6mi7nPUxJpIX9H qwfMkZY2tWoinBihKpouVRybzTRGZKq4JMNwUtVmzXsSwxrxRMJrMakDTQd/Hf4Yj6b/ pZaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686681292; x=1689273292; 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=7VOniHAGUpJBG8zP168pR17xtJV0AB0QQ9AAHTflB04=; b=b4/oDhO7ZonccR9uyiyVZAamm1CS8m/gKHhPLUtpYEhigOYCJNvrNvOz1RBYjfgd7f Y6ilj41EoogO6uXbrLGvp0X2jNehLn+acTKDCIWde/IqK54Edl2oTYMonLTgK3EiPPiN bs83QOWeytfgnvUCc0qwP262qqphvyeJsKpWcMIofDLd3HXIz0nIxoMggYHONST6vaqF Dio/dIdFw91tywnzIz46+H1pduPOCbZRcd9gu/pbVtz7xMGa9dgdZTAQaDKqF1H7ztbx sb72yjis0/DPdKDSbi+UWxgnXGCk2gZeuFYLl0llmxtKI/N0jGhwfCIhoXGBaxxeInHb 4WmA== X-Gm-Message-State: AC+VfDzfmk78o5qbvBmPB6Vs1rAxLHqNIUhSXFzlTJz+jf1jpJKzVu27 Rbj0sfi3akb06eiirQpRbgJOBkZUFnEmJA== X-Google-Smtp-Source: ACHHUZ44F++0e9kmWx8Z6sgOx6FOHN3Q6U8zhPo6QuzKj1uOeIKZg5pWC95Ow8DOSajKj2L1rE772g== X-Received: by 2002:a17:902:ea0e:b0:1ad:f407:37d1 with SMTP id s14-20020a170902ea0e00b001adf40737d1mr10594265plg.52.1686681291597; Tue, 13 Jun 2023 11:34:51 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 11:34:51 -0700 (PDT) From: James Raphael Tiovalen To: dev@openvswitch.org Date: Wed, 14 Jun 2023 02:34:37 +0800 Message-Id: <20230613183443.31540-3-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 2/8] lib, ovs-vsctl: Add zero-initializations 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 zero-initializations by changing `SFL_ALLOC` from `malloc` to `xzalloc`, adding a `memset` call to `sflAlloc`, initializing a `pollfd` struct variable with zeroes, and changing some calls to `xmalloc` to `xzalloc`. This is to prevent potential data leaks or undefined behavior from potentially uninitialized variables. Some variables would always be initialized by either the code flow or the compiler. Thus, some of the associated Coverity reports might be false positives. That said, it is still considered best practice to zero-initialize variables upfront just in case to ensure the overall resilience and security of OVS, as long as they do not impact performance-critical code. As a bonus, it would also make static analyzer tools, such as Coverity, happy. Signed-off-by: James Raphael Tiovalen Reviewed-by: Simon Horman --- lib/latch-unix.c | 2 +- lib/sflow_agent.c | 12 ++++++++++-- lib/sflow_api.h | 2 +- utilities/ovs-vsctl.c | 5 ++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/latch-unix.c b/lib/latch-unix.c index f4d10c39a..c62bb024b 100644 --- a/lib/latch-unix.c +++ b/lib/latch-unix.c @@ -71,7 +71,7 @@ latch_set(struct latch *latch) bool latch_is_set(const struct latch *latch) { - struct pollfd pfd; + struct pollfd pfd = {0}; int retval; pfd.fd = latch->fds[0]; diff --git a/lib/sflow_agent.c b/lib/sflow_agent.c index c95f654a5..b15758ae1 100644 --- a/lib/sflow_agent.c +++ b/lib/sflow_agent.c @@ -510,8 +510,16 @@ void sfl_agent_sysError(SFLAgent *agent, char *modName, char *msg) static void * sflAlloc(SFLAgent *agent, size_t bytes) { - if(agent->allocFn) return (*agent->allocFn)(agent->magic, agent, bytes); - else return SFL_ALLOC(bytes); + void *alloc; + if (agent->allocFn) { + alloc = (*agent->allocFn)(agent->magic, agent, bytes); + ovs_assert(alloc); + memset(alloc, 0, bytes); + } else { + alloc = SFL_ALLOC(bytes); + ovs_assert(alloc); + } + return alloc; } static void sflFree(SFLAgent *agent, void *obj) diff --git a/lib/sflow_api.h b/lib/sflow_api.h index a0530b37a..eb23e2acd 100644 --- a/lib/sflow_api.h +++ b/lib/sflow_api.h @@ -337,7 +337,7 @@ void sfl_agent_sysError(SFLAgent *agent, char *modName, char *msg); u_int32_t sfl_receiver_samplePacketsSent(SFLReceiver *receiver); -#define SFL_ALLOC malloc +#define SFL_ALLOC xzalloc #define SFL_FREE free #endif /* SFLOW_API_H */ diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index 2f5ac1a26..b3c75f8ba 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -575,7 +575,7 @@ add_bridge_to_cache(struct vsctl_context *vsctl_ctx, struct ovsrec_bridge *br_cfg, const char *name, struct vsctl_bridge *parent, int vlan) { - struct vsctl_bridge *br = xmalloc(sizeof *br); + struct vsctl_bridge *br = xzalloc(sizeof *br); br->br_cfg = br_cfg; br->name = xstrdup(name); ovs_list_init(&br->ports); @@ -659,7 +659,7 @@ static struct vsctl_port * add_port_to_cache(struct vsctl_context *vsctl_ctx, struct vsctl_bridge *parent, struct ovsrec_port *port_cfg) { - struct vsctl_port *port; + struct vsctl_port *port = xzalloc(sizeof *port); if (port_cfg->tag && *port_cfg->tag >= 0 && *port_cfg->tag <= 4095) { @@ -671,7 +671,6 @@ add_port_to_cache(struct vsctl_context *vsctl_ctx, struct vsctl_bridge *parent, } } - port = xmalloc(sizeof *port); ovs_list_push_back(&parent->ports, &port->ports_node); ovs_list_init(&port->ifaces); port->port_cfg = port_cfg; From patchwork Tue Jun 13 18:34:38 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: 1794622 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=140.211.166.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=Xwp9Wkp3; dkim-atps=neutral Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.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 4Qgcfv1XsMz20Vx for ; Wed, 14 Jun 2023 04:35:03 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id CADE46112C; Tue, 13 Jun 2023 18:35:00 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org CADE46112C 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=Xwp9Wkp3 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 tFXmZ7JMPXkU; Tue, 13 Jun 2023 18:34:59 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 53BE3610FF; Tue, 13 Jun 2023 18:34:58 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 53BE3610FF Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3346FC0092; Tue, 13 Jun 2023 18:34:56 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 417EEC0029 for ; Tue, 13 Jun 2023 18:34:55 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 182D582183 for ; Tue, 13 Jun 2023 18:34:55 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 182D582183 Authentication-Results: smtp1.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=Xwp9Wkp3 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id brgH1j9uDrYI for ; Tue, 13 Jun 2023 18:34:54 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 21633820DC Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by smtp1.osuosl.org (Postfix) with ESMTPS id 21633820DC for ; Tue, 13 Jun 2023 18:34:54 +0000 (UTC) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1b3d8aa2c17so13468005ad.3 for ; Tue, 13 Jun 2023 11:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686681293; x=1689273293; 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=aRi1AE/dD+xltBfFp+HP4yaUtcYQGpi+pNNwXiOgplw=; b=Xwp9Wkp3Es0hla5jxBBAuKzt8r/w/6JUFpYHeaehz2f7fKoTFpVRPxEA5AslWiLpPg 7/PQCA9x19TlfuNibu0GFiv/r1LLHCA/1T1/7PCQbWw2s6UQ3NlWoUpzpd8yMdVambal Funt1RJOBdrvPke7W99AyFca57hoLp5I4bMqRK5ghvEewxE4jn5EaLJqduCQqSxuFoOz zJusziD0V/Z7KtUYZIMsJwPZVj6KTujNEjXx4xOp97l019iY8oV+czffW7b2UQgpRbsp 6SlZEXi9Na0EDkRzmIjWNaBFfa0zPfxVd4dNLpx+wNq16c1S58qA/9UkATm8L876IqvE /e+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686681293; x=1689273293; 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=aRi1AE/dD+xltBfFp+HP4yaUtcYQGpi+pNNwXiOgplw=; b=Ghug+NcGog+P/Xgha/Kvbqq4tm08+/wDMRPIGvi+ZfBuH7YGXOhvolv/T32VgGZKLt e+FiHxHi35C9f2fzyf8V6wUJs81EY0R4aUKd38Eqxx3GpvqfgtQjkeQ6F7Y5btS/Xcpi ISMms/KNLjm54sjXe1Ng3X9brNbuZo2n12br+dC9ZdRdDSXvkSWs7vbi/4Rr7Y+KKGVw z/agpBtZsOEci1PlqvUgciq1HuALYQ3R5MGN4erJS2H/dZ14XVzGxdHnQ0aR7e5PP8yr MTCSXsqhZ4Z3iZN/DvS5sqRPv0vwP2u3o4xqYNGhjtsb4/4kVYKQto/FMcc9xio7KWuH 4fiw== X-Gm-Message-State: AC+VfDy91CsTwsRZp6uzzUD5i46k6iPwauGrzo1XH3AjhP1yE0kOjadv 7nc5R0U0zrjIlpMAcyXfkibwGDtX9erAlQ== X-Google-Smtp-Source: ACHHUZ59fe6P1UZfvNhZ5HaslxAHjFHljfl4mZvD3fPiqqWsc9dPoRNJsIrKvtF9QxeEVH56NAyPaA== X-Received: by 2002:a17:902:c20b:b0:1af:d9d2:a234 with SMTP id 11-20020a170902c20b00b001afd9d2a234mr9570061pll.3.1686681293107; Tue, 13 Jun 2023 11:34:53 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 11:34:52 -0700 (PDT) From: James Raphael Tiovalen To: dev@openvswitch.org Date: Wed, 14 Jun 2023 02:34:38 +0800 Message-Id: <20230613183443.31540-4-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: Simon Horman , James Raphael Tiovalen Subject: [ovs-dev] [PATCH v12 3/8] shash, simap, smap: Add assertions to `*_count` functions 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 assertions in the functions `shash_count`, `simap_count`, and `smap_count` to ensure that the corresponding input struct pointer is not NULL. This ensures that if the return values of `shash_sort`, `simap_sort`, or `smap_sort` are NULL, then the following for loops would not attempt to access the pointer, which might result in segmentation faults or undefined behavior. Signed-off-by: James Raphael Tiovalen Reviewed-by: Simon Horman Acked-by: Eelco Chaudron --- lib/shash.c | 2 ++ lib/simap.c | 2 ++ lib/smap.c | 1 + 3 files changed, 5 insertions(+) diff --git a/lib/shash.c b/lib/shash.c index a7b2c6458..2bfc8eb50 100644 --- a/lib/shash.c +++ b/lib/shash.c @@ -17,6 +17,7 @@ #include #include "openvswitch/shash.h" #include "hash.h" +#include "util.h" static struct shash_node *shash_find__(const struct shash *, const char *name, size_t name_len, @@ -100,6 +101,7 @@ shash_is_empty(const struct shash *shash) size_t shash_count(const struct shash *shash) { + ovs_assert(shash); return hmap_count(&shash->map); } diff --git a/lib/simap.c b/lib/simap.c index 0ee08d74d..1c01d4ebe 100644 --- a/lib/simap.c +++ b/lib/simap.c @@ -17,6 +17,7 @@ #include #include "simap.h" #include "hash.h" +#include "util.h" static size_t hash_name(const char *, size_t length); static struct simap_node *simap_find__(const struct simap *, @@ -84,6 +85,7 @@ simap_is_empty(const struct simap *simap) size_t simap_count(const struct simap *simap) { + ovs_assert(simap); return hmap_count(&simap->map); } diff --git a/lib/smap.c b/lib/smap.c index 47fb34502..122adca27 100644 --- a/lib/smap.c +++ b/lib/smap.c @@ -300,6 +300,7 @@ smap_is_empty(const struct smap *smap) size_t smap_count(const struct smap *smap) { + ovs_assert(smap); return hmap_count(&smap->map); } 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]) From patchwork Tue Jun 13 18:34:40 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: 1794625 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=140.211.166.138; helo=smtp1.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=WBw2Qqjt; dkim-atps=neutral Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 4Qgcfz4lcFz20XW for ; Wed, 14 Jun 2023 04:35:07 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 4AC5182330; Tue, 13 Jun 2023 18:35:05 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 4AC5182330 Authentication-Results: smtp1.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=WBw2Qqjt X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eI-6M0ECFSQa; Tue, 13 Jun 2023 18:35:03 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 734C982893; Tue, 13 Jun 2023 18:35:02 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 734C982893 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4C06BC009A; Tue, 13 Jun 2023 18:34:59 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id D7BC4C008C for ; Tue, 13 Jun 2023 18:34:57 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id A497182089 for ; Tue, 13 Jun 2023 18:34:57 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org A497182089 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eH7Mea5g8CBt for ; Tue, 13 Jun 2023 18:34:56 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org B520C82269 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by smtp1.osuosl.org (Postfix) with ESMTPS id B520C82269 for ; Tue, 13 Jun 2023 18:34:56 +0000 (UTC) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1b3a6469623so21475875ad.3 for ; Tue, 13 Jun 2023 11:34:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686681295; x=1689273295; 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=moW7cNpRfuaXoKqagJrAbwWUPxBijx+TwIy6Fw+x5n8=; b=WBw2QqjtYOUjSCGHME5MLY3KYDj3xCK5RiBIrNqzhZALihf+LG4QJdEt6W9Bqr3GL4 z1o8maBiN8+7LjFxEthkOySx1XzVUYyeGIST4x93WqdF5TJXzWIjVv/68VNz4K5wnQmk IR7A5SLWp6GoKZWJYRTT6TfQB+teMQjvyOoxQUJhm816KZnd5bmKvA/s+BTa4mwNC2dz HKR2dgweqCMxWAZ0UtoMhFYgqcJqdiwulboGI3q8hgyhQWmPwxaIkC+Hmyl5HdLfiH4D yS0jg+xtu8mqJvwy3ofGmN/8LPpu8sotqXyZ54hOjEnZP26pbS21ovPFr9wW3bvMIsgH wEFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686681295; x=1689273295; 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=moW7cNpRfuaXoKqagJrAbwWUPxBijx+TwIy6Fw+x5n8=; b=hFSUOCM01f4pYPI5f+C9W0XU5kbqerm48sWeT9cyVNIwNOtgKBy9Z0u3WEAaTvbbPY /UIdKQ3fyh1Tiy7yKjLuhYJoriKzmRKF8JLYFauj7u4oA4tHU74L/76yzGvBM3NZzO03 9bUzKgEA+MAgjiaxY3zH8UFaQ72oLEzZQn+ZQCa6vuNqBBfHYb7oESjLSlkhB0m0gnXP L8xjgfg+NZnUpqxJ/+tcBDE+ZyQbBi/J0ZFlgCg1lnQlw9DVmxKaAEIgnXJnMMH2jj6+ Qlk9nLXLQzZcR4qp8dwqMrDMK0SHBV6QgvYpidbZBJI+Eo8CJD4JsevSL9SmaDepOxfw tyTA== X-Gm-Message-State: AC+VfDw8rXkcjDS3oTF9ehsIu+c/WUg9vnfbKHGCvsEktofz7hHioMDA tnX6qVvR5If1AzwK5W/3koGR7FHw6ZHUpQ== X-Google-Smtp-Source: ACHHUZ5zEF8mwbapxH6JyoxhaI5C1dpmFC8u5gapd0bDD0RNfTBhR0YomM6B9hD8ltvK3bJkJPDWKQ== X-Received: by 2002:a17:903:124d:b0:1b1:b2fa:1903 with SMTP id u13-20020a170903124d00b001b1b2fa1903mr10964571plh.41.1686681295629; Tue, 13 Jun 2023 11:34:55 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 11:34:55 -0700 (PDT) From: James Raphael Tiovalen To: dev@openvswitch.org Date: Wed, 14 Jun 2023 02:34:40 +0800 Message-Id: <20230613183443.31540-6-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: Simon Horman , James Raphael Tiovalen Subject: [ovs-dev] [PATCH v12 5/8] file, monitor: Add null pointer assertions for old and new ovsdb_rows 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 non-null pointer assertions in some code that performs some decisions based on old and new input ovsdb_rows. Signed-off-by: James Raphael Tiovalen Reviewed-by: Simon Horman Acked-by: Eelco Chaudron --- ovsdb/file.c | 2 ++ ovsdb/monitor.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ovsdb/file.c b/ovsdb/file.c index 2d887e53e..b1d386e76 100644 --- a/ovsdb/file.c +++ b/ovsdb/file.c @@ -522,7 +522,9 @@ ovsdb_file_txn_add_row(struct ovsdb_file_txn *ftxn, } if (row) { + ovs_assert(new || old); struct ovsdb_table *table = new ? new->table : old->table; + ovs_assert(table); char uuid[UUID_LEN + 1]; if (table != ftxn->table) { diff --git a/ovsdb/monitor.c b/ovsdb/monitor.c index 4afaa89f4..c32af7b02 100644 --- a/ovsdb/monitor.c +++ b/ovsdb/monitor.c @@ -1372,8 +1372,10 @@ ovsdb_monitor_changes_update(const struct ovsdb_row *old, const struct ovsdb_monitor_table *mt, struct ovsdb_monitor_change_set_for_table *mcst) { + ovs_assert(new || old); const struct uuid *uuid = ovsdb_row_get_uuid(new ? new : old); - struct ovsdb_monitor_row *change; + ovs_assert(uuid); + struct ovsdb_monitor_row *change = NULL; change = ovsdb_monitor_changes_row_find(mcst, uuid); if (!change) { From patchwork Tue Jun 13 18:34:41 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: 1794626 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=P5SEiX21; 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 4Qgcg34DF7z20Wq for ; Wed, 14 Jun 2023 04:35:11 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 8EE4D611C8; Tue, 13 Jun 2023 18:35:09 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 8EE4D611C8 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=P5SEiX21 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 erfYEOiZvz3l; Tue, 13 Jun 2023 18:35:08 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 5BC99611A1; Tue, 13 Jun 2023 18:35:04 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 5BC99611A1 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 196D1C008D; Tue, 13 Jun 2023 18:35:01 +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 2C211C008E for ; Tue, 13 Jun 2023 18:35:00 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 03A3561142 for ; Tue, 13 Jun 2023 18:35:00 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 03A3561142 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 6JkdPsdx5fpF for ; Tue, 13 Jun 2023 18:34:58 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org D6B8A60F18 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by smtp3.osuosl.org (Postfix) with ESMTPS id D6B8A60F18 for ; Tue, 13 Jun 2023 18:34:57 +0000 (UTC) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1b3b3f67ad6so29254145ad.3 for ; Tue, 13 Jun 2023 11:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686681297; x=1689273297; 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=90+H2Fj8tbaOnY9UyUQZKaWVzjBOTUXw143dC3sCxPg=; b=P5SEiX21U+kOMQY2abnVchT/W12pR/s8yYmfYkaxMG20fZBra9gufyvimjdcGwqQrB J3jcol1/cPG+7sPy+IC9ob4NzhgmoWJI36u3egDSjZryYhSGOx/KZVBYyy4JgZT76dLJ UZ0QcBiAppHZvXJePAVBbr7UqXAoIubzh0WZFjZRfdLVjqZkbOvvg1DDTXcTETGnUGBF 4oLPCJVIHp+3LPlJdBdxK+Siw7YfbyLXBxno2K7TMYVMkwFvfOEgQJlmxNwUsniyz2At c3iE/V+ssceRSuSU92BXnKmI59SElvdmN46dlWFxTAbSayZLP/dvS7IwTyACMUGdWo3B mO/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686681297; x=1689273297; 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=90+H2Fj8tbaOnY9UyUQZKaWVzjBOTUXw143dC3sCxPg=; b=lTWTd7n60Tv/7ut9B4aTxOzx+ChCXgLS4HpRdiXyU55ntWZ5GO5wQXN9iiY0+rMcd3 U0nH5UOFGla5W6mGfqBTTIIp3TQ2wVO5mH2EtO4UircLxqFugdDMPpTKhV9kBHsk1kNE 4XMqcKqJWlHjrouaBaKAtn09rZ9VhiTlD22NY6yfgmDLWx/9O2tCP0bZtyRYrUcQlAkn 80AbSkQgDtg3pMOM9j1NPef634c1N5VArT8xvxRFTyLlyjquxkV9QldT3FqU6sHyMMei 6yZlmzqOiKAaQoPg3ECOX2o/CHDv02jOZHFXEeWiKuZ4mhKECFAhZnynnqtvClevb4xx Mzrg== X-Gm-Message-State: AC+VfDxl/7RQWLJTma0ZZXjEzGNaBQZHr8Q4pfdeQ6v3yN7uq2kFQVBY S42t8G527AxVuY/oMcT+2E9FODV/LXl01Q== X-Google-Smtp-Source: ACHHUZ5vTXQ/EosV4Jw0jBGeFIS2rD5CpKEa6wT+za2yLKkh0pTpzAOhE+TP7mIrkn42417X5qfX1A== X-Received: by 2002:a17:902:db09:b0:1b3:d357:5ea6 with SMTP id m9-20020a170902db0900b001b3d3575ea6mr5159045plx.53.1686681297022; Tue, 13 Jun 2023 11:34:57 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 11:34:56 -0700 (PDT) From: James Raphael Tiovalen To: dev@openvswitch.org Date: Wed, 14 Jun 2023 02:34:41 +0800 Message-Id: <20230613183443.31540-7-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: Simon Horman , James Raphael Tiovalen Subject: [ovs-dev] [PATCH v12 6/8] ovs-vsctl: Fix crash when routing is enabled 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" In the case where routing is enabled, the bridge member of the `vsctl_port` structs is not populated. This can cause a crash if we attempt to access it. This patch fixes the crash by checking if the bridge member is valid before attempting to access it. In the `check_conflicts` function, we print both the port name and the bridge name if routing is disabled and we only print the port name if routing is enabled. Signed-off-by: James Raphael Tiovalen Reviewed-by: Simon Horman Acked-by: Eelco Chaudron --- utilities/ovs-vsctl.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index b3c75f8ba..f55c2965a 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -888,14 +888,23 @@ check_conflicts(struct vsctl_context *vsctl_ctx, const char *name, port = shash_find_data(&vsctl_ctx->ports, name); if (port) { - ctl_fatal("%s because a port named %s already exists on " - "bridge %s", msg, name, port->bridge->name); + if (port->bridge) { + ctl_fatal("%s because a port named %s already exists on " + "bridge %s", msg, name, port->bridge->name); + } else { + ctl_fatal("%s because a port named %s already exists", msg, name); + } } iface = shash_find_data(&vsctl_ctx->ifaces, name); if (iface) { - ctl_fatal("%s because an interface named %s already exists " - "on bridge %s", msg, name, iface->port->bridge->name); + if (iface->port->bridge) { + ctl_fatal("%s because an interface named %s already exists " + "on bridge %s", msg, name, iface->port->bridge->name); + } else { + ctl_fatal("%s because an interface named %s already exists", msg, + name); + } } free(msg); @@ -935,7 +944,7 @@ find_port(struct vsctl_context *vsctl_ctx, const char *name, bool must_exist) ovs_assert(vsctl_ctx->cache_valid); port = shash_find_data(&vsctl_ctx->ports, name); - if (port && !strcmp(name, port->bridge->name)) { + if (port && port->bridge && !strcmp(name, port->bridge->name)) { port = NULL; } if (must_exist && !port) { @@ -953,7 +962,8 @@ find_iface(struct vsctl_context *vsctl_ctx, const char *name, bool must_exist) ovs_assert(vsctl_ctx->cache_valid); iface = shash_find_data(&vsctl_ctx->ifaces, name); - if (iface && !strcmp(name, iface->port->bridge->name)) { + if (iface && iface->port->bridge && + !strcmp(name, iface->port->bridge->name)) { iface = NULL; } if (must_exist && !iface) { From patchwork Tue Jun 13 18:34:42 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: 1794627 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=140.211.166.133; helo=smtp2.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=ifybZm/T; dkim-atps=neutral Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (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 4Qgcg452CLz20Wq for ; Wed, 14 Jun 2023 04:35:12 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 8519641770; Tue, 13 Jun 2023 18:35:10 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 8519641770 Authentication-Results: smtp2.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=ifybZm/T X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6JCuT2sGGRX5; Tue, 13 Jun 2023 18:35:07 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id EEC7741754; Tue, 13 Jun 2023 18:35:05 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org EEC7741754 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 01184C007A; Tue, 13 Jun 2023 18:35:03 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2B3ADC0094 for ; Tue, 13 Jun 2023 18:35:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 1B992409AE for ; Tue, 13 Jun 2023 18:35:01 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 1B992409AE Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=ifybZm/T X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id H5Iig_MAM8R6 for ; Tue, 13 Jun 2023 18:34:59 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 8916A410CB Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by smtp4.osuosl.org (Postfix) with ESMTPS id 8916A410CB for ; Tue, 13 Jun 2023 18:34:59 +0000 (UTC) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1b3ce6607cbso21507975ad.2 for ; Tue, 13 Jun 2023 11:34:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686681298; x=1689273298; 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=5Iuq67S208L80EUP0YjU7UaC2OBI6Pmn94GLO/Dn2TY=; b=ifybZm/TQkdDyyhEhMpmzumTGc4JqSJ5QDnJPnbeshHoitDimE/LnJPfGCfMCrq+pp izXsqJFtMqDhUUoZENTnRgf6AgYtJZpOUFOAKsfuGhUoeC5vehfeLAKbdEdvMm23Jv/+ ym32WirhQuu+VjccZFfXAWPdHpnxYsp0YDxHNsR6EhxzYxyaqby1yY+wiZkExvHGxqem t51LN292VZQzeetFpTQ12Qznfh6R1FbkWo7qDv7eGMRWxGULp1car+e3jlmuV4R9TZ/+ riNPrQqVifBA10y0roNQGrttbNpFJEo3XWjB+m7ejAyy3wnVtYKySHj47E2phbbF+oOR aNcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686681298; x=1689273298; 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=5Iuq67S208L80EUP0YjU7UaC2OBI6Pmn94GLO/Dn2TY=; b=kXguq/QjxdED9efFq/nj+REplyxOrO6J9xog4V13jQ8BaxLjv3JLKZHgsLFa8MqrfS MMyR1lVe7A79tJwlA7jUf6fCxTuHU+8o/SAAeStr+DrDrdoWOf52PiGRk8FCe/45iVkM /UW3vJX1dcblVku/6nTM2ZHQlB9q5IiU6hKDzShEjxbKREL8wPlhNGJZxbek/or/TYdm wDv56BxGV2LVTrz/Usv38Pd5JtgzRaxlNU3CritM9rtfFb+DmgOrXGt/Y6lZ50w3RVRD u0gURC/mfcLdakzAwiFFr0hUbX9TT3iHS2mgmr3qbYze4xZ8WXJoXgXVusvYdL0K6609 oEuA== X-Gm-Message-State: AC+VfDwajvlFtHRcFfrkuIsZnmSj9QstFOED2eG/KQsrJ1wmSLLjTazE IbYhX+IVB8RL/a1sMWYry/rKqC60vVwAyQ== X-Google-Smtp-Source: ACHHUZ6e4/lg9QomHTaHJlrQ1+avBCBHRkrWxHFr5mVUGVkUD6rUb6QEHtpL8puMOji3JB6jukfrVg== X-Received: by 2002:a17:903:283:b0:1b2:28ca:d38 with SMTP id j3-20020a170903028300b001b228ca0d38mr12303715plr.10.1686681298602; Tue, 13 Jun 2023 11:34:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 11:34:58 -0700 (PDT) From: James Raphael Tiovalen To: dev@openvswitch.org Date: Wed, 14 Jun 2023 02:34:42 +0800 Message-Id: <20230613183443.31540-8-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: Simon Horman , James Raphael Tiovalen Subject: [ovs-dev] [PATCH v12 7/8] lib, ovsdb: Add various null pointer checks 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 various null pointer checks to some files in the `lib` and the `ovsdb` directories to fix several Coverity defects. These changes are grouped together as they perform similar checks, returning early or skipping some action if a null pointer is encountered. Signed-off-by: James Raphael Tiovalen Reviewed-by: Simon Horman --- lib/dp-packet.c | 8 ++++---- lib/shash.c | 7 ++++++- ovsdb/jsonrpc-server.c | 2 +- ovsdb/monitor.c | 7 ++++++- ovsdb/ovsdb-client.c | 7 ++++++- ovsdb/row.c | 4 +++- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/dp-packet.c b/lib/dp-packet.c index 445cb4761..ca29b1f90 100644 --- a/lib/dp-packet.c +++ b/lib/dp-packet.c @@ -353,7 +353,7 @@ void * dp_packet_put_zeros(struct dp_packet *b, size_t size) { void *dst = dp_packet_put_uninit(b, size); - memset(dst, 0, size); + nullable_memset(dst, 0, size); return dst; } @@ -364,7 +364,7 @@ void * dp_packet_put(struct dp_packet *b, const void *p, size_t size) { void *dst = dp_packet_put_uninit(b, size); - memcpy(dst, p, size); + nullable_memcpy(dst, p, size); return dst; } @@ -436,7 +436,7 @@ void * dp_packet_push_zeros(struct dp_packet *b, size_t size) { void *dst = dp_packet_push_uninit(b, size); - memset(dst, 0, size); + nullable_memset(dst, 0, size); return dst; } @@ -447,7 +447,7 @@ void * dp_packet_push(struct dp_packet *b, const void *p, size_t size) { void *dst = dp_packet_push_uninit(b, size); - memcpy(dst, p, size); + nullable_memcpy(dst, p, size); return dst; } diff --git a/lib/shash.c b/lib/shash.c index 2bfc8eb50..b72b5bf27 100644 --- a/lib/shash.c +++ b/lib/shash.c @@ -205,8 +205,13 @@ shash_delete(struct shash *sh, struct shash_node *node) char * shash_steal(struct shash *sh, struct shash_node *node) { - char *name = node->name; + char *name; + if (!node) { + return NULL; + } + + name = node->name; hmap_remove(&sh->map, &node->node); free(node); return name; diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c index 17868f5b7..5361b3c76 100644 --- a/ovsdb/jsonrpc-server.c +++ b/ovsdb/jsonrpc-server.c @@ -1038,7 +1038,7 @@ ovsdb_jsonrpc_session_got_request(struct ovsdb_jsonrpc_session *s, request->id); } else if (!strcmp(request->method, "get_schema")) { struct ovsdb *db = ovsdb_jsonrpc_lookup_db(s, request, &reply); - if (!reply) { + if (db && !reply) { reply = jsonrpc_create_reply(ovsdb_schema_to_json(db->schema), request->id); } diff --git a/ovsdb/monitor.c b/ovsdb/monitor.c index c32af7b02..b560b0745 100644 --- a/ovsdb/monitor.c +++ b/ovsdb/monitor.c @@ -483,7 +483,9 @@ ovsdb_monitor_add_column(struct ovsdb_monitor *dbmon, struct ovsdb_monitor_column *c; mt = shash_find_data(&dbmon->tables, table->schema->name); - + if (!mt) { + return NULL; + } /* Check for column duplication. Return duplicated column name. */ if (mt->columns_index_map[column->index] != -1) { return column->name; @@ -810,6 +812,9 @@ ovsdb_monitor_table_condition_update( struct ovsdb_monitor_table_condition *mtc = shash_find_data(&condition->tables, table->schema->name); + if (!mtc) { + return NULL; + } struct ovsdb_error *error; struct ovsdb_condition cond = OVSDB_CONDITION_INITIALIZER(&cond); diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c index 46484630d..2b12907b6 100644 --- a/ovsdb/ovsdb-client.c +++ b/ovsdb/ovsdb-client.c @@ -1873,6 +1873,10 @@ do_dump(struct jsonrpc *rpc, const char *database, n_tables = shash_count(&schema->tables); } + if (!tables) { + goto end; + } + /* Construct transaction to retrieve entire database. */ transaction = json_array_create_1(json_string_create(database)); for (i = 0; i < n_tables; i++) { @@ -1932,8 +1936,9 @@ do_dump(struct jsonrpc *rpc, const char *database, } jsonrpc_msg_destroy(reply); - shash_destroy(&custom_columns); free(tables); +end: + shash_destroy(&custom_columns); ovsdb_schema_destroy(schema); } diff --git a/ovsdb/row.c b/ovsdb/row.c index d7bfbdd36..9f87c832a 100644 --- a/ovsdb/row.c +++ b/ovsdb/row.c @@ -399,7 +399,9 @@ ovsdb_row_set_add_row(struct ovsdb_row_set *set, const struct ovsdb_row *row) set->rows = x2nrealloc(set->rows, &set->allocated_rows, sizeof *set->rows); } - set->rows[set->n_rows++] = row; + if (set->rows) { + set->rows[set->n_rows++] = row; + } } struct json * From patchwork Tue Jun 13 18:34:43 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: 1794628 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::138; helo=smtp1.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=q+1e8DJh; dkim-atps=neutral Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (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 4QgcgP2thpz20Wq for ; Wed, 14 Jun 2023 04:35:29 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id CEF0D822E9; Tue, 13 Jun 2023 18:35:26 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org CEF0D822E9 Authentication-Results: smtp1.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=q+1e8DJh X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ePnFcP2cEug9; Tue, 13 Jun 2023 18:35:21 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 5E54C83065; Tue, 13 Jun 2023 18:35:13 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 5E54C83065 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0B9B0C007A; Tue, 13 Jun 2023 18:35:13 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1935CC0087 for ; Tue, 13 Jun 2023 18:35:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id EA4C84173A for ; Tue, 13 Jun 2023 18:35:02 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org EA4C84173A Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=q+1e8DJh X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wA01LIarL4KU for ; Tue, 13 Jun 2023 18:35:01 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 0EEC2416FF Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by smtp2.osuosl.org (Postfix) with ESMTPS id 0EEC2416FF for ; Tue, 13 Jun 2023 18:35:00 +0000 (UTC) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1b3f66dda65so5398265ad.1 for ; Tue, 13 Jun 2023 11:35:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686681300; x=1689273300; 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=SVjLfM1Pd+KWLxhgBl6VJ1NCT4b9MgnDX4AhGCJT0Ws=; b=q+1e8DJhOcKgaEMXnesf1pMvCvGW8kIRfOyV8VkVLg1h7ibygulooS7KBcvxsFI5NN PvBlz0lev6HvYQpdQDt4xYw3Kt0BMQwTLzZUiphmBYcXftYt+VGS59oKXk/Jkn7WYG+7 /YmxNk+GamtiSdbdX0NNmDKvoiJTuUbnWWO9khewb+WBGd1WXVJ/oEucXv9eNPLp+uEa MUuyAphfpC0P9angOp92QeHG8ZzYUdgjRUv8Z8pbE21xBAXxaGvFHMP2a0pKx0QbHbtN xHks5IQvzfGls3HDKR0Dv1OJ3uQBV4fFfWfBoF1U3z3O7BX40k+w3Cn2MdnqIItJhVEM EW5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686681300; x=1689273300; 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=SVjLfM1Pd+KWLxhgBl6VJ1NCT4b9MgnDX4AhGCJT0Ws=; b=VTtdCxPyBwGkClYE8nDVrqqqWHpPs199uwVLguZh5pmXNS7EkhTpS36LDPfUovoiFW hiwGUGq2cmaz3XADCB8PH7kYJXwXOcLrWOM3MNr9uotC1QHoot8XK/U+iTAyrsXKyWM7 wi765DpNR0GMGhbhfvwlKt3yC5MVmHnOGyOMSQpEe+oV69nC9PrklA1o9Q5/ExjI59JD /8lFHFVTs2kUzIUdqfiLHfhhYZMuqfElA6WR/RmnqrrfnCK3qPcDV/K6Srwu0OUPw39z VhQS3/gUMZYmhPTRN421cPmjxCW+9zLIxmFjcSg9XMuBC+LG44PUSYuXHWAATb8X96fK 40vw== X-Gm-Message-State: AC+VfDxBWy0K3vFc28Y6wnGrLn1Md/6mx1iHM9qIfhPxoTBzUI1aYnNt doonyT3kgvl/MSGDTNItf2ptPYjtxyjbMg== X-Google-Smtp-Source: ACHHUZ53Fn/h4OnBLMircWP2rbSefqlv5Yim9+KacSGfSSv8oUBC8GJSrCAqlCnJmtEFP7n8UeA1Kw== X-Received: by 2002:a17:902:db0f:b0:1af:981b:eeff with SMTP id m15-20020a170902db0f00b001af981beeffmr12096607plx.64.1686681299946; Tue, 13 Jun 2023 11:34:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 11:34:59 -0700 (PDT) From: James Raphael Tiovalen To: dev@openvswitch.org Date: Wed, 14 Jun 2023 02:34:43 +0800 Message-Id: <20230613183443.31540-9-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: Simon Horman , James Raphael Tiovalen Subject: [ovs-dev] [PATCH v12 8/8] treewide: Add `ovs_assert` to check for null pointers 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 patch adds an assortment of `ovs_assert` statements to check for null pointers. We use assertions since it should be impossible for any of these pointers to be NULL. Signed-off-by: James Raphael Tiovalen Reviewed-by: Simon Horman --- lib/dp-packet.c | 1 + lib/dpctl.c | 4 ++++ lib/odp-execute.c | 4 ++++ lib/rtnetlink.c | 4 ++-- lib/shash.c | 2 +- lib/sset.c | 2 ++ ovsdb/jsonrpc-server.c | 4 ++++ ovsdb/monitor.c | 3 +++ ovsdb/ovsdb-server.c | 2 ++ ovsdb/ovsdb.c | 8 +++++++- ovsdb/query.c | 2 ++ ovsdb/transaction.c | 2 ++ utilities/ovs-vsctl.c | 3 +++ vtep/vtep-ctl.c | 5 ++++- 14 files changed, 41 insertions(+), 5 deletions(-) diff --git a/lib/dp-packet.c b/lib/dp-packet.c index ca29b1f90..059db48ba 100644 --- a/lib/dp-packet.c +++ b/lib/dp-packet.c @@ -171,6 +171,7 @@ dp_packet_new_with_headroom(size_t size, size_t headroom) struct dp_packet * dp_packet_clone(const struct dp_packet *buffer) { + ovs_assert(buffer); return dp_packet_clone_with_headroom(buffer, 0); } diff --git a/lib/dpctl.c b/lib/dpctl.c index 15950bd50..51cd6c88c 100644 --- a/lib/dpctl.c +++ b/lib/dpctl.c @@ -336,6 +336,8 @@ dpctl_add_if(int argc OVS_UNUSED, const char *argv[], value = ""; } + ovs_assert(key); + if (!strcmp(key, "type")) { type = value; } else if (!strcmp(key, "port_no")) { @@ -454,6 +456,8 @@ dpctl_set_if(int argc, const char *argv[], struct dpctl_params *dpctl_p) value = ""; } + ovs_assert(key); + if (!strcmp(key, "type")) { if (strcmp(value, type)) { dpctl_error(dpctl_p, 0, diff --git a/lib/odp-execute.c b/lib/odp-execute.c index 5cf6fbec0..44b2cd360 100644 --- a/lib/odp-execute.c +++ b/lib/odp-execute.c @@ -147,6 +147,8 @@ odp_set_ipv4(struct dp_packet *packet, const struct ovs_key_ipv4 *key, uint8_t new_tos; uint8_t new_ttl; + ovs_assert(nh); + if (mask->ipv4_src) { ip_src_nh = get_16aligned_be32(&nh->ip_src); new_ip_src = key->ipv4_src | (ip_src_nh & ~mask->ipv4_src); @@ -276,6 +278,8 @@ set_arp(struct dp_packet *packet, const struct ovs_key_arp *key, { struct arp_eth_header *arp = dp_packet_l3(packet); + ovs_assert(arp); + if (!mask) { arp->ar_op = key->arp_op; arp->ar_sha = key->arp_sha; diff --git a/lib/rtnetlink.c b/lib/rtnetlink.c index f67352603..37078d00e 100644 --- a/lib/rtnetlink.c +++ b/lib/rtnetlink.c @@ -112,7 +112,7 @@ rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change) if (parsed) { const struct ifinfomsg *ifinfo; - ifinfo = ofpbuf_at(buf, NLMSG_HDRLEN, sizeof *ifinfo); + ifinfo = ofpbuf_at_assert(buf, NLMSG_HDRLEN, sizeof *ifinfo); /* Wireless events can be spammy and cause a * lot of unnecessary churn and CPU load in @@ -175,7 +175,7 @@ rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change) if (parsed) { const struct ifaddrmsg *ifaddr; - ifaddr = ofpbuf_at(buf, NLMSG_HDRLEN, sizeof *ifaddr); + ifaddr = ofpbuf_at_assert(buf, NLMSG_HDRLEN, sizeof *ifaddr); change->nlmsg_type = nlmsg->nlmsg_type; change->if_index = ifaddr->ifa_index; diff --git a/lib/shash.c b/lib/shash.c index b72b5bf27..c712b3769 100644 --- a/lib/shash.c +++ b/lib/shash.c @@ -270,7 +270,7 @@ void * shash_find_and_delete_assert(struct shash *sh, const char *name) { void *data = shash_find_and_delete(sh, name); - ovs_assert(data != NULL); + ovs_assert(data); return data; } diff --git a/lib/sset.c b/lib/sset.c index aa1790020..afdc4392c 100644 --- a/lib/sset.c +++ b/lib/sset.c @@ -20,6 +20,7 @@ #include "openvswitch/dynamic-string.h" #include "hash.h" +#include "util.h" static uint32_t hash_name__(const char *name, size_t length) @@ -261,6 +262,7 @@ char * sset_pop(struct sset *set) { const char *name = SSET_FIRST(set); + ovs_assert(name); char *copy = xstrdup(name); sset_delete(set, SSET_NODE_FROM_NAME(name)); return copy; diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c index 5361b3c76..a3ca48a7b 100644 --- a/ovsdb/jsonrpc-server.c +++ b/ovsdb/jsonrpc-server.c @@ -1131,6 +1131,8 @@ static void ovsdb_jsonrpc_trigger_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db, struct jsonrpc_msg *request) { + ovs_assert(db); + /* Check for duplicate ID. */ size_t hash = json_hash(request->id, 0); struct ovsdb_jsonrpc_trigger *t @@ -1391,6 +1393,8 @@ ovsdb_jsonrpc_monitor_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db, enum ovsdb_monitor_version version, const struct json *request_id) { + ovs_assert(db); + struct ovsdb_jsonrpc_monitor *m = NULL; struct ovsdb_monitor *dbmon = NULL; struct json *monitor_id, *monitor_requests; diff --git a/ovsdb/monitor.c b/ovsdb/monitor.c index b560b0745..2180f9e2d 100644 --- a/ovsdb/monitor.c +++ b/ovsdb/monitor.c @@ -1327,6 +1327,7 @@ ovsdb_monitor_table_add_select(struct ovsdb_monitor *dbmon, struct ovsdb_monitor_table * mt; mt = shash_find_data(&dbmon->tables, table->schema->name); + ovs_assert(mt); mt->select |= select; } @@ -1710,6 +1711,8 @@ ovsdb_monitor_hash(const struct ovsdb_monitor *dbmon, size_t basis) for (i = 0; i < n; i++) { struct ovsdb_monitor_table *mt = nodes[i]->data; + ovs_assert(mt); + basis = hash_pointer(mt->table, basis); basis = hash_3words(mt->select, mt->n_columns, basis); diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index 9bad0c8dd..87da41f17 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -2229,6 +2229,8 @@ save_config(struct server_config *config) static void sset_from_json(struct sset *sset, const struct json *array) { + ovs_assert(array); + size_t i; sset_clear(sset); diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c index f67b836d7..625b4ca68 100644 --- a/ovsdb/ovsdb.c +++ b/ovsdb/ovsdb.c @@ -40,6 +40,7 @@ #include "transaction-forward.h" #include "trigger.h" #include "unixctl.h" +#include "util.h" #include "openvswitch/vlog.h" VLOG_DEFINE_THIS_MODULE(ovsdb); @@ -229,7 +230,7 @@ root_set_size(const struct ovsdb_schema *schema) struct ovsdb_error * ovsdb_schema_from_json(const struct json *json, struct ovsdb_schema **schemap) { - struct ovsdb_schema *schema; + struct ovsdb_schema *schema = NULL; const struct json *name, *tables, *version_json, *cksum; struct ovsdb_error *error; struct shash_node *node; @@ -249,6 +250,9 @@ ovsdb_schema_from_json(const struct json *json, struct ovsdb_schema **schemap) return error; } + ovs_assert(name); + ovs_assert(tables); + if (version_json) { version = json_string(version_json); if (!ovsdb_is_valid_version(version)) { @@ -282,6 +286,8 @@ ovsdb_schema_from_json(const struct json *json, struct ovsdb_schema **schemap) shash_add(&schema->tables, table->name, table); } + ovs_assert(schema); + /* "isRoot" was not part of the original schema definition. Before it was * added, there was no support for garbage collection. So, for backward * compatibility, if the root set is empty then assume that every table is diff --git a/ovsdb/query.c b/ovsdb/query.c index eebe56412..29cc93093 100644 --- a/ovsdb/query.c +++ b/ovsdb/query.c @@ -21,6 +21,7 @@ #include "condition.h" #include "row.h" #include "table.h" +#include "util.h" void ovsdb_query(struct ovsdb_table *table, const struct ovsdb_condition *cnd, @@ -91,6 +92,7 @@ ovsdb_query_distinct(struct ovsdb_table *table, struct ovsdb_row_hash hash; ovsdb_row_hash_init(&hash, columns); + ovs_assert(condition); ovsdb_query(table, condition, query_distinct_cb, &hash); HMAP_FOR_EACH (node, hmap_node, &hash.rows) { ovsdb_row_set_add_row(results, node->row); diff --git a/ovsdb/transaction.c b/ovsdb/transaction.c index 7cf4a851a..4fdc5bcea 100644 --- a/ovsdb/transaction.c +++ b/ovsdb/transaction.c @@ -34,6 +34,7 @@ #include "storage.h" #include "table.h" #include "uuid.h" +#include "util.h" VLOG_DEFINE_THIS_MODULE(transaction); @@ -576,6 +577,7 @@ ovsdb_txn_update_weak_refs(struct ovsdb_txn *txn OVS_UNUSED, dst_row = CONST_CAST(struct ovsdb_row *, ovsdb_table_get_row(weak->dst_table, &weak->dst)); + ovs_assert(dst_row); ovs_assert(!ovsdb_row_find_weak_ref(dst_row, weak)); hmap_insert(&dst_row->dst_refs, &weak->dst_node, ovsdb_weak_ref_hash(weak)); diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index f55c2965a..42203a01c 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -671,6 +671,7 @@ add_port_to_cache(struct vsctl_context *vsctl_ctx, struct vsctl_bridge *parent, } } + ovs_assert(parent); ovs_list_push_back(&parent->ports, &port->ports_node); ovs_list_init(&port->ifaces); port->port_cfg = port_cfg; @@ -817,6 +818,7 @@ vsctl_context_populate_cache(struct ctl_context *ctx) continue; } br = shash_find_data(&vsctl_ctx->bridges, br_cfg->name); + ovs_assert(br); for (j = 0; j < br_cfg->n_ports; j++) { struct ovsrec_port *port_cfg = br_cfg->ports[j]; struct vsctl_port *port; @@ -843,6 +845,7 @@ vsctl_context_populate_cache(struct ctl_context *ctx) } port = add_port_to_cache(vsctl_ctx, br, port_cfg); + ovs_assert(port); for (k = 0; k < port_cfg->n_interfaces; k++) { struct ovsrec_interface *iface_cfg = port_cfg->interfaces[k]; struct vsctl_iface *iface; diff --git a/vtep/vtep-ctl.c b/vtep/vtep-ctl.c index e5d99714d..d5a6575d5 100644 --- a/vtep/vtep-ctl.c +++ b/vtep/vtep-ctl.c @@ -1065,6 +1065,7 @@ vtep_ctl_context_populate_cache(struct ctl_context *ctx) continue; } ps = shash_find_data(&vtepctl_ctx->pswitches, ps_cfg->name); + ovs_assert(ps); for (j = 0; j < ps_cfg->n_ports; j++) { struct vteprec_physical_port *port_cfg = ps_cfg->ports[j]; struct vtep_ctl_port *port; @@ -1087,7 +1088,7 @@ vtep_ctl_context_populate_cache(struct ctl_context *ctx) } port = add_port_to_cache(vtepctl_ctx, ps, port_cfg); - + ovs_assert(port); for (k = 0; k < port_cfg->n_vlan_bindings; k++) { struct vtep_ctl_lswitch *ls; char *vlan; @@ -1884,6 +1885,8 @@ del_mcast_entry(struct ctl_context *ctx, if (ovs_list_is_empty(&mcast_mac->locators)) { struct shash_node *node = shash_find(mcast_shash, mac); + ovs_assert(node); + vteprec_physical_locator_set_delete(ploc_set_cfg); if (local) {