From 8a8e2eb04aa03bd1b8f4a515fc1d7e50a35acb44 Mon Sep 17 00:00:00 2001 From: deraadt Date: Sun, 11 Jan 2015 04:14:40 +0000 Subject: [PATCH 1/4] 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 --- format.c | 2 +- screen.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/format.c b/format.c index c5ede2bd..ea0a91b1 100644 --- a/format.c +++ b/format.c @@ -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/screen.c b/screen.c index 3e3cac53..1b841eed 100644 --- a/screen.c +++ b/screen.c @@ -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(""); From 86207ee676af4fc64f6e289d824460800f43194e Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 15 Jan 2015 13:35:13 +0000 Subject: [PATCH 2/4] Shorten some long lines. --- window-copy.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/window-copy.c b/window-copy.c index 8aae09be..6447a2d5 100644 --- a/window-copy.c +++ b/window-copy.c @@ -390,13 +390,16 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key) if (data->inputtype == WINDOW_COPY_JUMPFORWARD) { for (; np != 0; np--) window_copy_cursor_jump(wp); - } else if (data->inputtype == WINDOW_COPY_JUMPBACK) { + } + if (data->inputtype == WINDOW_COPY_JUMPBACK) { for (; np != 0; np--) window_copy_cursor_jump_back(wp); - } else if (data->inputtype == WINDOW_COPY_JUMPTOFORWARD) { + } + if (data->inputtype == WINDOW_COPY_JUMPTOFORWARD) { for (; np != 0; np--) window_copy_cursor_jump_to(wp); - } else if (data->inputtype == WINDOW_COPY_JUMPTOBACK) { + } + if (data->inputtype == WINDOW_COPY_JUMPTOBACK) { for (; np != 0; np--) window_copy_cursor_jump_to_back(wp); } @@ -1771,7 +1774,7 @@ window_copy_other_end(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; struct screen *s = &data->screen; - u_int selx, sely, cx, cy, yy; + u_int selx, sely, cx, cy, yy, hsize; if (!s->sel.flag && s->sel.lineflag == LINE_SEL_NONE) return; @@ -1791,13 +1794,13 @@ window_copy_other_end(struct window_pane *wp) data->sely = yy; data->cx = selx; - if (sely < screen_hsize(data->backing) - data->oy) { - data->oy = screen_hsize(data->backing) - sely; + hsize = screen_hsize(data->backing); + if (sely < hsize - data->oy) { + data->oy = hsize - sely; data->cy = 0; - } else if (sely > screen_hsize(data->backing) - data->oy + screen_size_y(s)) { - data->oy = screen_hsize(data->backing) - sely + screen_size_y(s) - 1; + } else if (sely > hsize - data->oy + screen_size_y(s)) { + data->oy = hsize - sely + screen_size_y(s) - 1; data->cy = screen_size_y(s) - 1; - } else data->cy = cy + sely - yy; From 6e764fb53e7665d723d0ac58ec32c5b608f9c713 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 15 Jan 2015 13:43:13 +0000 Subject: [PATCH 3/4] Remove an unnecessary variable and shorten a line. --- window-choose.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/window-choose.c b/window-choose.c index 56016394..0d724746 100644 --- a/window-choose.c +++ b/window-choose.c @@ -330,14 +330,12 @@ window_choose_collapse(struct window_pane *wp, struct session *s) struct window_choose_mode_data *data = wp->modedata; struct window_choose_mode_item *item, *chosen; struct window_choose_data *wcd; - u_int i, pos; + u_int i; ARRAY_DECL(, struct window_choose_mode_item) list_copy; ARRAY_INIT(&list_copy); - pos = data->selected; - - chosen = &ARRAY_ITEM(&data->list, pos); + chosen = &ARRAY_ITEM(&data->list, data->selected); chosen->state &= ~TREE_EXPANDED; /* @@ -353,9 +351,8 @@ window_choose_collapse(struct window_pane *wp, struct session *s) /* We only show the session when collapsed. */ if (wcd->type & TREE_SESSION) { item->state &= ~TREE_EXPANDED; + ARRAY_ADD(&list_copy, *item); - ARRAY_ADD(&list_copy, - ARRAY_ITEM(&data->list, i)); /* * Update the selection to this session item so * we don't end up highlighting a non-existent From 776eef49d8e13b227d25e5d56d4c379b89c4aacb Mon Sep 17 00:00:00 2001 From: deraadt Date: Fri, 16 Jan 2015 06:40:13 +0000 Subject: [PATCH 4/4] Replace with and other less dirty headers where possible. Annotate lines with their current reasons. Switch to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where sensible to avoid pulling in the pollution. These are the files confirmed through binary verification. ok guenther, millert, doug (helped with the verification protocol) --- procname.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/procname.c b/procname.c index 7ee076e7..97a78d71 100644 --- a/procname.c +++ b/procname.c @@ -16,7 +16,8 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include +#include /* MAXCOMLEN */ +#include #include #include #include