[{"id":3678752,"web_url":"http://patchwork.ozlabs.org/comment/3678752/","msgid":"<87mrz1k5w7.fsf@pond.sub.org>","list_archive_url":null,"date":"2026-04-17T14:39:36","subject":"Re: [PATCH] system: Improve error handling and robustness","submitter":{"id":2645,"url":"http://patchwork.ozlabs.org/api/people/2645/","name":"Markus Armbruster","email":"armbru@redhat.com"},"content":"Jun Yu <yujun@kylinos.cn> writes:\n\n> This commit fixes two important issues:\n>\n> 1. In parse_name(), ensure qemu_name is never NULL by initializing it to\n>    an empty string when the \"guest\" option is not provided. This prevents\n>    potential null pointer dereferences.\n\nCan you point to an actual null pointer dereference?\n\nIf you can't, there is no bug to fix.\n\nIf you can, then your fix needs work.  Here's why.\n\nparse_name() runs when the user passes a -name option.  Your patch\nensures parse_name sets @qemu_name to a non-null string.\n\nWhen it doesn't run, @qemu_name remains null.\n\nThe users of qemu_name check whether it is null.  For instance:\n\n    const char *audio_application_name(void)\n    {\n        const char *vm_name;\n\n        vm_name = qemu_get_vm_name();\n        return vm_name ? vm_name : \"qemu\";\n    }\n\nYour patch breaks such code when -name is passed.\n\n> 2. In parse_add_fd(), replace error_abort with proper error handling\n>    using the provided errp parameter. This avoids immediate program\n>    termination on failure and allows for more graceful error reporting.\n\nThis is insufficient rationale.\n\n&error_abort is a fancy way to write assert().  It's is the appropriate\nway to catch programming errors, i.e. errors that aren't supposed to\nhappen, and when they do happen, there is a bug that needs fixing.\n\nYou'd have to explain why this error is *not* a programming error.  As a\nfirst step, explain how it could happen.\n\nYou can't, because it is in fact a programming error.\nmonitor_fdset_add_fd() only fails when passed a an @fdset_id < 0.\nparse_add_fd() catches that itself a few lines above the call.\n\n> These changes improve the robustness of the QEMU system emulator by\n> providing more predictable error handling and preventing potential\n> crashes.\n\nThis sounds like an AI to me.  Please note that current QEMU project\npolicy is to DECLINE any contributions which are believed to include or\nderive from AI generated content.  See docs/devel/code-provenance.rst\nsection \"Use of AI-generated content\" for why.\n\n> Signed-off-by: Jun Yu <yujun@kylinos.cn>\n> ---\n>  system/vl.c | 9 ++++++++-\n>  1 file changed, 8 insertions(+), 1 deletion(-)\n>\n> diff --git a/system/vl.c b/system/vl.c\n> index 246623b319..eb07b04044 100644\n> --- a/system/vl.c\n> +++ b/system/vl.c\n> @@ -560,6 +560,9 @@ static int parse_name(void *opaque, QemuOpts *opts, Error **errp)\n>      }\n>  \n>      qemu_name = qemu_opt_get(opts, \"guest\");\n> +    if (!qemu_name) {\n> +        qemu_name = \"\";\n> +    }\n>  \n>      proc_name = qemu_opt_get(opts, \"process\");\n>      if (proc_name) {\n> @@ -626,7 +629,11 @@ static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)\n>  \n>      /* add the duplicate fd, and optionally the opaque string, to the fd set */\n>      fdinfo = monitor_fdset_add_fd(dupfd, true, fdset_id, fd_opaque,\n> -                                  &error_abort);\n> +                                  errp);\n> +    if (!fdinfo) {\n> +        close(dupfd);\n> +        return -1;\n> +    }\n>      g_free(fdinfo);\n>  \n>      return 0;","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=NMJAkGDV;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fxyGS5SFyz1yD3\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 00:40:16 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wDkMH-0003Oz-I4; Fri, 17 Apr 2026 10:39:49 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <armbru@redhat.com>) id 1wDkMG-0003Oo-7O\n for qemu-devel@nongnu.org; Fri, 17 Apr 2026 10:39:48 -0400","from us-smtp-delivery-124.mimecast.com ([170.10.129.124])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <armbru@redhat.com>) id 1wDkME-0005cS-Eq\n for qemu-devel@nongnu.org; Fri, 17 Apr 2026 10:39:47 -0400","from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-455-tcQrB4tHOCOigZ3R2kWP_g-1; Fri,\n 17 Apr 2026 10:39:41 -0400","from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 173DE1800464; Fri, 17 Apr 2026 14:39:40 +0000 (UTC)","from blackfin.pond.sub.org (unknown [10.44.22.4])\n by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id 9CE93195608E; Fri, 17 Apr 2026 14:39:39 +0000 (UTC)","by blackfin.pond.sub.org (Postfix, from userid 1000)\n id E74A821E6A28; Fri, 17 Apr 2026 16:39:36 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776436784;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=u2H6ont24s/tEJdHct1r+q8YkBP2G1W56q9PhJOwKjU=;\n b=NMJAkGDVcIJHrANbdot/YA+B93drbiimCQ/xoVIJ5SsRkvcP1Vr1nqilFHTYDj5JXdFOze\n Cp4lOJIdMpJrKeFXVS+oyaXSwGhm6g+PeFSXXLXgGveceSXiN6OOJcEHNLiiUeshhHWX7s\n WdBUwfP0gdVOGe36eDsAJSBmE39tYnw=","X-MC-Unique":"tcQrB4tHOCOigZ3R2kWP_g-1","X-Mimecast-MFC-AGG-ID":"tcQrB4tHOCOigZ3R2kWP_g_1776436780","From":"Markus Armbruster <armbru@redhat.com>","To":"Jun Yu <yujun@kylinos.cn>","Cc":"pbonzini@redhat.com,  qemu-devel@nongnu.org","Subject":"Re: [PATCH] system: Improve error handling and robustness","In-Reply-To":"<20260408022507.27457-1-yujun@kylinos.cn> (Jun Yu's message of\n \"Wed, 8 Apr 2026 10:25:07 +0800\")","References":"<20260408022507.27457-1-yujun@kylinos.cn>","Date":"Fri, 17 Apr 2026 16:39:36 +0200","Message-ID":"<87mrz1k5w7.fsf@pond.sub.org>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","Content-Type":"text/plain","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.17","Received-SPF":"pass client-ip=170.10.129.124; envelope-from=armbru@redhat.com;\n helo=us-smtp-delivery-124.mimecast.com","X-Spam_score_int":"-25","X-Spam_score":"-2.6","X-Spam_bar":"--","X-Spam_report":"(-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\n SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"}}]