Noux, libc_terminal: initialize 'stat' buffer

Initialize the 'stat' buffer in the 'stat()' function to avoid potential
non-deterministic program behavior.

Fixes #362.
This commit is contained in:
Christian Prochaska 2012-09-17 18:00:06 +02:00 committed by Norman Feske
parent 8af582fac2
commit 97c3f6599d
3 changed files with 12 additions and 6 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}