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().
This commit is contained in:
Ben Noordhuis 2013-04-15 20:51:28 +02:00
parent 8ee43006b8
commit 78c5de598b

View File

@ -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