diff options
author | Lukas Larsson <[email protected]> | 2017-03-30 10:36:30 +0200 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2017-03-30 10:36:30 +0200 |
commit | 5da9e0ab5cb96f2cb37e534b2c1a55c0c2c9783c (patch) | |
tree | 2c5149e87daeaa23500bb94918f77fe25c7e2637 /erts | |
parent | 53b483cb14c4b3b666eab63f9f09d7ac827f9a7c (diff) | |
parent | 3fcf58b142e22adb754b312576570c904655f877 (diff) | |
download | otp-5da9e0ab5cb96f2cb37e534b2c1a55c0c2c9783c.tar.gz otp-5da9e0ab5cb96f2cb37e534b2c1a55c0c2c9783c.tar.bz2 otp-5da9e0ab5cb96f2cb37e534b2c1a55c0c2c9783c.zip |
Merge branch 'goeldeepak/erts/fix_inet_gethost_long/ERL-61/PR-1345/OTP-14310'
* goeldeepak/erts/fix_inet_gethost_long/ERL-61/PR-1345/OTP-14310:
This patch fixes the issue in which erlang fails to start if the hostname is 64 characters on a linux system.
Diffstat (limited to 'erts')
-rw-r--r-- | erts/emulator/beam/erl_mtrace.c | 7 | ||||
-rw-r--r-- | erts/emulator/drivers/common/inet_drv.c | 13 |
2 files changed, 11 insertions, 9 deletions
diff --git a/erts/emulator/beam/erl_mtrace.c b/erts/emulator/beam/erl_mtrace.c index e275867928..bb6f8660f1 100644 --- a/erts/emulator/beam/erl_mtrace.c +++ b/erts/emulator/beam/erl_mtrace.c @@ -572,7 +572,7 @@ void erts_mtrace_pre_init(void) void erts_mtrace_init(char *receiver, char *nodename) { - char hostname[MAXHOSTNAMELEN]; + char hostname[MAXHOSTNAMELEN + 1]; char pid[21]; /* enough for a 64 bit number */ socket_desc = ERTS_SOCK_INVALID_SOCKET; @@ -613,9 +613,10 @@ void erts_mtrace_init(char *receiver, char *nodename) } tracep = trace_buffer; endp = trace_buffer + TRACE_BUF_SZ; - if (erts_sock_gethostname(hostname, MAXHOSTNAMELEN) != 0) + /* gethostname requires that the len is max(hostname) + 1 */ + if (erts_sock_gethostname(hostname, MAXHOSTNAMELEN + 1) != 0) hostname[0] = '\0'; - hostname[MAXHOSTNAMELEN-1] = '\0'; + hostname[MAXHOSTNAMELEN] = '\0'; sys_get_pid(pid, sizeof(pid)); write_trace_header(nodename ? nodename : "", pid, hostname); erts_mtrace_update_heap_size(); diff --git a/erts/emulator/drivers/common/inet_drv.c b/erts/emulator/drivers/common/inet_drv.c index 278abe4e00..0fe5183b42 100644 --- a/erts/emulator/drivers/common/inet_drv.c +++ b/erts/emulator/drivers/common/inet_drv.c @@ -8345,10 +8345,10 @@ static ErlDrvData inet_start(ErlDrvPort port, int size, int protocol) return (ErlDrvData)desc; } - -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 256 -#endif +/* MAXHOSTNAMELEN could be 64 or 255 depending +on the platform. Instead, use INET_MAXHOSTNAMELEN +which is always 255 across all platforms */ +#define INET_MAXHOSTNAMELEN 255 /* ** common TCP/UDP/SCTP control command @@ -8525,13 +8525,14 @@ static ErlDrvSSizeT inet_ctl(inet_descriptor* desc, int cmd, char* buf, } case INET_REQ_GETHOSTNAME: { /* get host name */ - char tbuf[MAXHOSTNAMELEN]; + char tbuf[INET_MAXHOSTNAMELEN + 1]; DEBUGF(("inet_ctl(%ld): GETHOSTNAME\r\n", (long)desc->port)); if (len != 0) return ctl_error(EINVAL, rbuf, rsize); - if (IS_SOCKET_ERROR(sock_hostname(tbuf, MAXHOSTNAMELEN))) + /* gethostname requires len to be max(hostname) + 1 */ + if (IS_SOCKET_ERROR(sock_hostname(tbuf, INET_MAXHOSTNAMELEN + 1))) return ctl_error(sock_errno(), rbuf, rsize); return ctl_reply(INET_REP_OK, tbuf, strlen(tbuf), rbuf, rsize); } |