From 97c3f6599d1e958cdfa93f3c6dffc3ce0a4e8c61 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Mon, 17 Sep 2012 18:00:06 +0200 Subject: [PATCH] Noux, libc_terminal: initialize 'stat' buffer Initialize the 'stat' buffer in the 'stat()' function to avoid potential non-deterministic program behavior. Fixes #362. --- libports/src/lib/libc_terminal/plugin.cc | 5 ++++- ports/src/noux/fs_file_system.h | 2 ++ ports/src/noux/tar_file_system.h | 11 ++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/libports/src/lib/libc_terminal/plugin.cc b/libports/src/lib/libc_terminal/plugin.cc index 12add6c1b7..6811e86647 100644 --- a/libports/src/lib/libc_terminal/plugin.cc +++ b/libports/src/lib/libc_terminal/plugin.cc @@ -162,7 +162,10 @@ namespace { * This is important, i.e., to convince the gdbserver code to * cooperate with us. */ - if (buf) buf->st_mode = S_IFCHR; + if (buf) { + Genode::memset(buf, 0, sizeof(struct stat)); + buf->st_mode = S_IFCHR; + } return 0; } diff --git a/ports/src/noux/fs_file_system.h b/ports/src/noux/fs_file_system.h index 7c17dcd20a..ef3cdf1fc8 100644 --- a/ports/src/noux/fs_file_system.h +++ b/ports/src/noux/fs_file_system.h @@ -189,6 +189,8 @@ namespace Noux { return false; } + memset(&sysio->stat_out.st, 0, sizeof(sysio->stat_out.st)); + sysio->stat_out.st.size = status.size; sysio->stat_out.st.mode = Sysio::STAT_MODE_FILE | 0777; diff --git a/ports/src/noux/tar_file_system.h b/ports/src/noux/tar_file_system.h index fa4aaf56e9..ac7833bfd2 100644 --- a/ports/src/noux/tar_file_system.h +++ b/ports/src/noux/tar_file_system.h @@ -344,11 +344,12 @@ namespace Noux { PDBG("unhandled record type %d", record->type()); } - sysio->stat_out.st.mode = mode; - sysio->stat_out.st.size = record->size(); - sysio->stat_out.st.uid = record->uid(); - sysio->stat_out.st.gid = record->gid(); - sysio->stat_out.st.inode = (unsigned long)record; + memset(&sysio->stat_out.st, 0, sizeof(sysio->stat_out.st)); + sysio->stat_out.st.mode = mode; + sysio->stat_out.st.size = record->size(); + sysio->stat_out.st.uid = record->uid(); + sysio->stat_out.st.gid = record->gid(); + sysio->stat_out.st.inode = (unsigned long)record; return true; }