diff options
| author | isaacs <i@izs.me> | 2013-04-22 10:18:46 -0700 |
|---|---|---|
| committer | isaacs <i@izs.me> | 2013-04-22 11:00:52 -0700 |
| commit | c77747354c573f57f4f5a2de42407c9fcf6dc10c (patch) | |
| tree | 927fec100b6958cd08d540a61a5e9ddc6d15b59f /src/node_os.cc | |
| parent | 01e29202193cfc4257d6c638b8c08b7fcc2c9931 (diff) | |
| download | node-c77747354c573f57f4f5a2de42407c9fcf6dc10c.tar.gz | |
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.
Diffstat (limited to 'src/node_os.cc')
| -rw-r--r-- | src/node_os.cc | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/node_os.cc b/src/node_os.cc index 7f392a58f..663fa9c6b 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -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) { |
