From nobody Thu Nov 28 08:30:29 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 ARC-Seal: i=1; a=rsa-sha256; t=1693715634; cv=none; d=zohomail.com; s=zohoarc; b=hccrSh461tQgLxRkOOtUyGMR7SWfXs1fdFQGu4xzaKgGD3TEdL1nlr3xESrwhQVF1IL+ziILW7pp/xTV9bAVZAx0HhLAayhEQ/VzcQAzbqkf9VnjEJxBgeTa4KOyimskiK9romrnPBq9n3gkx5I6xDcw63SfTZANCgroG56Zm7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693715634; 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; bh=z/aZ16AuCEo7wpubooP4JHdg7IKFA98mYu/To/TblDc=; b=PVIEmEyNTLBRFv0I4uT2MYlDJYODx8JNgD1d7xVKfe6e2jz/7TkV5gLJNJEOkb2RJBWqwbKxAVNLT8TmWmAyxHew3yeKERQyHdRNqkp3G3hX6oCATzaHVEnFUVMGknMwKjWzToh4YT7m2+hjVJMJ5a06JjU4eCwVr+rB51q0mRs= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693715634373826.4851969698284; Sat, 2 Sep 2023 21:33:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qcem2-0002Eu-9n; Sun, 03 Sep 2023 00:31:46 -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 1qcelu-0002DJ-UW for qemu-devel@nongnu.org; Sun, 03 Sep 2023 00:31:42 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qcelr-0006va-4K for qemu-devel@nongnu.org; Sun, 03 Sep 2023 00:31:38 -0400 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-26f3975ddd4so270213a91.1 for ; Sat, 02 Sep 2023 21:31:34 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id iz2-20020a170902ef8200b001bb9f104328sm5295792plb.146.2023.09.02.21.31.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Sep 2023 21:31:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1693715493; x=1694320293; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=z/aZ16AuCEo7wpubooP4JHdg7IKFA98mYu/To/TblDc=; b=0npzz2ObQNRkZi4Eh38hHblL59dVrtwiw2oQClBOrUmpDWuqBo/47ygOCJ3Ab9J5O5 DX2SZMekHBClpSlGIR5qOQPqAbpsXGz4QXS16Y2gVG5GTbzmd2AVfd878z0goGzkGW2V IrhpQ5BmTILRwMDlHtMsIDl77O7+FmE7BcTvwSmr1GZRfY94cqVKKqqbW1d7oGw7cnSf 8BENLVoMPQDJSurPCEraZzg6IIZs/wBcyvsaOseLkuintGhHpBrgc5wbSwV8ONdPORit 8uL5kx1sBmy1mbvpfTNzZXcUy49PsF8U6yYRA27cHpBNRFeEE8W/IVMZW/s7CmKcJsLu 301w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693715493; x=1694320293; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z/aZ16AuCEo7wpubooP4JHdg7IKFA98mYu/To/TblDc=; b=XKBLeM8el1JH7GXPcZPUvXiGcuimPe4FuYuOnSAGRHn6K+eLeFwPSZiChTtnfHOVCy 5pQfAy5QIIljurO/0+u9xLG+YM05+HdlEgEefYfbZ32xp4W8cSubbC9/ETUnxHH7SBJh PKJoZUXGtvUx2WcRDfBvjZjIP6Zkb/v6yLiKMA+mLc7CpcDncGr05xeec3bEdT/lbkGC 4YIB76o4/X3fyVb10sqUD0coOlHp8Z+/RWWGdwuBq4rQ7agXDY7HbsrUnUBJk43vp3CM EQrbikzUdneMyTpICOO1Fu9rI6XRyhN9kTZ7XxTz1nDi4jMDk769NdhJas31/PXj2wj+ 0nqQ== X-Gm-Message-State: AOJu0YwPksWtG4YzI7LIRcwfZ2kWVE+AfN6jR/te02L3RQuB7HZICr55 /pdFJWRKKt4fAZQrefuBUC6+Ew== X-Google-Smtp-Source: AGHT+IGpUlqXdUGU543EtzTNpwbZyZkf86NKdkwWU8r8yW+vJCJ61u2R3VbTHYN/X8Ykc9YUKIDPgg== X-Received: by 2002:a17:90b:33d1:b0:25e:a8ab:9157 with SMTP id lk17-20020a17090b33d100b0025ea8ab9157mr5715886pjb.22.1693715493660; Sat, 02 Sep 2023 21:31:33 -0700 (PDT) From: Akihiko Odaki To: Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mikhail Tyutin , Aleksandr Anenkov , qemu-devel@nongnu.org, Akihiko Odaki , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 5/8] gdbstub: Dynamically allocate target.xml buffer Date: Sun, 3 Sep 2023 13:30:15 +0900 Message-ID: <20230903043030.20708-6-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230903043030.20708-1-akihiko.odaki@daynix.com> References: <20230903043030.20708-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: none client-ip=2607:f8b0:4864:20::1035; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1035.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: 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 @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1693715634748100001 There is no guarantee that target.xml fits in 1024 bytes, and the fixed buffer length requires tedious buffer overflow check. Dynamically allocate the target.xml buffer to resolve these problems. Suggested-by: Alex Benn=C3=A9e Signed-off-by: Akihiko Odaki --- gdbstub/internals.h | 2 +- gdbstub/gdbstub.c | 44 ++++++++++++++++++++++++-------------------- gdbstub/softmmu.c | 2 +- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/gdbstub/internals.h b/gdbstub/internals.h index f2b46cce41..4876ebd74f 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -33,7 +33,7 @@ typedef struct GDBProcess { uint32_t pid; bool attached; =20 - char target_xml[1024]; + char *target_xml; } GDBProcess; =20 enum RSState { diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 78711801db..3f97dc66e5 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -367,33 +367,37 @@ static const char *get_feature_xml(const char *p, con= st char **newp, =20 name =3D NULL; if (strncmp(p, "target.xml", len) =3D=3D 0) { - char *buf =3D process->target_xml; - const size_t buf_sz =3D sizeof(process->target_xml); - /* Generate the XML description for this CPU. */ - if (!buf[0]) { + if (!process->target_xml) { + g_autoptr(GPtrArray) a =3D g_ptr_array_new_with_free_func(g_fr= ee); GDBRegisterState *r; =20 - pstrcat(buf, buf_sz, - "" - "" - ""); + g_ptr_array_add( + a, + g_strdup("" + "" + "")); if (cc->gdb_arch_name) { - pstrcat(buf, buf_sz, ""); - pstrcat(buf, buf_sz, cc->gdb_arch_name(cpu)); - pstrcat(buf, buf_sz, ""); + g_ptr_array_add( + a, + g_markup_printf_escaped("%s", + cc->gdb_arch_name(cpu))); } - pstrcat(buf, buf_sz, "gdb_core_xml_file); - pstrcat(buf, buf_sz, "\"/>"); + g_ptr_array_add( + a, + g_markup_printf_escaped("", + cc->gdb_core_xml_file)); for (r =3D cpu->gdb_regs; r; r =3D r->next) { - pstrcat(buf, buf_sz, "xml); - pstrcat(buf, buf_sz, "\"/>"); + g_ptr_array_add( + a, + g_markup_printf_escaped("", + r->xml)); } - pstrcat(buf, buf_sz, ""); + g_ptr_array_add(a, g_strdup("")); + g_ptr_array_add(a, NULL); + process->target_xml =3D g_strjoinv(NULL, (void *)a->pdata); } - return buf; + return process->target_xml; } if (cc->gdb_get_dynamic_xml) { char *xmlname =3D g_strndup(p, len); @@ -2199,6 +2203,6 @@ void gdb_create_default_process(GDBState *s) process =3D &s->processes[s->process_num - 1]; process->pid =3D pid; process->attached =3D false; - process->target_xml[0] =3D '\0'; + process->target_xml =3D NULL; } =20 diff --git a/gdbstub/softmmu.c b/gdbstub/softmmu.c index f509b7285d..5282324764 100644 --- a/gdbstub/softmmu.c +++ b/gdbstub/softmmu.c @@ -293,7 +293,7 @@ static int find_cpu_clusters(Object *child, void *opaqu= e) assert(cluster->cluster_id !=3D UINT32_MAX); process->pid =3D cluster->cluster_id + 1; process->attached =3D false; - process->target_xml[0] =3D '\0'; + process->target_xml =3D NULL; =20 return 0; } --=20 2.42.0