Skip to content

Commit c777473

Browse files
committed
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.
1 parent 01e2920 commit c777473

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

src/node_os.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static Handle<Value> GetOSType(const Arguments& args) {
7777

7878
#ifdef __POSIX__
7979
struct utsname info;
80-
if (uname(&info)) {
80+
if (uname(&info) < 0) {
8181
return ThrowException(ErrnoException(errno, "uname"));
8282
}
8383
return scope.Close(String::New(info.sysname));
@@ -88,16 +88,15 @@ static Handle<Value> GetOSType(const Arguments& args) {
8888

8989
static Handle<Value> GetOSRelease(const Arguments& args) {
9090
HandleScope scope;
91-
char release[256];
9291

9392
#ifdef __POSIX__
9493
struct utsname info;
95-
96-
uname(&info);
97-
strncpy(release, info.release, strlen(info.release));
98-
release[strlen(info.release)] = 0;
99-
94+
if (uname(&info) < 0) {
95+
return ThrowException(ErrnoException(errno, "uname"));
96+
}
97+
return scope.Close(String::New(info.release));
10098
#else // __MINGW32__
99+
char release[256];
101100
OSVERSIONINFO info;
102101
info.dwOSVersionInfoSize = sizeof(info);
103102

@@ -107,9 +106,9 @@ static Handle<Value> GetOSRelease(const Arguments& args) {
107106

108107
sprintf(release, "%d.%d.%d", static_cast<int>(info.dwMajorVersion),
109108
static_cast<int>(info.dwMinorVersion), static_cast<int>(info.dwBuildNumber));
109+
return scope.Close(String::New(release));
110110
#endif
111111

112-
return scope.Close(String::New(release));
113112
}
114113

115114
static Handle<Value> GetCPUInfo(const Arguments& args) {

0 commit comments

Comments
 (0)