From nobody Mon May 20 16:30:38 2024 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=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1645118329; cv=none; d=zohomail.com; s=zohoarc; b=MmHVpf2xT6w7bURa2r9dbBoMj4Mw16zML1E9j2LAVQ5tPT01pk4ASDb5LCzTd08aXfxEkuUNQZ9ZJ3Dm0Q8Mfd9nX8lMqq1UAUVjEvyxqWqMGHDrRSD/92oOeZtXtfgEEKT488F6UCQylmbO+iGiMftTugnM7OSzXrDFskY5sN8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645118329; 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; bh=2f/auedyRN5PsjHfuc6bSpPOyeYNidRH6eop1nQv5J8=; b=OiFKN51rHZHS27+2qSO/6Hl2puJubHel8z5DUlAS0PWVbqfrG0P2mBL5f+0mdwz2udgU+GqaLEM6peYIwMirqoN3EgEanTYbXVNptMEPN61Zloe2TFNDCd++ejRAf+ds+UnEaXNJMxSKMQeXU0qG3LlygRrjFKaP8nIrZyo+d5c= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645118329650910.0114679603422; Thu, 17 Feb 2022 09:18:49 -0800 (PST) Received: from localhost ([::1]:51856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKkQa-0000JX-DB for importer@patchew.org; Thu, 17 Feb 2022 12:18:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <65ceee0ae5475589be0a22831860430c7c10bf52@lizzy.crudebyte.com>) id 1nKkNQ-0004JW-AN for qemu-devel@nongnu.org; Thu, 17 Feb 2022 12:15:32 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:55605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <65ceee0ae5475589be0a22831860430c7c10bf52@lizzy.crudebyte.com>) id 1nKkNN-0001xc-EI for qemu-devel@nongnu.org; Thu, 17 Feb 2022 12:15:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=2f/auedyRN5PsjHfuc6bSpPOyeYNidRH6eop1nQv5J8=; b=C1nh+ cheweM8PMq7ylKK5i83UPfX4liWBH0fcq1L3+Vx+4/hHmKy+pUw0vnAK1Hdh7i0J/HcKc0MBIXTBl lYUC0AYfczyFH9p6ccT51NnZJvq1FsEQTHo5Gnv08+NAUb61I6YPFYVbWaWSaMLNnW2i7X9PM31bj SiA7bK+H0pYEzK9QdsK2g2qp5fZRa4SqVPA5SfWKQs6ZzGWkzzDxGfaz0oHq2zr6MaR7Jf/vmgF2Z pEXLTI/spuqpyBN+GN916vGRdgcz5GCNUJ9fsaDCblEefO16i1IbkG3Bs9Inog7vyrsl0c2DqFS9M 7AoARwzrxYUNS8KA3Zj4pPkAnqINQ==; Message-Id: <65ceee0ae5475589be0a22831860430c7c10bf52.1645114783.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 17 Feb 2022 17:19:44 +0100 Subject: [PULL v2 1/5] tests/9pfs: use g_autofree where possible To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz 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: none client-ip=91.194.90.13; envelope-from=65ceee0ae5475589be0a22831860430c7c10bf52@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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" X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1645118332032100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Christian Schoenebeck Reviewed-by: Greg Kurz Message-Id: --- tests/qtest/virtio-9p-test.c | 90 +++++++++++------------------------- 1 file changed, 27 insertions(+), 63 deletions(-) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index 41fed41de1..502e5ad0c7 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -84,7 +84,7 @@ static void pci_config(void *obj, void *data, QGuestAlloc= ator *t_alloc) QVirtio9P *v9p =3D obj; alloc =3D t_alloc; size_t tag_len =3D qvirtio_config_readw(v9p->vdev, 0); - char *tag; + g_autofree char *tag =3D NULL; int i; =20 g_assert_cmpint(tag_len, =3D=3D, strlen(MOUNT_TAG)); @@ -94,7 +94,6 @@ static void pci_config(void *obj, void *data, QGuestAlloc= ator *t_alloc) tag[i] =3D qvirtio_config_readb(v9p->vdev, i + 2); } g_assert_cmpmem(tag, tag_len, MOUNT_TAG, tag_len); - g_free(tag); } =20 #define P9_MAX_SIZE 4096 /* Max size of a T-message or R-message */ @@ -580,7 +579,7 @@ static void do_version(QVirtio9P *v9p) { const char *version =3D "9P2000.L"; uint16_t server_len; - char *server_version; + g_autofree char *server_version =3D NULL; P9Req *req; =20 req =3D v9fs_tversion(v9p, P9_MAX_SIZE, version, P9_NOTAG); @@ -588,8 +587,6 @@ static void do_version(QVirtio9P *v9p) v9fs_rversion(req, &server_len, &server_version); =20 g_assert_cmpmem(server_version, server_len, version, strlen(version)); - - g_free(server_version); } =20 /* utility function: walk to requested dir and return fid for that dir */ @@ -637,7 +634,7 @@ static void fs_walk(void *obj, void *data, QGuestAlloca= tor *t_alloc) alloc =3D t_alloc; char *wnames[P9_MAXWELEM]; uint16_t nwqid; - v9fs_qid *wqid; + g_autofree v9fs_qid *wqid =3D NULL; int i; P9Req *req; =20 @@ -655,8 +652,6 @@ static void fs_walk(void *obj, void *data, QGuestAlloca= tor *t_alloc) for (i =3D 0; i < P9_MAXWELEM; i++) { g_free(wnames[i]); } - - g_free(wqid); } =20 static bool fs_dirents_contain_name(struct V9fsDirent *e, const char* name) @@ -872,9 +867,9 @@ static void fs_readdir(void *obj, void *data, QGuestAll= ocator *t_alloc) g_assert_cmpint(fs_dirents_contain_name(entries, "."), =3D=3D, true); g_assert_cmpint(fs_dirents_contain_name(entries, ".."), =3D=3D, true); for (int i =3D 0; i < QTEST_V9FS_SYNTH_READDIR_NFILES; ++i) { - char *name =3D g_strdup_printf(QTEST_V9FS_SYNTH_READDIR_FILE, i); + g_autofree char *name =3D + g_strdup_printf(QTEST_V9FS_SYNTH_READDIR_FILE, i); g_assert_cmpint(fs_dirents_contain_name(entries, name), =3D=3D, tr= ue); - g_free(name); } =20 v9fs_free_dirents(entries); @@ -984,7 +979,8 @@ static void fs_walk_dotdot(void *obj, void *data, QGues= tAllocator *t_alloc) QVirtio9P *v9p =3D obj; alloc =3D t_alloc; char *const wnames[] =3D { g_strdup("..") }; - v9fs_qid root_qid, *wqid; + v9fs_qid root_qid; + g_autofree v9fs_qid *wqid =3D NULL; P9Req *req; =20 do_version(v9p); @@ -998,7 +994,6 @@ static void fs_walk_dotdot(void *obj, void *data, QGues= tAllocator *t_alloc) =20 g_assert_cmpmem(&root_qid, 13, wqid[0], 13); =20 - g_free(wqid); g_free(wnames[0]); } =20 @@ -1027,7 +1022,7 @@ static void fs_write(void *obj, void *data, QGuestAll= ocator *t_alloc) alloc =3D t_alloc; static const uint32_t write_count =3D P9_MAX_SIZE / 2; char *const wnames[] =3D { g_strdup(QTEST_V9FS_SYNTH_WRITE_FILE) }; - char *buf =3D g_malloc0(write_count); + g_autofree char *buf =3D g_malloc0(write_count); uint32_t count; P9Req *req; =20 @@ -1045,7 +1040,6 @@ static void fs_write(void *obj, void *data, QGuestAll= ocator *t_alloc) v9fs_rwrite(req, &count); g_assert_cmpint(count, =3D=3D, write_count); =20 - g_free(buf); g_free(wnames[0]); } =20 @@ -1125,7 +1119,7 @@ static void fs_flush_ignored(void *obj, void *data, Q= GuestAllocator *t_alloc) =20 static void do_mkdir(QVirtio9P *v9p, const char *path, const char *cname) { - char *const name =3D g_strdup(cname); + g_autofree char *name =3D g_strdup(cname); uint32_t fid; P9Req *req; =20 @@ -1134,15 +1128,13 @@ static void do_mkdir(QVirtio9P *v9p, const char *pa= th, const char *cname) req =3D v9fs_tmkdir(v9p, fid, name, 0750, 0, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rmkdir(req, NULL); - - g_free(name); } =20 /* create a regular file with Tlcreate and return file's fid */ static uint32_t do_lcreate(QVirtio9P *v9p, const char *path, const char *cname) { - char *const name =3D g_strdup(cname); + g_autofree char *name =3D g_strdup(cname); uint32_t fid; P9Req *req; =20 @@ -1152,7 +1144,6 @@ static uint32_t do_lcreate(QVirtio9P *v9p, const char= *path, v9fs_req_wait_for_reply(req, NULL); v9fs_rlcreate(req, NULL, NULL); =20 - g_free(name); return fid; } =20 @@ -1160,8 +1151,8 @@ static uint32_t do_lcreate(QVirtio9P *v9p, const char= *path, static void do_symlink(QVirtio9P *v9p, const char *path, const char *clink, const char *to) { - char *const name =3D g_strdup(clink); - char *const dst =3D g_strdup(to); + g_autofree char *name =3D g_strdup(clink); + g_autofree char *dst =3D g_strdup(to); uint32_t fid; P9Req *req; =20 @@ -1170,9 +1161,6 @@ static void do_symlink(QVirtio9P *v9p, const char *pa= th, const char *clink, req =3D v9fs_tsymlink(v9p, fid, name, dst, 0, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rsymlink(req, NULL); - - g_free(dst); - g_free(name); } =20 /* create a hard link named @a clink in directory @a path pointing to @a t= o */ @@ -1193,7 +1181,7 @@ static void do_hardlink(QVirtio9P *v9p, const char *p= ath, const char *clink, static void do_unlinkat(QVirtio9P *v9p, const char *atpath, const char *rp= ath, uint32_t flags) { - char *const name =3D g_strdup(rpath); + g_autofree char *name =3D g_strdup(rpath); uint32_t fid; P9Req *req; =20 @@ -1202,8 +1190,6 @@ static void do_unlinkat(QVirtio9P *v9p, const char *a= tpath, const char *rpath, req =3D v9fs_tunlinkat(v9p, fid, name, flags, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_runlinkat(req); - - g_free(name); } =20 static void fs_readdir_split_128(void *obj, void *data, @@ -1235,8 +1221,8 @@ static void fs_create_dir(void *obj, void *data, QGue= stAllocator *t_alloc) QVirtio9P *v9p =3D obj; alloc =3D t_alloc; struct stat st; - char *root_path =3D virtio_9p_test_path(""); - char *new_dir =3D virtio_9p_test_path("01"); + g_autofree char *root_path =3D virtio_9p_test_path(""); + g_autofree char *new_dir =3D virtio_9p_test_path("01"); =20 g_assert(root_path !=3D NULL); =20 @@ -1247,9 +1233,6 @@ static void fs_create_dir(void *obj, void *data, QGue= stAllocator *t_alloc) g_assert(stat(new_dir, &st) =3D=3D 0); /* ... and is actually a directory */ g_assert((st.st_mode & S_IFMT) =3D=3D S_IFDIR); - - g_free(new_dir); - g_free(root_path); } =20 static void fs_unlinkat_dir(void *obj, void *data, QGuestAllocator *t_allo= c) @@ -1257,8 +1240,8 @@ static void fs_unlinkat_dir(void *obj, void *data, QG= uestAllocator *t_alloc) QVirtio9P *v9p =3D obj; alloc =3D t_alloc; struct stat st; - char *root_path =3D virtio_9p_test_path(""); - char *new_dir =3D virtio_9p_test_path("02"); + g_autofree char *root_path =3D virtio_9p_test_path(""); + g_autofree char *new_dir =3D virtio_9p_test_path("02"); =20 g_assert(root_path !=3D NULL); =20 @@ -1273,9 +1256,6 @@ static void fs_unlinkat_dir(void *obj, void *data, QG= uestAllocator *t_alloc) do_unlinkat(v9p, "/", "02", AT_REMOVEDIR); /* directory should be gone now */ g_assert(stat(new_dir, &st) !=3D 0); - - g_free(new_dir); - g_free(root_path); } =20 static void fs_create_file(void *obj, void *data, QGuestAllocator *t_alloc) @@ -1283,7 +1263,7 @@ static void fs_create_file(void *obj, void *data, QGu= estAllocator *t_alloc) QVirtio9P *v9p =3D obj; alloc =3D t_alloc; struct stat st; - char *new_file =3D virtio_9p_test_path("03/1st_file"); + g_autofree char *new_file =3D virtio_9p_test_path("03/1st_file"); =20 do_attach(v9p); do_mkdir(v9p, "/", "03"); @@ -1293,8 +1273,6 @@ static void fs_create_file(void *obj, void *data, QGu= estAllocator *t_alloc) g_assert(stat(new_file, &st) =3D=3D 0); /* ... and is a regular file */ g_assert((st.st_mode & S_IFMT) =3D=3D S_IFREG); - - g_free(new_file); } =20 static void fs_unlinkat_file(void *obj, void *data, QGuestAllocator *t_all= oc) @@ -1302,7 +1280,7 @@ static void fs_unlinkat_file(void *obj, void *data, Q= GuestAllocator *t_alloc) QVirtio9P *v9p =3D obj; alloc =3D t_alloc; struct stat st; - char *new_file =3D virtio_9p_test_path("04/doa_file"); + g_autofree char *new_file =3D virtio_9p_test_path("04/doa_file"); =20 do_attach(v9p); do_mkdir(v9p, "/", "04"); @@ -1316,8 +1294,6 @@ static void fs_unlinkat_file(void *obj, void *data, Q= GuestAllocator *t_alloc) do_unlinkat(v9p, "04", "doa_file", 0); /* file should be gone now */ g_assert(stat(new_file, &st) !=3D 0); - - g_free(new_file); } =20 static void fs_symlink_file(void *obj, void *data, QGuestAllocator *t_allo= c) @@ -1325,8 +1301,8 @@ static void fs_symlink_file(void *obj, void *data, QG= uestAllocator *t_alloc) QVirtio9P *v9p =3D obj; alloc =3D t_alloc; struct stat st; - char *real_file =3D virtio_9p_test_path("05/real_file"); - char *symlink_file =3D virtio_9p_test_path("05/symlink_file"); + g_autofree char *real_file =3D virtio_9p_test_path("05/real_file"); + g_autofree char *symlink_file =3D virtio_9p_test_path("05/symlink_file= "); =20 do_attach(v9p); do_mkdir(v9p, "/", "05"); @@ -1338,9 +1314,6 @@ static void fs_symlink_file(void *obj, void *data, QG= uestAllocator *t_alloc) =20 /* check if created link exists now */ g_assert(stat(symlink_file, &st) =3D=3D 0); - - g_free(symlink_file); - g_free(real_file); } =20 static void fs_unlinkat_symlink(void *obj, void *data, @@ -1349,8 +1322,8 @@ static void fs_unlinkat_symlink(void *obj, void *data, QVirtio9P *v9p =3D obj; alloc =3D t_alloc; struct stat st; - char *real_file =3D virtio_9p_test_path("06/real_file"); - char *symlink_file =3D virtio_9p_test_path("06/symlink_file"); + g_autofree char *real_file =3D virtio_9p_test_path("06/real_file"); + g_autofree char *symlink_file =3D virtio_9p_test_path("06/symlink_file= "); =20 do_attach(v9p); do_mkdir(v9p, "/", "06"); @@ -1364,9 +1337,6 @@ static void fs_unlinkat_symlink(void *obj, void *data, do_unlinkat(v9p, "06", "symlink_file", 0); /* symlink should be gone now */ g_assert(stat(symlink_file, &st) !=3D 0); - - g_free(symlink_file); - g_free(real_file); } =20 static void fs_hardlink_file(void *obj, void *data, QGuestAllocator *t_all= oc) @@ -1374,8 +1344,8 @@ static void fs_hardlink_file(void *obj, void *data, Q= GuestAllocator *t_alloc) QVirtio9P *v9p =3D obj; alloc =3D t_alloc; struct stat st_real, st_link; - char *real_file =3D virtio_9p_test_path("07/real_file"); - char *hardlink_file =3D virtio_9p_test_path("07/hardlink_file"); + g_autofree char *real_file =3D virtio_9p_test_path("07/real_file"); + g_autofree char *hardlink_file =3D virtio_9p_test_path("07/hardlink_fi= le"); =20 do_attach(v9p); do_mkdir(v9p, "/", "07"); @@ -1391,9 +1361,6 @@ static void fs_hardlink_file(void *obj, void *data, Q= GuestAllocator *t_alloc) g_assert((st_link.st_mode & S_IFMT) =3D=3D S_IFREG); g_assert(st_link.st_dev =3D=3D st_real.st_dev); g_assert(st_link.st_ino =3D=3D st_real.st_ino); - - g_free(hardlink_file); - g_free(real_file); } =20 static void fs_unlinkat_hardlink(void *obj, void *data, @@ -1402,8 +1369,8 @@ static void fs_unlinkat_hardlink(void *obj, void *dat= a, QVirtio9P *v9p =3D obj; alloc =3D t_alloc; struct stat st_real, st_link; - char *real_file =3D virtio_9p_test_path("08/real_file"); - char *hardlink_file =3D virtio_9p_test_path("08/hardlink_file"); + g_autofree char *real_file =3D virtio_9p_test_path("08/real_file"); + g_autofree char *hardlink_file =3D virtio_9p_test_path("08/hardlink_fi= le"); =20 do_attach(v9p); do_mkdir(v9p, "/", "08"); @@ -1419,9 +1386,6 @@ static void fs_unlinkat_hardlink(void *obj, void *dat= a, g_assert(stat(hardlink_file, &st_link) !=3D 0); /* and old file should still exist */ g_assert(stat(real_file, &st_real) =3D=3D 0); - - g_free(hardlink_file); - g_free(real_file); } =20 static void *assign_9p_local_driver(GString *cmd_line, void *arg) --=20 2.20.1 From nobody Mon May 20 16:30:38 2024 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=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1645117927; cv=none; d=zohomail.com; s=zohoarc; b=RW7POLOS9T1H8wrflPqnwYKEoid/kWEPYOAh5THMXBRKzeVqhG4NSs4mCZRp3XSB/f6tzjIsXBqujIjlzH+nmZphVuKxTtpCsq+Ug77RfzKLZ3+hTYTxTxmeUzC/WpFB1d+N3MhRFI+t1Ednkh7Jx1SMlTl/RvF3Ltn3GA8G8UQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645117927; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rMf4KtmBn+yyQQHi+FpBQwGipj8F3jW/JGrXe3xFgzc=; b=dapsQBxVFGfIUjmqvkVPmLKx5tj1M89+8LxV9DwQLOAtBFoiNN3usswhC/Sbrpy4xSS0NFRm26gjpvgCa8arQAEjOMBAmOgccZSoX22rOEGvscFmozcshImcKBpqj5JsHJcKsKmlVFYgoUEK0yPGSQnRiSg+/D881WthVdym7H8= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645117927464304.5698691371558; Thu, 17 Feb 2022 09:12:07 -0800 (PST) Received: from localhost ([::1]:37794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKkK6-0007fQ-Co for importer@patchew.org; Thu, 17 Feb 2022 12:12:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <68c66a96c8393d482599bf56f1c13c7ae3e13ec1@lizzy.crudebyte.com>) id 1nKkIw-0006Tk-NN for qemu-devel@nongnu.org; Thu, 17 Feb 2022 12:10:54 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:51545) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <68c66a96c8393d482599bf56f1c13c7ae3e13ec1@lizzy.crudebyte.com>) id 1nKkIu-0001Iw-4Q for qemu-devel@nongnu.org; Thu, 17 Feb 2022 12:10:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:References:In-Reply-To:Message-Id:Content-ID: Content-Description; bh=rMf4KtmBn+yyQQHi+FpBQwGipj8F3jW/JGrXe3xFgzc=; b=HLlwA ZIK2Y0fI/Z+dN61/6MQqCCLD3xR9rbeVrCj+N+j5i/Y+CzPRagS9uwk+7HdxU/f5MFVFEtg/7nKOE hs1nxDbML6n8MV/NY4Fhlq3BMjG2MVGqtsCvoeUfnrhhH4ZwNbIQIVBCxEUsQj28LksSzYJkIGXbY SmVc7w/dYHnco0zLNSnsA1rmOPepbQeYToMlngKI9SBhGRIfRJsLl9F2OLo/xnvQ3JPiJhNiLENm4 132L5TnNiMim8MQEpETPwqUT1DZZ334Mv8t29wJbfTX8pLot4hSy3Q8ln78Qdyonm7bsl9fHLGAqV 1LMzgxbtUBWFJo1swHR+nSiiGvsvw==; Message-Id: <68c66a96c8393d482599bf56f1c13c7ae3e13ec1.1645114783.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 17 Feb 2022 17:19:44 +0100 Subject: [PULL v2 2/5] tests/9pfs: fix mkdir() being called twice MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz 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: none client-ip=91.194.90.13; envelope-from=68c66a96c8393d482599bf56f1c13c7ae3e13ec1@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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" X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1645117929888100001 The 9p test cases use mkdtemp() to create a temporary directory for running the 'local' 9p tests with real files/dirs. Unlike mktemp() which only generates a unique file name, mkdtemp() also creates the directory, therefore the subsequent mkdir() was wrong and caused errors on some systems. Signed-off-by: Christian Schoenebeck Fixes: 136b7af2 (tests/9pfs: fix test dir for parallel tests) Reported-by: Daniel P. Berrang=C3=A9 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/832 Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Greg Kurz Message-Id: --- tests/qtest/libqos/virtio-9p.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c index b4e1143288..ef96ef006a 100644 --- a/tests/qtest/libqos/virtio-9p.c +++ b/tests/qtest/libqos/virtio-9p.c @@ -37,31 +37,19 @@ static char *concat_path(const char* a, const char* b) return g_build_filename(a, b, NULL); } =20 -static void init_local_test_path(void) +void virtio_9p_create_local_test_dir(void) { + struct stat st; char *pwd =3D g_get_current_dir(); char *template =3D concat_path(pwd, "qtest-9p-local-XXXXXX"); + local_test_path =3D mkdtemp(template); if (!local_test_path) { g_test_message("mkdtemp('%s') failed: %s", template, strerror(errn= o)); } - g_assert(local_test_path); g_free(pwd); -} - -void virtio_9p_create_local_test_dir(void) -{ - struct stat st; - int res; - - init_local_test_path(); =20 g_assert(local_test_path !=3D NULL); - res =3D mkdir(local_test_path, 0777); - if (res < 0) { - g_test_message("mkdir('%s') failed: %s", local_test_path, - strerror(errno)); - } =20 /* ensure test directory exists now ... */ g_assert(stat(local_test_path, &st) =3D=3D 0); --=20 2.20.1 From nobody Mon May 20 16:30:38 2024 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=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1645118241; cv=none; d=zohomail.com; s=zohoarc; b=PLmz/vBgJP7ApSFI1kAAYzq/EI5bcGTjb3JO3Cnnbyj1kG2aeNyoUt2jJoFlZpL15ZaVspa1QhVPWj/YyATasNejZtL4chXRbRk/VRh03DV83/X7eorrE7RZYMINUueEkBReDllOLpMW737OeeCjPM3PZags6G4hT5QcopXdwBc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645118241; 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; bh=nol1mgUdNPIinW3AvolOp2b+vCDqiMhIC5upX6MUJlg=; b=Uabp76WleE7cBOFYfC8OOjBigA8Ztizqq7Wf2Z0ra0BeHoZX8p3L5INf3w+EBlHqoeTu/KtOLAMsw5zD9K6RwZEP1pq6ALiSkcoky5i45SFX2EI8Ev6wkwcP+EcT2Njf0nMBzp4TCpQjNBZ4abVrLwExQNWcfPzSX9zOyWjcor0= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645118241306587.1057221376057; Thu, 17 Feb 2022 09:17:21 -0800 (PST) Received: from localhost ([::1]:48848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKkPA-0006k7-2P for importer@patchew.org; Thu, 17 Feb 2022 12:17:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56898) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKkMN-0002i9-9R for qemu-devel@nongnu.org; Thu, 17 Feb 2022 12:14:28 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:54215) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKkMD-0001tO-IC for qemu-devel@nongnu.org; Thu, 17 Feb 2022 12:14:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=nol1mgUdNPIinW3AvolOp2b+vCDqiMhIC5upX6MUJlg=; b=APc3I uAw1xHHbK0hMLhEJdRwVdNXZwVk9f++RXhnyGd7JhJA33jrfYnrga+v2lztG+rxnYGqECsCjjwroh Mp+24VHfQz/uzgAjuCxCfNX2Zjb5zqOnqC/imqyJyBbasZYbmlihwunD9yGDq69z+GJ+vo7w96O1V bjfCC6fN/OzeuaEPXIloZmrN48uo16eyzo/xFL1Fpqpz0Bc8LDZAbfwaqU7CKTqgm9unin/8eAptB Uhm+OAgwTFIs5ZixUCB/u5zzp8cjOcFtCSXzznJ9MdmkG7q/TQTrPVRjIUmTGTCqYhPJXmIesrMdn qtwMR86YU4Ys+P6x3PLldIFuXxj8A==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 17 Feb 2022 17:19:44 +0100 Subject: [PULL v2 3/5] tests/9pfs: Fix leak of local_test_path To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz 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: none client-ip=91.194.90.13; envelope-from=ba6112e40c03594cf4e3a7a6ebf52341153e7496@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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" X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1645118243776100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Greg Kurz local_test_path is allocated in virtio_9p_create_local_test_dir() to hold t= he path of the temporary directory. It should be freed in virtio_9p_remove_local_te= st_dir() when the temporary directory is removed. Clarify the lifecycle of local_tes= t_path while here. Based-on: Signed-off-by: Greg Kurz Message-Id: <20220201151508.190035-2-groug@kaod.org> Reviewed-by: Christian Schoenebeck Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c index ef96ef006a..5d18e5eae5 100644 --- a/tests/qtest/libqos/virtio-9p.c +++ b/tests/qtest/libqos/virtio-9p.c @@ -39,8 +39,13 @@ static char *concat_path(const char* a, const char* b) =20 void virtio_9p_create_local_test_dir(void) { + g_assert(local_test_path =3D=3D NULL); struct stat st; char *pwd =3D g_get_current_dir(); + /* + * template gets cached into local_test_path and freed in + * virtio_9p_remove_local_test_dir(). + */ char *template =3D concat_path(pwd, "qtest-9p-local-XXXXXX"); =20 local_test_path =3D mkdtemp(template); @@ -66,6 +71,8 @@ void virtio_9p_remove_local_test_dir(void) /* ignore error, dummy check to prevent compiler error */ } g_free(cmd); + g_free(local_test_path); + local_test_path =3D NULL; } =20 char *virtio_9p_test_path(const char *path) --=20 2.20.1 From nobody Mon May 20 16:30:38 2024 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=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1645118098; cv=none; d=zohomail.com; s=zohoarc; b=HfzFWgHgEQYXAP2VlJDoXkPYR4jCsGQLl9ZWXo8wJBN+rQi4tGGsbaQ3ByCpIJiwIKLfu58+Hyum7BQUoksZlPUyV4t+ZOQnqOiEW3Z3H+7dCdd+tg9pAjPHh9tkl4nv7YKged6kTKNi/0eu51SUb07V5OBl3h0jqzQpFXs0RY0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645118098; 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; bh=mcbRg2xlZAZHldg9PdPezpruRYnaMN84QxS/hR585+U=; b=jhLLl9/SzlgIFvHjlKTLWDQTDnRbWBBTrpkjFgAFdyxFBNFYoKBfEaFJtR13BGzwb+Fz3vLIB+z66cp4n+yBsD/o8rK9tyMuSMCrejykIktnfbaK4hmlIR1ACBsAt4aWdel8Un6WCUU0CSUipVhLps83OdTol6LIF1y0jC1yiko= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164511809836561.91615427060526; Thu, 17 Feb 2022 09:14:58 -0800 (PST) Received: from localhost ([::1]:42170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKkMp-0002BH-Ts for importer@patchew.org; Thu, 17 Feb 2022 12:14:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56680) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <494fbbd3ed46a14ef0924651c058b9b0dcb4a7b4@lizzy.crudebyte.com>) id 1nKkK7-0008Lc-B5 for qemu-devel@nongnu.org; Thu, 17 Feb 2022 12:12:07 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:41729) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <494fbbd3ed46a14ef0924651c058b9b0dcb4a7b4@lizzy.crudebyte.com>) id 1nKkK0-0001fJ-1Z for qemu-devel@nongnu.org; Thu, 17 Feb 2022 12:12:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=mcbRg2xlZAZHldg9PdPezpruRYnaMN84QxS/hR585+U=; b=jyauA PGLMEABx4ia3grMWc7oHNhA/306LiHzZ4lo6FHnBkBffFIsFOc38dfcdQDL1X+VIIfJP08zjLFr5c atcVnDt7f5rm3eQO9Kn1FOIVxwNntwnMN6rIP/8WMsudvFKbgm/XVXdKignCKeadkudMiFUVZD3Ff nYlIn4okaGZFZlTqpgMjjr9JShY5f6rEyfZnl5aVLorcIKnNZrTPL/7E3oa15nUuKo+TQfUDPdnm1 BPjF1LbHnOhRuq8yB38Luk8e7oB6ho1n1PVdc9tnSt9QjvmHiJGBq6zNdb4Qb+WgOcPC1MCee8ZyN txKi2mNqg8mUk7iyC1vpd8KEoHZWQ==; Message-Id: <494fbbd3ed46a14ef0924651c058b9b0dcb4a7b4.1645114783.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 17 Feb 2022 17:19:44 +0100 Subject: [PULL v2 4/5] tests/9pfs: Use g_autofree and g_autoptr where possible To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz 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: none client-ip=91.194.90.13; envelope-from=494fbbd3ed46a14ef0924651c058b9b0dcb4a7b4@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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" X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1645118100070100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Greg Kurz It is recommended to use g_autofree or g_autoptr as it reduces the odds of introducing memory leaks in future changes. Signed-off-by: Greg Kurz Message-Id: <20220201151508.190035-3-groug@kaod.org> Reviewed-by: Christian Schoenebeck Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c index 5d18e5eae5..f51f0635cc 100644 --- a/tests/qtest/libqos/virtio-9p.c +++ b/tests/qtest/libqos/virtio-9p.c @@ -41,7 +41,7 @@ void virtio_9p_create_local_test_dir(void) { g_assert(local_test_path =3D=3D NULL); struct stat st; - char *pwd =3D g_get_current_dir(); + g_autofree char *pwd =3D g_get_current_dir(); /* * template gets cached into local_test_path and freed in * virtio_9p_remove_local_test_dir(). @@ -52,7 +52,6 @@ void virtio_9p_create_local_test_dir(void) if (!local_test_path) { g_test_message("mkdtemp('%s') failed: %s", template, strerror(errn= o)); } - g_free(pwd); =20 g_assert(local_test_path !=3D NULL); =20 @@ -65,12 +64,11 @@ void virtio_9p_create_local_test_dir(void) void virtio_9p_remove_local_test_dir(void) { g_assert(local_test_path !=3D NULL); - char *cmd =3D g_strdup_printf("rm -fr '%s'\n", local_test_path); + g_autofree char *cmd =3D g_strdup_printf("rm -fr '%s'\n", local_test_p= ath); int res =3D system(cmd); if (res < 0) { /* ignore error, dummy check to prevent compiler error */ } - g_free(cmd); g_free(local_test_path); local_test_path =3D NULL; } @@ -216,8 +214,8 @@ static void *virtio_9p_pci_create(void *pci_bus, QGuest= Allocator *t_alloc, static void regex_replace(GString *haystack, const char *pattern, const char *replace_fmt, ...) { - GRegex *regex; - char *replace, *s; + g_autoptr(GRegex) regex =3D NULL; + g_autofree char *replace =3D NULL, *s =3D NULL; va_list argp; =20 va_start(argp, replace_fmt); @@ -227,9 +225,6 @@ static void regex_replace(GString *haystack, const char= *pattern, regex =3D g_regex_new(pattern, 0, 0, NULL); s =3D g_regex_replace(regex, haystack->str, -1, 0, replace, 0, NULL); g_string_assign(haystack, s); - g_free(s); - g_regex_unref(regex); - g_free(replace); } =20 void virtio_9p_assign_local_driver(GString *cmd_line, const char *args) --=20 2.20.1 From nobody Mon May 20 16:30:38 2024 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=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1645116462; cv=none; d=zohomail.com; s=zohoarc; b=LPyijKKpkfy/N+66OYjScGw5raa2DhCPQ8jiv0SVLyhG+zKvP7YGYT2sDj7DSvbA6G/C5TpticYQABaPMgQvycXesx9mfkYhTiWdfvIMOa9Z90EprBlAbYgL65D3u+oU2IQyJ6UmoFPB6wKg1VrFRKmUR1rS2qFXeAtFgxPPSP0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645116462; 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; bh=ibq2v8nsektk29gBgTOlpX79uTXZm/dDVAofuhI8Ulc=; b=Dms6c4H6/SINiYteXnSMi1bfmOejJv+t0XMVmxSfsM9/1C4pn/yi77Suyy9XgJ7C6jfMDJytSt8zqUX5Y04KpQ0VPRLWi2G4SLMLRSU9lBEVW0ZKcRUr1gSHBsXJF2YOrllq4x1IddtoAwdSBx1JsuIYJDe9xTUFG08piCL7R44= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645116462787823.5334789649306; Thu, 17 Feb 2022 08:47:42 -0800 (PST) Received: from localhost ([::1]:42338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKjwS-0007Rl-LQ for importer@patchew.org; Thu, 17 Feb 2022 11:47:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKjtx-0006Kw-Tk for qemu-devel@nongnu.org; Thu, 17 Feb 2022 11:45:06 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:42757) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKjtq-0005TX-Fl for qemu-devel@nongnu.org; Thu, 17 Feb 2022 11:45:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=ibq2v8nsektk29gBgTOlpX79uTXZm/dDVAofuhI8Ulc=; b=PPcxV wh51Av87wPC+adhbn3h5tRTp9n6bIZpRFcpZGAUpo40GPfU/UhWoB0AIti09J5oY2xF0jNt2TUPyd vmwIgodTAvsVg0hUKu1Q9pI63MSkrTM6yuaVDUg79cvN03QAoF/WVPGHgx7zdWwBZ5bZ4gdNe4JSt pIKfxv/3Ft1lrRC3zIBQxN9FjcX/gQKVf1Fdxyx4tTKkqfe6WwEcz+n38v0D1GHt8YoTv1VimOurp i8MxrXxbmOE3h6goJe4PqPs5+tueLxog8sWvCfqdwdA61g8lxppP8SW7cuL6uGfGo4mJrOqA/i+0/ q7JAmIbHTNbU0f3AmrI7DjjjokWNw==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 17 Feb 2022 17:19:44 +0100 Subject: [PULL v2 5/5] 9pfs: Fix segfault in do_readdir_many caused by struct dirent overread To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz 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: none client-ip=91.194.90.13; envelope-from=e64e27d5cb103b7764f1a05b6eda7e7fedd517c5@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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" X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1645116464227100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vitaly Chikunov `struct dirent' returned from readdir(3) could be shorter (or longer) than `sizeof(struct dirent)', thus memcpy of sizeof length will overread into unallocated page causing SIGSEGV. Example stack trace: #0 0x00005555559ebeed v9fs_co_readdir_many (/usr/bin/qemu-system-x86_64 += 0x497eed) #1 0x00005555559ec2e9 v9fs_readdir (/usr/bin/qemu-system-x86_64 + 0x4982e= 9) #2 0x0000555555eb7983 coroutine_trampoline (/usr/bin/qemu-system-x86_64 += 0x963983) #3 0x00007ffff73e0be0 n/a (n/a + 0x0) While fixing this, provide a helper for any future `struct dirent' cloning. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/841 Cc: qemu-stable@nongnu.org Co-authored-by: Christian Schoenebeck Reviewed-by: Dmitry V. Levin Signed-off-by: Vitaly Chikunov Tested-by: Christian Schoenebeck Reviewed-by: Christian Schoenebeck Acked-by: Greg Kurz Tested-by: Vitaly Chikunov Message-Id: <20220216181821.3481527-1-vt@altlinux.org> [C.S. - Fix typo in source comment. ] Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p-synth.c | 18 +++++++++++++++--- hw/9pfs/9p-synth.h | 5 +++++ hw/9pfs/codir.c | 3 +-- include/qemu/osdep.h | 13 +++++++++++++ util/osdep.c | 21 +++++++++++++++++++++ 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c index b38088e066..7a7cd5c5ba 100644 --- a/hw/9pfs/9p-synth.c +++ b/hw/9pfs/9p-synth.c @@ -182,7 +182,12 @@ static int synth_opendir(FsContext *ctx, V9fsSynthOpenState *synth_open; V9fsSynthNode *node =3D *(V9fsSynthNode **)fs_path->data; =20 - synth_open =3D g_malloc(sizeof(*synth_open)); + /* + * V9fsSynthOpenState contains 'struct dirent' which have OS-specific + * properties, thus it's zero cleared on allocation here and below + * in synth_open. + */ + synth_open =3D g_new0(V9fsSynthOpenState, 1); synth_open->node =3D node; node->open_count++; fs->private =3D synth_open; @@ -220,7 +225,14 @@ static void synth_rewinddir(FsContext *ctx, V9fsFidOpe= nState *fs) static void synth_direntry(V9fsSynthNode *node, struct dirent *entry, off_t off) { - strcpy(entry->d_name, node->name); + size_t sz =3D strlen(node->name) + 1; + /* + * 'entry' is always inside of V9fsSynthOpenState which have NAME_MAX + * back padding. Ensure we do not overflow it. + */ + g_assert(sizeof(struct dirent) + NAME_MAX >=3D + offsetof(struct dirent, d_name) + sz); + memcpy(entry->d_name, node->name, sz); entry->d_ino =3D node->attr->inode; entry->d_off =3D off + 1; } @@ -266,7 +278,7 @@ static int synth_open(FsContext *ctx, V9fsPath *fs_path, V9fsSynthOpenState *synth_open; V9fsSynthNode *node =3D *(V9fsSynthNode **)fs_path->data; =20 - synth_open =3D g_malloc(sizeof(*synth_open)); + synth_open =3D g_new0(V9fsSynthOpenState, 1); synth_open->node =3D node; node->open_count++; fs->private =3D synth_open; diff --git a/hw/9pfs/9p-synth.h b/hw/9pfs/9p-synth.h index 036d7e4a5b..eeb246f377 100644 --- a/hw/9pfs/9p-synth.h +++ b/hw/9pfs/9p-synth.h @@ -41,6 +41,11 @@ typedef struct V9fsSynthOpenState { off_t offset; V9fsSynthNode *node; struct dirent dent; + /* + * Ensure there is enough space for 'dent' above, some systems have a + * d_name size of just 1, which would cause a buffer overrun. + */ + char dent_trailing_space[NAME_MAX]; } V9fsSynthOpenState; =20 int qemu_v9fs_synth_mkdir(V9fsSynthNode *parent, int mode, diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c index 032cce04c4..c0873bde16 100644 --- a/hw/9pfs/codir.c +++ b/hw/9pfs/codir.c @@ -143,8 +143,7 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *= fidp, } else { e =3D e->next =3D g_malloc0(sizeof(V9fsDirEnt)); } - e->dent =3D g_malloc0(sizeof(struct dirent)); - memcpy(e->dent, dent, sizeof(struct dirent)); + e->dent =3D qemu_dirent_dup(dent); =20 /* perform a full stat() for directory entry if requested by calle= r */ if (dostat) { diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index d1660d67fa..ce12f64853 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -805,6 +805,19 @@ static inline int platform_does_not_support_system(con= st char *command) } #endif /* !HAVE_SYSTEM_FUNCTION */ =20 +/** + * Duplicate directory entry @dent. + * + * It is highly recommended to use this function instead of open coding + * duplication of @c dirent objects, because the actual @c struct @c dirent + * size may be bigger or shorter than @c sizeof(struct dirent) and correct + * handling is platform specific (see gitlab issue #841). + * + * @dent - original directory entry to be duplicated + * @returns duplicated directory entry which should be freed with g_free() + */ +struct dirent *qemu_dirent_dup(struct dirent *dent); + #ifdef __cplusplus } #endif diff --git a/util/osdep.c b/util/osdep.c index 42a0a4986a..67fbf22778 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -33,6 +33,7 @@ extern int madvise(char *, size_t, int); #endif =20 +#include #include "qemu-common.h" #include "qemu/cutils.h" #include "qemu/sockets.h" @@ -615,3 +616,23 @@ writev(int fd, const struct iovec *iov, int iov_cnt) return readv_writev(fd, iov, iov_cnt, true); } #endif + +struct dirent * +qemu_dirent_dup(struct dirent *dent) +{ + size_t sz =3D 0; +#if defined _DIRENT_HAVE_D_RECLEN + /* Avoid use of strlen() if platform supports d_reclen. */ + sz =3D dent->d_reclen; +#endif + /* + * Test sz for zero even if d_reclen is available + * because some drivers may set d_reclen to zero. + */ + if (sz =3D=3D 0) { + /* Fallback to the most portable way. */ + sz =3D offsetof(struct dirent, d_name) + + strlen(dent->d_name) + 1; + } + return g_memdup(dent, sz); +} --=20 2.20.1