From 78c5de598bb6ebd68d8d93fabdcebdca1f024580 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 15 Apr 2013 20:51:28 +0200 Subject: [PATCH] os: fix unlikely buffer overflow in os.type() * Fix a buffer overflow that happens iff strlen(info.sysname) > 255. * Check the return value of uname(). --- src/node_os.cc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/node_os.cc b/src/node_os.cc index d9712b8bf4..3047d0744d 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -69,14 +69,11 @@ static Handle GetOSType(const Arguments& args) { HandleScope scope; #ifdef __POSIX__ - char type[256]; struct utsname info; - - uname(&info); - strncpy(type, info.sysname, strlen(info.sysname)); - type[strlen(info.sysname)] = 0; - - return scope.Close(String::New(type)); + if (uname(&info)) { + return ThrowException(ErrnoException(errno, "uname")); + } + return scope.Close(String::New(info.sysname)); #else // __MINGW32__ return scope.Close(String::New("Windows_NT")); #endif