Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
os,report: use UV_MAXHOSTNAMESIZE
UV_MAXHOSTNAMESIZE was introduced in libuv 1.26.0. Use this
instead of including multiple header files, adding fallback
ifdef logic, and remembering to add one to the buffer size
for the terminating nul character with MAXHOSTNAMELEN.

PR-URL: #26038
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig committed Feb 13, 2019
commit 8ecf313324e619d7211adaee76c6b7bb1882e12b
9 changes: 1 addition & 8 deletions src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,9 @@

#ifdef __POSIX__
# include <limits.h> // PATH_MAX on Solaris.
# include <netdb.h> // MAXHOSTNAMELEN on Solaris.
# include <unistd.h> // gethostname, sysconf
# include <sys/param.h> // MAXHOSTNAMELEN on Linux and the BSDs.
#endif // __POSIX__

// Add Windows fallback.
#ifndef MAXHOSTNAMELEN
# define MAXHOSTNAMELEN 256
#endif // MAXHOSTNAMELEN

namespace node {
namespace os {

Expand All @@ -66,7 +59,7 @@ using v8::Value;

static void GetHostname(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
char buf[MAXHOSTNAMELEN + 1];
char buf[UV_MAXHOSTNAMESIZE];
size_t size = sizeof(buf);
int r = uv_os_gethostname(buf, &size);

Expand Down
11 changes: 1 addition & 10 deletions src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@
extern char** environ;
#endif

#ifdef __POSIX__
# include <netdb.h> // MAXHOSTNAMELEN on Solaris.
# include <sys/param.h> // MAXHOSTNAMELEN on Linux and the BSDs.
#endif // __POSIX__

#ifndef MAXHOSTNAMELEN
# define MAXHOSTNAMELEN 256
#endif // MAXHOSTNAMELEN

namespace report {
using node::arraysize;
using node::Environment;
Expand Down Expand Up @@ -377,7 +368,7 @@ static void PrintVersionInformation(JSONWriter* writer) {
writer->json_keyvalue("osMachine", os_info.machine);
}

char host[MAXHOSTNAMELEN + 1];
char host[UV_MAXHOSTNAMESIZE];
size_t host_size = sizeof(host);

if (uv_os_gethostname(host, &host_size) == 0)
Expand Down