mirror of
https://github.com/nodejs/node.git
synced 2025-05-22 08:35:19 +00:00
os: handle 256 character hostnames
Fix a (rather academic) buffer overflow. MAXHOSTNAMELEN is 256 on most platforms, which means the buffer wasn't big enough to hold the trailing nul byte on a system with a maximum length hostname.
This commit is contained in:
parent
78c5de598b
commit
afbaddecd3
@ -33,7 +33,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __POSIX__
|
#ifdef __POSIX__
|
||||||
# include <unistd.h> // gethostname, sysconf
|
# include <netdb.h> // MAXHOSTNAMELEN on Solaris.
|
||||||
|
# include <unistd.h> // gethostname, sysconf
|
||||||
|
# include <sys/param.h> // MAXHOSTNAMELEN on Linux and the BSDs.
|
||||||
# include <sys/utsname.h>
|
# include <sys/utsname.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -51,10 +53,9 @@ static Handle<Value> GetEndianness(const Arguments& args) {
|
|||||||
|
|
||||||
static Handle<Value> GetHostname(const Arguments& args) {
|
static Handle<Value> GetHostname(const Arguments& args) {
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
char s[255];
|
char buf[MAXHOSTNAMELEN + 1];
|
||||||
int r = gethostname(s, 255);
|
|
||||||
|
|
||||||
if (r < 0) {
|
if (gethostname(buf, sizeof(buf))) {
|
||||||
#ifdef __POSIX__
|
#ifdef __POSIX__
|
||||||
return ThrowException(ErrnoException(errno, "gethostname"));
|
return ThrowException(ErrnoException(errno, "gethostname"));
|
||||||
#else // __MINGW32__
|
#else // __MINGW32__
|
||||||
@ -62,7 +63,7 @@ static Handle<Value> GetHostname(const Arguments& args) {
|
|||||||
#endif // __MINGW32__
|
#endif // __MINGW32__
|
||||||
}
|
}
|
||||||
|
|
||||||
return scope.Close(String::New(s));
|
return scope.Close(String::New(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Handle<Value> GetOSType(const Arguments& args) {
|
static Handle<Value> GetOSType(const Arguments& args) {
|
||||||
|
Loading…
Reference in New Issue
Block a user