os: Fix uname() error handling on sunos
authorisaacs <i@izs.me>
Mon, 22 Apr 2013 17:18:46 +0000 (10:18 -0700)
committerisaacs <i@izs.me>
Mon, 22 Apr 2013 18:00:52 +0000 (11:00 -0700)
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

index 7f392a5..663fa9c 100644 (file)
@@ -77,7 +77,7 @@ static Handle<Value> 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<Value> GetOSType(const Arguments& args) {
 
 static Handle<Value> 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<Value> GetOSRelease(const Arguments& args) {
 
   sprintf(release, "%d.%d.%d", static_cast<int>(info.dwMajorVersion),
       static_cast<int>(info.dwMinorVersion), static_cast<int>(info.dwBuildNumber));
+  return scope.Close(String::New(release));
 #endif
 
-  return scope.Close(String::New(release));
 }
 
 static Handle<Value> GetCPUInfo(const Arguments& args) {