From nobody Sat Nov 15 14:48:14 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1751030128; cv=none; d=zohomail.com; s=zohoarc; b=aLvd/f9HUmUJ7cpJYCkqmsrI/WeocylMYAODKgSxHjR5DZU8k3mjtuoRST1kjBscLOCMuQfRXijDlRK5OKXwS5dbcWIvhMQ+deSoOjZwSSg48dcfFMHZv71G3/MTn133xetFIKPp5JLjwSP44XtXXV9UluZVF/b7/8iVTntoU/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751030128; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YCaT80+woPzPW811tJJDtvGMU03636VebjfcJA5zUmA=; b=ObuVJ3B4glO7YdHuP8BpYccpBvVGiaBvz5skCJatIoKe/waLGWL9c4RKuCQAnj/dZuCtoX1dds1mfVIfTNr6LHRl9k3CGccsibZ+e64C8a1gYP3P4BoNo7bI++VPLGsj+L1+nmKxkOjlLcNyI2UKURo/J1LVdv1rMiJzO2Oz/J4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751030128654171.83550847688707; Fri, 27 Jun 2025 06:15:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uV8ur-00010v-Eh; Fri, 27 Jun 2025 09:14:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uUz3X-0005t1-PP for qemu-devel@nongnu.org; Thu, 26 Jun 2025 22:43:13 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uUz3T-00048P-4y for qemu-devel@nongnu.org; Thu, 26 Jun 2025 22:43:08 -0400 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-313910f392dso1402720a91.2 for ; Thu, 26 Jun 2025 19:43:05 -0700 (PDT) Received: from localhost.localdomain ([1.203.169.237]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-318ca222dcdsm529501a91.39.2025.06.26.19.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jun 2025 19:43:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750992184; x=1751596984; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=YCaT80+woPzPW811tJJDtvGMU03636VebjfcJA5zUmA=; b=VU4Zgpj6XGtp11pE+3Wp/NKpTdpJD79KO0mtw+ApbBgJ4HHliwdZ/LHVJhuuL/w3NY r3gXOypHsSFXtdGu0Pb3OxdLiH7tgwxks1Yz7mVysfcSZ0kHQuWvaPFy8KeQdiZh58O9 I4rEL1KJCZpGVjaxPnXZTJsgT1F50BpYCbKt48ioBTgi3nhfTUa6GJ2q9Gy/lBqIV5SB LaS120+YJY+ymh3Hp77UQ9sCL63RpzokztUF+MoyisrZU/9sfHGp49Qj0aTve2B4cN/7 NGyN+wIJ4JnqA2Nl0ksxTaO7YPkQzWzb2pdAY8dSdBuK/9zyaNeOOl6EdAaMi0UfcJVs UWJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750992184; x=1751596984; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YCaT80+woPzPW811tJJDtvGMU03636VebjfcJA5zUmA=; b=fSYdPrVQ3QqUNuToofEtQsS8jSDHM0MZaxtJJ6K2YNNo613/V/OCtGhw6oIFXXbg26 UMd/ssSa+PTR4Shlvv0fB1Nh5R8azqy1ragCB0ri0jXer0SYftXh7gnw01B2Dh+Gr92f lYWHtQSSQ6HhjWnsoLnWc5d9Wo63AE7gNgt/HKlTcDgv0pxAlidlndiU0zRjkzXVvS1R o4olKBSBswe62pn1LiEFeQD+xHRKwnXTRpjFxjFrDhPt9AblH5xJsiNuKUkIw9qRm8eN PvYC/k8UJV+sRaVcqLdF86u6pjQACskik9qAbdsqeyx1fqFStT74vGjhQbVMJBxCyxRM t0tg== X-Gm-Message-State: AOJu0Yz9qQ3DNWc86MdMQC6ibwSqVRIcNyHRWaG/UKbrwXBvNuJnTuqG ISiljXr9E6rhBMeRkIqKvws2vuUkjB+35R/uUjJNhkA7JESYqYvvMSaXf3OVJoDrAHqctQ== X-Gm-Gg: ASbGnctcqxHJ6eRPmjNafVs7U+RPph8EUviX1q2w1ncnqiV+NDLU8ml3bcbYA4GzDqD GnnUEyFJj7kcLw9soi5Fs3VXwKvKCembulo3FbqlrpFrKpI1YaqPvRivGumT0HyU3QyGXxRRZV9 17tNst5yqAut6jvOBaz9k2Wm227feBoy0wzQUQ+tkfLIABK4mfVoIV0jG5eAEm3VKejKohfOqY3 e3em6DiE1/QM2C06UXpjJptdfZ4c80WkH2//G4y5/bRE1dqNXgDUFPWfeJ0r5xpCOvUc7wBQRhW 6oIMgB2MFwgN9xPpez2Xgggkponzd264K2Tiwnz58P07RCN7JSBHn0f95HOX7gcrmibe/os+EQp cKrcuPxmh X-Google-Smtp-Source: AGHT+IGTo4EXOyszvbTKlWC99oSPrkLjOfzAq325Q7nBdkXqbPtDP9RpsJcW2nzqEkb19dDoUYzuzQ== X-Received: by 2002:a17:90b:5347:b0:311:e8cc:4255 with SMTP id 98e67ed59e1d1-318c930f93amr1555136a91.31.1750992183666; Thu, 26 Jun 2025 19:43:03 -0700 (PDT) From: xjdeng To: qemu-devel@nongnu.org Cc: xjdeng Subject: [PATCH] qtest/migration: Fix potential NPD through getenv Date: Fri, 27 Jun 2025 10:42:26 +0800 Message-Id: <20250627024226.1767-1-micro6947@gmail.com> X-Mailer: git-send-email 2.27.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=micro6947@gmail.com; helo=mail-pj1-x102e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 27 Jun 2025 09:14:51 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1751030129638116600 Content-Type: text/plain; charset="utf-8" In `find_common_machine_version`, the code previously assumed that `getenv(var1)` and `getenv(var2)` would always return non-NULL values. However, if either environment variable is not set, `getenv` returns NULL, which could lead to a null pointer dereference. Tracing upstream usage: `find_common_machine_version` is called by `resolve_machine_version` with `QEMU_ENV_SRC` and `QEMU_ENV_DST`. `resolve_machine_version` is used by `migrate_start`, which is called by `migrate_postcopy_prepare`, and ultimately by `test_postcopy_common`. In `test_postcopy_common`, after `migrate_postcopy_prepare`, the function `migrate_postcopy_complete` is called. Inside,=20 `migration_get_env` checks if `QEMU_ENV_SRC` and `QEMU_ENV_DST` are set before use. Thus, these variables can be NULL, leading to a potential null pointer dereference in `find_common_machine_version`. Signed-off-by: xjdeng --- tests/qtest/migration/migration-util.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/qtest/migration/migration-util.c b/tests/qtest/migration= /migration-util.c index 642cf50c8d..45c9e164e2 100644 --- a/tests/qtest/migration/migration-util.c +++ b/tests/qtest/migration/migration-util.c @@ -203,8 +203,25 @@ char *find_common_machine_version(const char *mtype, c= onst char *var1, return g_strdup(type2); } =20 - g_test_message("No common machine version for machine type '%s' betwee= n " - "binaries %s and %s", mtype, getenv(var1), getenv(var2)= ); + char *varstring1 =3D getenv(var1); + char *varstring2 =3D getenv(var2); + if (varstring1 && varstring2) { + g_test_message("No common machine version for machine type '%s' " + "between binaries %s and %s", + mtype, varstring1, varstring2); + } else if (varstring1) { + g_test_message("No common machine version for machine type '%s' " + "between binary %s and environment variable %s", + mtype, varstring1, var2); + } else if (varstring2) { + g_test_message("No common machine version for machine type '%s' " + "between binary %s and environment variable %s", + mtype, varstring2, var1); + } else { + g_test_message("No common machine version for machine type '%s' " + "between environment variables %s and %s", + mtype, var1, var2); + } g_assert_not_reached(); } =20 --=20 2.27.0.windows.1