From a6bac95fbda1ef3c08034b88e2b861b96ea379f3 Mon Sep 17 00:00:00 2001 From: Julian Stecklina Date: Wed, 8 Feb 2012 22:57:57 +0100 Subject: [PATCH] Fix possible NULL-pointer dereference in _stat When given NULL pointers as buffers to _stat, return EFAULT, just as Linux and FreeBSD. Fixes #101. --- ports/src/lib/libc_noux/plugin.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/src/lib/libc_noux/plugin.cc b/ports/src/lib/libc_noux/plugin.cc index e8e7834a3..1b7b58692 100644 --- a/ports/src/lib/libc_noux/plugin.cc +++ b/ports/src/lib/libc_noux/plugin.cc @@ -96,6 +96,11 @@ static void _sysio_to_stat_struct(Noux::Sysio const *sysio, struct stat *buf) static int _stat(const char *path, struct stat *buf, bool lstat = false) { + if ((path == NULL) or (buf == NULL)) { + errno = EFAULT; + return -1; + } + Genode::strncpy(sysio()->stat_in.path, path, sizeof(sysio()->stat_in.path)); if (!noux()->syscall(Noux::Session::SYSCALL_STAT)) {