From patchwork Sat Sep 30 23:39:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viktor Prutyanov X-Patchwork-Id: 13405248 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 37E16E748E6 for ; Sat, 30 Sep 2023 23:40:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmjYk-0006xC-9k; Sat, 30 Sep 2023 19:39:42 -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 1qmjYi-0006wx-BD for qemu-devel@nongnu.org; Sat, 30 Sep 2023 19:39:40 -0400 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmjYg-0004od-L4 for qemu-devel@nongnu.org; Sat, 30 Sep 2023 19:39:40 -0400 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-503f39d3236so23812844e87.0 for ; Sat, 30 Sep 2023 16:39:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696117176; x=1696721976; 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=92fSRc4tFlSTM5OlZs0crcqNCe9FLrZqT3dnztjQ4gQ=; b=CnZhoL6jAWLcjLvBYwVvnOOI1t9KkmazzIZHZ3UF67FdxmG0hMFf5NWwAGJAAJPUtH ecXgneR/LdtXpGQxR6xkGs6/F90akni51yorMeeqAteIxzuBUF1H2xbXHP+j7WHynTo9 259yB8Kx5nSpeVdfr1HBtFEtgQOjUA/q6/PF17JuFw81pyd4IPmQIWqAJ/O1kN34j74g sKpmAZGckEtO4zUxtoOfXkjk6+ylKv1sgEdybtQuC/K2iB3hzITSgGCmhOI5m1kK0n9g 7mepOZNhfqfHcAyf6EGt6phgchD6nwzZnvs23IHx4jDhN+4BxPF5ZEvexPDjoihCHtEi ITwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696117176; x=1696721976; 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=92fSRc4tFlSTM5OlZs0crcqNCe9FLrZqT3dnztjQ4gQ=; b=j/OtumPoWHWxCt1o3E4diO7xRjrIiwMccTiT30Mg804jsMwgiwO7RwF72vcK2UzWtY F1dd377LdnZ0Rp9Lh9A3pIGQWesd29USqM3WfX4khme4R/EJObdZDPwbQPqnJw23h5HJ 87AhokMCkT035YnfokdPOjIK2l3DhqD8NUJYQ4eS2G2jUsxpz7Z8jJVcG4YM7EjzGLRq 8xoBsav8wNq4Ve9pY9YD5MiMHiCJUH00TlKu/Y4K2yigMjRTmO6qg4SdkYnzsVu3x6ts kBlaU87S/3CF6NLHts50w8WlaqqwzXRzo95U3sf9KDmF0lbSMfoiTj0xCgA/v/QPd1kf RTHw== X-Gm-Message-State: AOJu0YzWQgFNm1AczGv63LcsBTDoy81297HYPz7BcuVUukGdBdNZK2aW JN8BZEKOEcsCu3my0R9Ji8G53Q== X-Google-Smtp-Source: AGHT+IHw2+8Ja38PjhChd0rvd+Yr0dfH3EQrsgR9HvQw+jej0/ku6+/DWiIxuU0HEzYt8FQ7MhaiSQ== X-Received: by 2002:a19:e051:0:b0:4fe:711:2931 with SMTP id g17-20020a19e051000000b004fe07112931mr5573403lfj.22.1696117175635; Sat, 30 Sep 2023 16:39:35 -0700 (PDT) Received: from localhost.localdomain (109-252-90-8.nat.spd-mgts.ru. [109.252.90.8]) by smtp.gmail.com with ESMTPSA id c19-20020a197613000000b005033948f108sm4013429lff.272.2023.09.30.16.39.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 16:39:35 -0700 (PDT) From: Viktor Prutyanov To: peter.maydell@linaro.org Cc: qemu-devel@nongnu.org, akihiko.odaki@daynix.com, yan@daynix.com, viktor@daynix.com, viktor.prutyanov@phystech.edu Subject: [PATCH 1/2] elf2dmp: limit print length for sign_rsds Date: Sun, 1 Oct 2023 02:39:21 +0300 Message-Id: <20230930233922.9969-2-viktor@daynix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20230930233922.9969-1-viktor@daynix.com> References: <20230930233922.9969-1-viktor@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2a00:1450:4864:20::12c; envelope-from=viktor@daynix.com; helo=mail-lf1-x12c.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Viktor Prutyanov String sign_rsds isn't terminated, so the print length must be limited. Signed-off-by: Viktor Prutyanov --- contrib/elf2dmp/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 5db163bdbe..6de5c9808e 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -478,7 +478,7 @@ static bool pe_check_pdb_name(uint64_t base, void *start_addr, } if (memcmp(&rsds->Signature, sign_rsds, sizeof(sign_rsds))) { - eprintf("CodeView signature is \'%.4s\', \'%s\' expected\n", + eprintf("CodeView signature is \'%.4s\', \'%.4s\' expected\n", rsds->Signature, sign_rsds); return false; } From patchwork Sat Sep 30 23:39:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viktor Prutyanov X-Patchwork-Id: 13405247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CDB55E748F1 for ; Sat, 30 Sep 2023 23:40:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmjYk-0006xE-8N; Sat, 30 Sep 2023 19:39:42 -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 1qmjYi-0006ww-8B for qemu-devel@nongnu.org; Sat, 30 Sep 2023 19:39:40 -0400 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmjYg-0004oe-H5 for qemu-devel@nongnu.org; Sat, 30 Sep 2023 19:39:39 -0400 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-5044dd5b561so18428325e87.1 for ; Sat, 30 Sep 2023 16:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696117176; x=1696721976; 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=lLnZw8JrJfZxACNFwjppPjGwFqVUzz0U+VS935cCEJg=; b=EP9iWfSd9YcIiGd4H5KoCOoHOO0G5CwR8k62EBVYbESC/HMRCrcv9E5YLjEvPQw/Lx JwcECdqagq3I6FrsvVfqyN3vC96EgG/LM091dJrwqNE8Dg0B/gjc8nsXJv3nMoq8zO0O 35w+SfTnspBpWPlmGJyIjOx9HZxt2UQZnyekB2xXWXnfLP+3fyKwF2Rrk40Qb1wGdh8K j3uKKiZLYrUABtfamkRBKUeGgURMIh39ZGeRinaeH1L/HP2vMlT/TQgUt3lbUX/jRYXt DPSpil4AP8vu0fqpkBMd7FyOjg1jrzxGIQlDJHM/B3TuZt0LDFYlyjjdlDe0XfAl/4g1 Uz9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696117176; x=1696721976; 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=lLnZw8JrJfZxACNFwjppPjGwFqVUzz0U+VS935cCEJg=; b=HLcY1GMG8GP2c3b+1f0Twdsz9AunsdDvdgNVopkAMr4gUJJObd6NRLZQd2okm/hTIK 7fMNVSMoxEGmTGEMeScF+UQe1ErkhSE9zt7QUzQpuV+UU5PJJNxoKbCRb+xnyxeyJUg/ j1iALpQbCQdv3voMr9KD+5pAgiIukcJ+JJtRXEdwSMCrFvRPhGfjzEuPIqI4TrPq4S4F w8DSWjbbd9TkMCdzrmnlKj3XHjSPtKneqy4m7Xc04fozvuGePvdewQx8fX0iQJOkiz1r qqBsiGCzulI1DVw3RPrOkXqlVTjxFgv86i4+2KHzVDug648op1TJ9vTLPXN1yRWwlm4i yxQA== X-Gm-Message-State: AOJu0YyQS34xeKNA9cAU/EGWD0v9BcLmSVZ9gSWeknNtneBSnyhAPO98 nvk6xCnVht8ha5+dmdVQiKEmLw== X-Google-Smtp-Source: AGHT+IEpPI4Vgt47yCWUmx4SuHgP2ZbXv5wgNMvZ6jMHsUV12+OXRgSr/QbRJ6fZ9OZ1o89NEUIdXA== X-Received: by 2002:a05:6512:3118:b0:500:c2d8:a2a2 with SMTP id n24-20020a056512311800b00500c2d8a2a2mr6070385lfb.46.1696117176370; Sat, 30 Sep 2023 16:39:36 -0700 (PDT) Received: from localhost.localdomain (109-252-90-8.nat.spd-mgts.ru. [109.252.90.8]) by smtp.gmail.com with ESMTPSA id c19-20020a197613000000b005033948f108sm4013429lff.272.2023.09.30.16.39.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 16:39:35 -0700 (PDT) From: Viktor Prutyanov To: peter.maydell@linaro.org Cc: qemu-devel@nongnu.org, akihiko.odaki@daynix.com, yan@daynix.com, viktor@daynix.com, viktor.prutyanov@phystech.edu Subject: [PATCH 2/2] elf2dmp: check array bounds in pdb_get_file_size Date: Sun, 1 Oct 2023 02:39:22 +0300 Message-Id: <20230930233922.9969-3-viktor@daynix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20230930233922.9969-1-viktor@daynix.com> References: <20230930233922.9969-1-viktor@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2a00:1450:4864:20::129; envelope-from=viktor@daynix.com; helo=mail-lf1-x129.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Index in file_size array must be checked against num_files, because the entries we are looking for may be absent in the PDB. Signed-off-by: Viktor Prutyanov --- contrib/elf2dmp/pdb.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c index 6ca5086f02..8e3c18c82f 100644 --- a/contrib/elf2dmp/pdb.c +++ b/contrib/elf2dmp/pdb.c @@ -25,6 +25,10 @@ static uint32_t pdb_get_file_size(const struct pdb_reader *r, unsigned idx) { + if (idx >= r->ds.toc->num_files) { + return 0; + } + return r->ds.toc->file_size[idx]; } @@ -159,16 +163,17 @@ static void *pdb_ds_read_file(struct pdb_reader* r, uint32_t file_number) static int pdb_init_segments(struct pdb_reader *r) { - char *segs; unsigned stream_idx = r->segments; - segs = pdb_ds_read_file(r, stream_idx); - if (!segs) { + r->segs = pdb_ds_read_file(r, stream_idx); + if (!r->segs) { return 1; } - r->segs = segs; r->segs_size = pdb_get_file_size(r, stream_idx); + if (!r->segs_size) { + return 1; + } return 0; }