From c77747354c573f57f4f5a2de42407c9fcf6dc10c Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 22 Apr 2013 10:18:46 -0700 Subject: [PATCH] os: Fix uname() error handling on sunos The uname function can return any non-negative int to indicate success. Strange, but that's how it is documented. This also fixes a similar buffer overflow in the even more unlikely event that info.release is > 255 characters, similar to how 78c5de5 did for info.sysname. --- src/node_os.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/node_os.cc b/src/node_os.cc index 7f392a58fd..663fa9c6bf 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -77,7 +77,7 @@ static Handle GetOSType(const Arguments& args) { #ifdef __POSIX__ struct utsname info; - if (uname(&info)) { + if (uname(&info) < 0) { return ThrowException(ErrnoException(errno, "uname")); } return scope.Close(String::New(info.sysname)); @@ -88,16 +88,15 @@ static Handle GetOSType(const Arguments& args) { static Handle GetOSRelease(const Arguments& args) { HandleScope scope; - char release[256]; #ifdef __POSIX__ struct utsname info; - - uname(&info); - strncpy(release, info.release, strlen(info.release)); - release[strlen(info.release)] = 0; - + if (uname(&info) < 0) { + return ThrowException(ErrnoException(errno, "uname")); + } + return scope.Close(String::New(info.release)); #else // __MINGW32__ + char release[256]; OSVERSIONINFO info; info.dwOSVersionInfoSize = sizeof(info); @@ -107,9 +106,9 @@ static Handle GetOSRelease(const Arguments& args) { sprintf(release, "%d.%d.%d", static_cast(info.dwMajorVersion), static_cast(info.dwMinorVersion), static_cast(info.dwBuildNumber)); + return scope.Close(String::New(release)); #endif - return scope.Close(String::New(release)); } static Handle GetCPUInfo(const Arguments& args) {