From 1201598913ece82e4c43203b527fb248f590703a Mon Sep 17 00:00:00 2001 From: deraadt Date: Sun, 11 Jan 2015 04:14:40 +0000 Subject: [PATCH] correctly use HOST_NAME_MAX. Some notes: POSIX HOST_NAME_MAX doesn't include the NUL. POSIX LOGIN_NAME_MAX and TTY_NAME_MAX do include the NUL. BSD MAXHOSTNAMELEN includes the NUL. Actually, most of the historical BSD MAX* defines did include the NUL, except for the historical mistake of utmp fields without NULs in the string, which directly led to strncpy.. just showing how error prone this kind of accounting is. CSRG did right. Somehow POSIX missed the memo on the concepts of carefulness and consistancy, and we are still paying the price when people trip over this. Of course, glibc is even more amazing (that is a hint to blackhats) ok guenther --- usr.bin/tmux/format.c | 4 ++-- usr.bin/tmux/screen.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index 7abe2dbb304..2185af1d582 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.55 2014/12/09 19:23:35 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.56 2015/01/11 04:14:40 deraadt Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -133,7 +133,7 @@ struct format_tree * format_create(void) { struct format_tree *ft; - char host[MAXHOSTNAMELEN], *ptr; + char host[HOST_NAME_MAX+1], *ptr; ft = xcalloc(1, sizeof *ft); RB_INIT(&ft->tree); diff --git a/usr.bin/tmux/screen.c b/usr.bin/tmux/screen.c index 07e77d066cb..f39ce3708d2 100644 --- a/usr.bin/tmux/screen.c +++ b/usr.bin/tmux/screen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen.c,v 1.32 2014/11/06 09:17:25 nicm Exp $ */ +/* $OpenBSD: screen.c,v 1.33 2015/01/11 04:14:40 deraadt Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -31,11 +31,11 @@ void screen_resize_y(struct screen *, u_int); void screen_init(struct screen *s, u_int sx, u_int sy, u_int hlimit) { - char host[HOST_NAME_MAX]; + char host[HOST_NAME_MAX+1]; s->grid = grid_create(sx, sy, hlimit); - if (gethostname(host, HOST_NAME_MAX) == 0) + if (gethostname(host, sizeof(host)) == 0) s->title = xstrdup(host); else s->title = xstrdup(""); -- 2.20.1