Browse Source

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.
v0.10.5-release
isaacs 12 years ago
parent
commit
c77747354c
  1. 15
      src/node_os.cc

15
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) {

Loading…
Cancel
Save