From nobody Wed Apr 16 12:41:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564389293; cv=none; d=zoho.com; s=zohoarc; b=YMfWm8fTItVaF6J6OKAen9hucduJTCfOmSbDCf1tEbxyUFwyVw7EfBpRvDyv0e9tz8IOPRZDRx5UoDz2aTNdd3KFMrQ20OMR2skwjbdrnsjHMRya6LVM9hb2JylLp/uj/djoKV3ihsPPlHXg/CAQMdNXEb/XoZkqcW3bS09BYSI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564389293; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=oS5GVC0RIylSkvcG6h66LQZdxLdAZnP3+6L2mQqlRiY=; b=X8evvO/B+mZFSaQYHnfPsMRfSkboF1SU/7lCnW5sMLXFCzElB1ueMPsKUY9XvVr4IFGl2QbO9sYlBot/etJRkTepOyvRLYTy2jrTeIOewEDybHt4eonl7J9P2RPR0N+DlTUMZ0qgqDARVCMexIZJBpa6BAYSb9/fX+dvynE+od8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564389293157174.61808604427938; Mon, 29 Jul 2019 01:34:53 -0700 (PDT) Received: from localhost ([::1]:50470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hs17M-0005kl-6k for importer@patchew.org; Mon, 29 Jul 2019 04:34:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48074) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hs16b-0004X6-71 for qemu-devel@nongnu.org; Mon, 29 Jul 2019 04:34:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hs16Z-0003Jp-7U for qemu-devel@nongnu.org; Mon, 29 Jul 2019 04:34:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38966) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hs16X-0003IZ-8T for qemu-devel@nongnu.org; Mon, 29 Jul 2019 04:34:02 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B0E7C01DE0D; Mon, 29 Jul 2019 08:34:00 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-203.pek2.redhat.com [10.72.12.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD46B10190B5; Mon, 29 Jul 2019 08:33:58 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Mon, 29 Jul 2019 16:33:46 +0800 Message-Id: <1564389226-4489-6-git-send-email-jasowang@redhat.com> In-Reply-To: <1564389226-4489-1-git-send-email-jasowang@redhat.com> References: <1564389226-4489-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 29 Jul 2019 08:34:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/5] net/colo-compare.c: Fix memory leak and code style issue. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Jason Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen This patch to fix the origin "char *data" memory leak, code style issue and add necessary check here. Reported-by: Coverity (CID 1402785) Signed-off-by: Zhang Chen Reviewed-by: Peter Maydell Signed-off-by: Jason Wang --- net/colo-compare.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 909dd6c..7489840 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -127,6 +127,17 @@ static int compare_chr_send(CompareState *s, uint32_t vnet_hdr_len, bool notify_remote_frame); =20 +static bool packet_matches_str(const char *str, + const uint8_t *buf, + uint32_t packet_len) +{ + if (packet_len !=3D strlen(str)) { + return false; + } + + return !memcmp(str, buf, strlen(str)); +} + static void notify_remote_frame(CompareState *s) { char msg[] =3D "DO_CHECKPOINT"; @@ -1008,21 +1019,23 @@ static void compare_notify_rs_finalize(SocketReadSt= ate *notify_rs) { CompareState *s =3D container_of(notify_rs, CompareState, notify_rs); =20 - /* Get Xen colo-frame's notify and handle the message */ - char *data =3D g_memdup(notify_rs->buf, notify_rs->packet_len); - char msg[] =3D "COLO_COMPARE_GET_XEN_INIT"; + const char msg[] =3D "COLO_COMPARE_GET_XEN_INIT"; int ret; =20 - if (!strcmp(data, "COLO_USERSPACE_PROXY_INIT")) { + if (packet_matches_str("COLO_USERSPACE_PROXY_INIT", + notify_rs->buf, + notify_rs->packet_len)) { ret =3D compare_chr_send(s, (uint8_t *)msg, strlen(msg), 0, true); if (ret < 0) { error_report("Notify Xen COLO-frame INIT failed"); } - } - - if (!strcmp(data, "COLO_CHECKPOINT")) { + } else if (packet_matches_str("COLO_CHECKPOINT", + notify_rs->buf, + notify_rs->packet_len)) { /* colo-compare do checkpoint, flush pri packet and remove sec pac= ket */ g_queue_foreach(&s->conn_list, colo_flush_packets, s); + } else { + error_report("COLO compare got unsupported instruction"); } } =20 --=20 2.5.0