Skip to content

Commit

Permalink
os: fix unlikely buffer overflow in os.type()
Browse files Browse the repository at this point in the history
* Fix a buffer overflow that happens iff strlen(info.sysname) > 255.
* Check the return value of uname().
  • Loading branch information
bnoordhuis committed Apr 15, 2013
1 parent 8ee4300 commit 78c5de5
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,11 @@ static Handle<Value> GetOSType(const Arguments& args) {
HandleScope scope;

#ifdef __POSIX__
char type[256];
struct utsname info;

uname(&info);
strncpy(type, info.sysname, strlen(info.sysname));
type[strlen(info.sysname)] = 0;

return scope.Close(String::New(type));
if (uname(&info)) {
return ThrowException(ErrnoException(errno, "uname"));
}
return scope.Close(String::New(info.sysname));
#else // __MINGW32__
return scope.Close(String::New("Windows_NT"));
#endif
Expand Down

0 comments on commit 78c5de5

Please sign in to comment.