Use the sysconf(_SC_HOST_NAME_MAX) to determine maximum length of a hostname. Signed-off-by: Sami Kerola <kerolasa@xxxxxx> --- login-utils/last.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/login-utils/last.c b/login-utils/last.c index 77a890a..a3d5a85 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -418,22 +418,19 @@ addtty(char *ttyname) { */ static void hostconv(char *arg) { - static int first = 1; - static char *hostdot, - name[MAXHOSTNAMELEN]; - char *argdot; + static char *hostdot; + static char *argdot; + static char *name; if (!(argdot = strchr(arg, '.'))) return; - if (first) { - first = 0; - if (gethostname(name, sizeof(name))) - err(EXIT_FAILURE, _("gethostname failed")); - - hostdot = strchr(name, '.'); - } + name = xmalloc(sizeof(char) * (sysconf(_SC_HOST_NAME_MAX) + 1)); + if (gethostname(name, sysconf(_SC_HOST_NAME_MAX))) + err(EXIT_FAILURE, _("gethostname failed")); + hostdot = strchr(name, '.'); if (hostdot && !strcmp(hostdot, argdot)) *argdot = '\0'; + free(name); } /* -- 1.7.12.2 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html