From nobody Sat May 4 17:29:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615300030; cv=none; d=zohomail.com; s=zohoarc; b=K99f7UepelRvPiRpTqABRGI1/ERm33+liA+9ytXWPRpq43eQPxPTWymDIwziy/dAeRBvvTZr5TTohnum9bNfwGS0lYnk1qliy6tKQ8+EYdyqe1ssPoKLXhJGJGZc9rCvVf0dG2lkqBE1F0V1k2wdG4DCasLXawv1ZSit2b1O06s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615300030; h=Content-Type:Content-Transfer-Encoding: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=G+sZYRbmxAJd4eLyhVjCMX+B0N1H0nqZKnkFIYUOk2k=; b=ZRoAp9cY68qmsSppjT1d7Z+AtwAfWu7JSlpa86xB9bWrwFWtoLBzcJ6jMYflmYCFU95/cWdhmqm7b1KavzJbSdpAufvbsJ7YGYC/SgevmdkeOxiCiaEbrkALtiCOT2eX5JzSk66iKrxMK/0q0aJoCiJyOcbOI6J559b54s3atR0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1615300030410242.625721346006; Tue, 9 Mar 2021 06:27:10 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-483-iXxhm_c6OuqhTrAJ6B6ktQ-1; Tue, 09 Mar 2021 09:26:43 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D52821934104; Tue, 9 Mar 2021 14:26:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9D3735C233; Tue, 9 Mar 2021 14:26:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 09E9B57DC2; Tue, 9 Mar 2021 14:26:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 129EQV0M016587 for ; Tue, 9 Mar 2021 09:26:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id AECD0196E3; Tue, 9 Mar 2021 14:26:31 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31E87104FF for ; Tue, 9 Mar 2021 14:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615300029; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=G+sZYRbmxAJd4eLyhVjCMX+B0N1H0nqZKnkFIYUOk2k=; b=QKoeQwzjYBvfiVn/Mc3LlTy5/Uw093SeTxORXi9N/W4OqQQnS0YlG1EOwA8szYfc9UDlAQ UAky4tMd96ISeSHkD+vuhnZ5ytAVaZfTjlON6y6mWAMkwrZNP+FVPhl7+uGr5r2CCg1fjx Up7O+pzzZDbN24xfX4iuO85JEArB1QQ= X-MC-Unique: iXxhm_c6OuqhTrAJ6B6ktQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/4] qemu_shim: Replace g_file_get_contents() with virFileReadAll() Date: Tue, 9 Mar 2021 15:26:22 +0100 Message-Id: <308f65cc9f839b32d6e225beec9e05ae1102ed4c.1615299876.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The qemu_shim (compiled into virt-qemu-run-binary) reads several files provided by user (XML definition of secret, value of the secret, XML definition of domain) and it does so using g_file_get_contents(). This is potentially dangerous, because there is no limit on the size of files/buffers. Since this is a standalone binary it's not critical as it can't cause libvirtd to be OOM killed, but it's still worth fixing as I am planning on discouraging people from using the GLib function. Signed-off-by: Michal Privoznik --- src/qemu/qemu_shim.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_shim.c b/src/qemu/qemu_shim.c index c10598df4b..1b0c41a9d2 100644 --- a/src/qemu/qemu_shim.c +++ b/src/qemu/qemu_shim.c @@ -31,6 +31,10 @@ =20 #define VIR_FROM_THIS VIR_FROM_QEMU =20 +/* Below, several files are read into buffers. This defines the + * maximum possible size for such buffer. 10MiB should be enough. */ +#define MAX_FILE_SIZE (10 * 1024 * 1024) + static GMutex eventLock; static bool eventPreventQuitFlag; static bool eventQuitFlag; @@ -264,7 +268,7 @@ int main(int argc, char **argv) g_autofree char *sxml =3D NULL; g_autofree char *value =3D NULL; virSecretPtr sec; - size_t nvalue; + int nvalue; =20 if (!bits || bits[0] =3D=3D NULL || bits[1] =3D=3D NULL) { g_printerr("%s: expected a pair of filenames for --secret = argument\n", @@ -276,15 +280,15 @@ int main(int argc, char **argv) g_printerr("%s: %lld: loading secret %s and %s\n", argv[0], deltams(), bits[0], bits[1]); =20 - if (!g_file_get_contents(bits[0], &sxml, NULL, &error)) { + if (virFileReadAll(bits[0], MAX_FILE_SIZE, &sxml) < 0) { g_printerr("%s: cannot read secret XML %s: %s\n", - argv[0], bits[0], error->message); + argv[0], bits[0], virGetLastErrorMessage()); goto cleanup; } =20 - if (!g_file_get_contents(bits[1], &value, &nvalue, &error)) { + if ((nvalue =3D virFileReadAll(bits[1], MAX_FILE_SIZE, &value)= ) < 0) { g_printerr("%s: cannot read secret value %s: %s\n", - argv[0], bits[1], error->message); + argv[0], bits[1], virGetLastErrorMessage()); goto cleanup; } =20 @@ -332,9 +336,9 @@ int main(int argc, char **argv) g_printerr("%s: %lld: fetching guest config %s\n", argv[0], deltams(), argv[1]); =20 - if (!g_file_get_contents(argv[1], &xml, NULL, &error)) { + if (virFileReadAll(argv[1], MAX_FILE_SIZE, &xml) < 0) { g_printerr("%s: cannot read %s: %s\n", - argv[0], argv[1], error->message); + argv[0], argv[1], virGetLastErrorMessage()); goto cleanup; } =20 --=20 2.26.2 From nobody Sat May 4 17:29:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615300006; cv=none; d=zohomail.com; s=zohoarc; b=HJv28UtS/Bt0dWtUip+VPXAMBMhTu0Uq7g9MxfUZJ9CILci1VFbMjgT6ecCq1Z6itH/Un/P+IM4i0JF0BPlEOh0SgBFUC3JqQ4v6AL7AU7XoAsRy8yAYpUb7gBB2HzHl2IfSwpWTCF1OwvLmkxzt21mjzYX/Yse9vEZIHusgSn4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615300006; h=Content-Type:Content-Transfer-Encoding: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=5rpKT0p7x0n3kZ6Nttqy1UmKFNro/RdoZT6z1p/5PgI=; b=W0wjJwPRDdqAtWfw0Vwmp112IFBqIr8P11ydymhgWenzzB4OvCLzFbGJrotpOI9qbwnNQJVGltAaPa9XkcpaNPEWd5D0YFTOu7DSGC+H3vJ+BJJ4D3+gED9qqMA7IMmFIe8FxHx5l5CjpGJZbBFMOTa2xOrZ4G6A9CbzsC+FxfQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1615300006839389.4198722113673; Tue, 9 Mar 2021 06:26:46 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-483-rsv5zzuYP3C8mRM_SM6Yrg-1; Tue, 09 Mar 2021 09:26:43 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EFE93108BD07; Tue, 9 Mar 2021 14:26:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CC6C45D9CD; Tue, 9 Mar 2021 14:26:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C56FB1809C8B; Tue, 9 Mar 2021 14:26:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 129EQWVh016597 for ; Tue, 9 Mar 2021 09:26:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id 89DF6196E3; Tue, 9 Mar 2021 14:26:32 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CF4C104FF for ; Tue, 9 Mar 2021 14:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615300005; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=5rpKT0p7x0n3kZ6Nttqy1UmKFNro/RdoZT6z1p/5PgI=; b=dpYPbc0pBD59iTognbyo0w6oWhxHjlSUC4EIMNRWEVjmoNsl5plxdqCO9Ts1LceOJ+C+G6 RRJdC44sZJX1vKsUOYWnlKr6LC0e4oEqWFMpZQ5BQI/hQ53gVNvioF0AjWtqi1FokCFY7a hIbapRl0BnDnZzLFTmwbOyUbOElNGbY= X-MC-Unique: rsv5zzuYP3C8mRM_SM6Yrg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/4] virutil: Do not use g_get_host_name() to obtain hostname Date: Tue, 9 Mar 2021 15:26:23 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The problem is that g_get_host_name() caches the hostname in a thread local variable. Therefore, it doesn't reflect any subsequent hostname changes. While this might be acceptable for logs where the hostname is printed exactly once when the libvirtd starts up, it is not optimal for virGetHostnameImpl() which is what our public virConnectGetHostname() API calls. If the hostname at the moment of the first API invocation happens to be "localhost" or contains a dot, then no further hostname changes will ever be reflected. This reverts 26d9748ff11, partially. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/util/virutil.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index 227997c7be..118ceec0db 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -475,11 +475,17 @@ static char * virGetHostnameImpl(bool quiet) { int r; - const char *hostname; - char *result =3D NULL; + char hostname[HOST_NAME_MAX+1], *result =3D NULL; struct addrinfo hints, *info; =20 - hostname =3D g_get_host_name(); + r =3D gethostname(hostname, sizeof(hostname)); + if (r =3D=3D -1) { + if (!quiet) + virReportSystemError(errno, + "%s", _("failed to determine host name")); + return NULL; + } + NUL_TERMINATE(hostname); =20 if (STRPREFIX(hostname, "localhost") || strchr(hostname, '.')) { /* in this case, gethostname returned localhost (meaning we can't --=20 2.26.2 From nobody Sat May 4 17:29:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615300020; cv=none; d=zohomail.com; s=zohoarc; b=ZtiNjbMlzCKXKzIF+pqU7sOO7DPYTWYSrUNgjyDQGuRP2gepMve/wKTsHW12opj1W8fgMtUWOlQqJTVMomE06u2ildVcN0qcqfMQMc4gqP6qP1Ab8WyOnHth96WRR/qpCGuA+MS+9uj/kVAOVJy8UnMttgI8NfUr6AR3X26HAbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615300020; h=Content-Type:Content-Transfer-Encoding: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=zt/TU8oaxyHsjg4IfSWdx+iewCR6DRlUoTLL7pkNB2I=; b=aOyDCdkt5dcJQmOyzj8QqcGtGWH4rjOosMzjQ1vaLVqcDQK9p9Z+IZH9KGXN/0w31LctA7v3POAT15CgIY8O45xl3ST6laPwZCNu0pI8HclMIw5s7GEb/uzX9x1QqJ1L5W1vc6I9rRfBAEMuevGz+SokfQaNL3WQSHIq6kcnj5s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1615300020160127.4922373089504; Tue, 9 Mar 2021 06:27:00 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-318-40J4U4XAOPGETR7Ay604-A-1; Tue, 09 Mar 2021 09:26:55 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 30A921018F7B; Tue, 9 Mar 2021 14:26:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D9386062F; Tue, 9 Mar 2021 14:26:48 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C669A57DC6; Tue, 9 Mar 2021 14:26:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 129EQXEm016603 for ; Tue, 9 Mar 2021 09:26:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 65D5A104FF; Tue, 9 Mar 2021 14:26:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB088196E3 for ; Tue, 9 Mar 2021 14:26:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615300019; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=zt/TU8oaxyHsjg4IfSWdx+iewCR6DRlUoTLL7pkNB2I=; b=TOOHpzEwjnAn54+Wose7Bsj6gGmsY/LfIVtJHSOM6IOwIcwN6bgvbYEbbwkkp8Frfsk5Mf H7wAYP473iU5Eev4HC/epPk3B69jbtE5mg2FEoLAkY+y+qNdl0hCqPXSfexQJj4kwB7CXi mQGm6w9nWgXkTEJ/3+XUfVrGapI3+/k= X-MC-Unique: 40J4U4XAOPGETR7Ay604-A-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/4] syntax-check: Update list of gethostname exceptions Date: Tue, 9 Mar 2021 15:26:24 +0100 Message-Id: <4f659ab27edb51852304d5685c8157dd7fa65766.1615299876.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The only place where gethostname() is acceptable is in virGetHostnameImpl() which lives in src/util/virutil.c. Reflect this in the list of exceptions for the syntax-check rule. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- build-aux/syntax-check.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 2f4f932a5b..794ec326e4 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1910,7 +1910,7 @@ exclude_file_name_regexp--sc_prohibit_empty_lines_at_= EOF =3D \ exclude_file_name_regexp--sc_prohibit_fork_wrappers =3D \ (^(src/(util/(vircommand|virdaemon)|lxc/lxc_controller)|tests/testutils)= \.c$$) =20 -exclude_file_name_regexp--sc_prohibit_gethostname =3D ^src/util/vir(util|l= og)\.c$$ +exclude_file_name_regexp--sc_prohibit_gethostname =3D ^src/util/virutil\.c= $$ =20 exclude_file_name_regexp--sc_prohibit_internal_functions =3D \ ^src/(util/(viralloc|virutil|virfile)\.[hc]|esx/esx_vi\.c)$$ --=20 2.26.2 From nobody Sat May 4 17:29:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615300021; cv=none; d=zohomail.com; s=zohoarc; b=T2YtUZqwnCQcN7x7ybUd/gGD8OcbEm+VY2wyTzBONYdmOM8obYed+bLTxiXeciE6XBUylZjln8yElMNQEnKScpdQBBgYhH6a2vV9tQLK3ePab8a+vqEA8BZrMmUiaqRoBP/qEIf3eGdfGKLD42J7e7muLAVFE2iXg08HkOhXu78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615300021; h=Content-Type:Content-Transfer-Encoding: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=Ii+aIpNh8KjUjOanF1+j4SJSyGHr/Q8ZDmQZlEMPYPc=; b=UX82fWsTwOHGQDuW39p25rMOGeoSfo4vzrIij9+CR+liKOkdt1nNEv8vUT41QIiaOata6OAD6auPnVqBv/VhbVkjnAqw0lKQ3y96PRvJvme9ND/8ttDF1zvK3coRkenYhj0UijrZZoiZxfwEFZ2TD0WSlJ354YX+DqaU7rrHB90= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1615300021013341.14677439143395; Tue, 9 Mar 2021 06:27:01 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-134-dD9EUFIROgSd-VfouZsUyg-1; Tue, 09 Mar 2021 09:26:57 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 50C921934105; Tue, 9 Mar 2021 14:26:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 29D3160C13; Tue, 9 Mar 2021 14:26:51 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E0C851809C8C; Tue, 9 Mar 2021 14:26:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 129EQYtp016612 for ; Tue, 9 Mar 2021 09:26:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4040B104FF; Tue, 9 Mar 2021 14:26:34 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id B72EA196E3 for ; Tue, 9 Mar 2021 14:26:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615300019; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Ii+aIpNh8KjUjOanF1+j4SJSyGHr/Q8ZDmQZlEMPYPc=; b=PUtKyDPAquXkq50QykQfWS3JK5Y/URykFRocMwTJs4cghaK0+usFcmKvIHdZQ+60JzTms1 ErV67oPU95eW4Gaar5kEfrh5y8joNxeki/1/iVouG8PSewmlnW3GNDf+9V+6TNjlJUBBPR cDBWY+jP5JVUzpopg91cEspCOPKxkU8= X-MC-Unique: dD9EUFIROgSd-VfouZsUyg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/4] docs: Discourage use of some glib functions Date: Tue, 9 Mar 2021 15:26:25 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Unfortunately, not all GLib functions provide the level of security we want, or behave how we want. So far, g_file_get_contents() and g_get_host_name() have been identified. Signed-off-by: Michal Privoznik --- docs/glib-adoption.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/glib-adoption.rst b/docs/glib-adoption.rst index f969ac80a1..bbc27fed6d 100644 --- a/docs/glib-adoption.rst +++ b/docs/glib-adoption.rst @@ -52,3 +52,20 @@ Objects https://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type= .html =20 Prefer ``GObject`` instead. + + +Forbidden functions +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +There are some functions where Libvirt offers superior quality to GLib. In +those cases, GLib functions must NOT be used and Libvirt functions should = be +used instead. + +``g_file_get_contents`` + Use ``virFileReadAll`` instead. The GLib function reads the entire file + into the memory without possibility to provide any limit on the buffer + size. + +``g_get_host_name`` + Prefer ``virGetHostname``. The GLib function caches the hostname and t= hus + does not reflect (possible) hostname changes. --=20 2.26.2