Browse Source

os: fix unlikely buffer overflow in os.type()

* Fix a buffer overflow that happens iff strlen(info.sysname) > 255.
* Check the return value of uname().
v0.10.5-release
Ben Noordhuis 12 years ago
parent
commit
78c5de598b
  1. 11
      src/node_os.cc

11
src/node_os.cc

@ -69,14 +69,11 @@ static Handle<Value> GetOSType(const Arguments& args) {
HandleScope scope; HandleScope scope;
#ifdef __POSIX__ #ifdef __POSIX__
char type[256];
struct utsname info; struct utsname info;
if (uname(&info)) {
uname(&info); return ThrowException(ErrnoException(errno, "uname"));
strncpy(type, info.sysname, strlen(info.sysname)); }
type[strlen(info.sysname)] = 0; return scope.Close(String::New(info.sysname));
return scope.Close(String::New(type));
#else // __MINGW32__ #else // __MINGW32__
return scope.Close(String::New("Windows_NT")); return scope.Close(String::New("Windows_NT"));
#endif #endif

Loading…
Cancel
Save