public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] sim/ppc: initialize a memory buffer in all cases
Date: Mon, 24 Oct 2022 16:13:58 +0000 (GMT)	[thread overview]
Message-ID: <20221024161404.C8068385840C@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=548d634f1b61571f118c3133ce0e8986714c8fd6

commit 548d634f1b61571f118c3133ce0e8986714c8fd6
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Wed Oct 19 15:07:40 2022 +0100

    sim/ppc: initialize a memory buffer in all cases
    
    In the ppc simulator's do_fstat function, which provides the fstat
    call for the simulator, if the fstat is going to fail then we
    currently write an uninitialized buffer into the simulated target.
    
    In theory, I think this is fine, we also write the error status into
    the simulated target, so, given that the fstat has failed, the target
    shouldn't be relying on the buffer contents.
    
    However, writing an uninitialized buffer means we might leak simulator
    private data into the simulated target, which is probably a bad thing.
    Plus it probably makes life easier if something consistent, like all
    zeros, is written rather than random junk, which might look like a
    successful call (except for the error code).
    
    So, in this commit, I initialize the stat buffer to zero before
    it is potentially used.  If the stat call is not made then the buffer
    will be left initialized as all zeros.

Diff:
---
 sim/ppc/emul_netbsd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sim/ppc/emul_netbsd.c b/sim/ppc/emul_netbsd.c
index 322b584a3f1..a8bfd27610e 100644
--- a/sim/ppc/emul_netbsd.c
+++ b/sim/ppc/emul_netbsd.c
@@ -879,7 +879,7 @@ do_fstat(os_emul_data *emul,
 {
   int fd = cpu_registers(processor)->gpr[arg0];
   unsigned_word stat_buf_addr = cpu_registers(processor)->gpr[arg0+1];
-  struct stat buf;
+  struct stat buf = {};
   int status;
 #ifdef SYS_fstat
   SYS(fstat);

                 reply	other threads:[~2022-10-24 16:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221024161404.C8068385840C@sourceware.org \
    --to=aburgess@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).