From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id C8068385840C; Mon, 24 Oct 2022 16:13:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8068385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666628044; bh=7Talz/HtBhLbbOqT2B/i/7WiffKLDixPSfR7YxpRNXc=; h=From:To:Subject:Date:From; b=j6yFcblQwL61sRjQTYRhFO+HucKNABLvWAYe1rHFXr4wOGzpbW7KJbSUQTQeT50o9 Y7id02wMCARBCinQOMid4yVK+tKef6daY5RziZpq2JG4Y+ILF0uQH9KNn6NFko4Zij z+E9tRsc5DFFaBU/7lhBJag2PnTYkp4JvSCV39KM= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] sim/ppc: initialize a memory buffer in all cases X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 368b8c325922ca329ae0edb1a9ce6bc16c9f927f X-Git-Newrev: 548d634f1b61571f118c3133ce0e8986714c8fd6 Message-Id: <20221024161404.C8068385840C@sourceware.org> Date: Mon, 24 Oct 2022 16:13:58 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D548d634f1b61= 571f118c3133ce0e8986714c8fd6 commit 548d634f1b61571f118c3133ce0e8986714c8fd6 Author: Andrew Burgess Date: Wed Oct 19 15:07:40 2022 +0100 sim/ppc: initialize a memory buffer in all cases =20 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. =20 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. =20 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). =20 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 =3D cpu_registers(processor)->gpr[arg0]; unsigned_word stat_buf_addr =3D cpu_registers(processor)->gpr[arg0+1]; - struct stat buf; + struct stat buf =3D {}; int status; #ifdef SYS_fstat SYS(fstat);