1 From 4bf72cb8f1d3aa5f33c31eb817a5f0338f4aaf6f Mon Sep 17 00:00:00 2001
2 From: Ovidiu Panait <ovidiu.panait@windriver.com>
3 Date: Wed, 20 Sep 2017 05:02:00 +0000
4 Subject: [PATCH] Import upstream patch 20170826
7 + fixes for "iterm2" (report by Leonardo Brondani Schenkel) -TD
8 + corrected a warning from tic about keys which are the same, to skip
9 over missing/cancelled values.
10 + add check in tic for unnecessary use of "2" to denote a shifted
12 + improve checks in trim_sgr0, comp_parse.c and parse_entry.c, for
13 cancelled string capabilities.
14 + add check in _nc_parse_entry() for invalid entry name, setting the
15 name to "invalid" to avoid problems storing entries.
16 + add/improve checks in tic's parser to address invalid input
17 + add a check in comp_scan.c to handle the special case where a
18 nontext file ending with a NUL rather than newline is given to tic
19 as input (Redhat #1484274).
20 + allow for cancelled capabilities in _nc_save_str (Redhat #1484276).
21 + add validity checks for "use=" target in _nc_parse_entry (Redhat
23 + check for invalid strings in postprocess_termcap (Redhat #1484285)
24 + reset secondary pointers on EOF in next_char() (Redhat #1484287).
25 + guard _nc_safe_strcpy() and _nc_safe_strcat() against calls using
26 cancelled strings (Redhat #1484291).
27 + correct typo in curs_memleaks.3x (Sven Joachim).
28 + improve test/configure checks for some curses variants not based on
30 + add options for test/configure to disable checks for form, menu and
33 Upstream-Status: Backport
34 CVE: CVE-2017-13732, CVE-2017-13734, CVE-2017-13730, CVE-2017-13729, CVE-2017-13728, CVE-2017-13731
37 Author: Sven Joachim <svenjoac@gmx.de>
38 Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
41 include/ncurses_defs | 4 +-
42 ncurses/tinfo/alloc_entry.c | 4 +-
43 ncurses/tinfo/comp_parse.c | 10 ++---
44 ncurses/tinfo/comp_scan.c | 6 ++-
45 ncurses/tinfo/parse_entry.c | 91 ++++++++++++++++++++++++++++++---------------
46 ncurses/tinfo/strings.c | 9 +++--
47 ncurses/tinfo/trim_sgr0.c | 4 +-
48 progs/tic.c | 75 ++++++++++++++++++++++++++++++++++++-
49 9 files changed, 157 insertions(+), 50 deletions(-)
51 diff --git a/dist.mk b/dist.mk
52 index 9af2699..2c70472 100644
56 # use or other dealings in this Software without prior written #
58 ##############################################################################
59 -# $Id: dist.mk,v 1.1172 2017/07/13 00:15:27 tom Exp $
60 +# $Id: dist.mk,v 1.1179 2017/08/20 15:33:41 tom Exp $
61 # Makefile for creating ncurses distributions.
63 # This only needs to be used directly as a makefile by developers, but
64 @@ -37,7 +37,7 @@ SHELL = /bin/sh
65 # These define the major/minor/patch versions of ncurses.
68 -NCURSES_PATCH = 20170715
69 +NCURSES_PATCH = 20170826
71 # We don't append the patch to the version, since this only applies to releases
72 VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR)
73 diff --git a/include/ncurses_defs b/include/ncurses_defs
74 index e6611b7..d237db1 100644
75 --- a/include/ncurses_defs
76 +++ b/include/ncurses_defs
78 -# $Id: ncurses_defs,v 1.73 2017/06/24 14:20:57 tom Exp $
79 +# $Id: ncurses_defs,v 1.75 2017/08/20 16:50:04 tom Exp $
80 ##############################################################################
81 # Copyright (c) 2000-2016,2017 Free Software Foundation, Inc. #
83 @@ -50,7 +50,9 @@ HAVE_BSD_STRING_H
93 diff --git a/ncurses/tinfo/alloc_entry.c b/ncurses/tinfo/alloc_entry.c
94 index 5de09f1..09374d6 100644
95 --- a/ncurses/tinfo/alloc_entry.c
96 +++ b/ncurses/tinfo/alloc_entry.c
101 -MODULE_ID("$Id: alloc_entry.c,v 1.60 2017/06/27 23:48:55 tom Exp $")
102 +MODULE_ID("$Id: alloc_entry.c,v 1.61 2017/08/25 09:09:08 tom Exp $")
104 #define ABSENT_OFFSET -1
105 #define CANCELLED_OFFSET -2
106 @@ -98,7 +98,7 @@ _nc_save_str(const char *const string)
107 size_t old_next_free = next_free;
111 + if (!VALID_STRING(string))
112 return _nc_save_str("");
113 len = strlen(string) + 1;
115 diff --git a/ncurses/tinfo/comp_parse.c b/ncurses/tinfo/comp_parse.c
116 index 34e6216..580d4df 100644
117 --- a/ncurses/tinfo/comp_parse.c
118 +++ b/ncurses/tinfo/comp_parse.c
123 -MODULE_ID("$Id: comp_parse.c,v 1.96 2017/04/15 15:36:58 tom Exp $")
124 +MODULE_ID("$Id: comp_parse.c,v 1.99 2017/08/26 16:15:50 tom Exp $")
126 static void sanity_check2(TERMTYPE2 *, bool);
127 NCURSES_IMPEXP void NCURSES_API(*_nc_check_termtype2) (TERMTYPE2 *, bool) = sanity_check2;
128 @@ -510,9 +510,9 @@ static void
129 fixup_acsc(TERMTYPE2 *tp, int literal)
133 - && enter_alt_charset_mode != 0
134 - && exit_alt_charset_mode != 0)
135 + if (acs_chars == ABSENT_STRING
136 + && PRESENT(enter_alt_charset_mode)
137 + && PRESENT(exit_alt_charset_mode))
138 acs_chars = strdup(VT_ACSC);
141 @@ -568,9 +568,7 @@ sanity_check2(TERMTYPE2 *tp, bool literal)
142 PAIRED(enter_xon_mode, exit_xon_mode);
143 PAIRED(enter_am_mode, exit_am_mode);
144 ANDMISSING(label_off, label_on);
146 PAIRED(display_clock, remove_clock);
148 ANDMISSING(set_color_pair, initialize_pair);
151 diff --git a/ncurses/tinfo/comp_scan.c b/ncurses/tinfo/comp_scan.c
152 index 40d7f6a..b207257 100644
153 --- a/ncurses/tinfo/comp_scan.c
154 +++ b/ncurses/tinfo/comp_scan.c
159 -MODULE_ID("$Id: comp_scan.c,v 1.106 2017/04/22 11:41:12 tom Exp $")
160 +MODULE_ID("$Id: comp_scan.c,v 1.108 2017/08/25 22:57:21 tom Exp $")
163 * Maximum length of string capability we'll accept before raising an error.
164 @@ -168,6 +168,8 @@ next_char(void)
167 FreeAndNull(pushname);
173 @@ -222,6 +224,8 @@ next_char(void)
175 if ((bufptr = bufstart) != 0) {
176 used = strlen(bufptr);
179 while (iswhite(*bufptr)) {
180 if (*bufptr == '\t') {
181 _nc_curr_col = (_nc_curr_col | 7) + 1;
182 diff --git a/ncurses/tinfo/parse_entry.c b/ncurses/tinfo/parse_entry.c
183 index 3fa2f25..bbbfcb2 100644
184 --- a/ncurses/tinfo/parse_entry.c
185 +++ b/ncurses/tinfo/parse_entry.c
190 -MODULE_ID("$Id: parse_entry.c,v 1.86 2017/06/28 00:53:12 tom Exp $")
191 +MODULE_ID("$Id: parse_entry.c,v 1.91 2017/08/26 16:13:34 tom Exp $")
194 static short const parametrized[] =
195 @@ -180,6 +180,20 @@ _nc_extend_names(ENTRY * entryp, char *name, int token_type)
197 #endif /* NCURSES_XNAMES */
200 +valid_entryname(const char *name)
202 + bool result = TRUE;
204 + while ((ch = UChar(*name++)) != '\0') {
205 + if (ch <= ' ' || ch > '~' || ch == '/') {
215 * _nc_parse_entry(entry, literal, silent)
216 @@ -211,6 +225,7 @@ _nc_parse_entry(ENTRY * entryp, int literal, bool silent)
218 struct name_table_entry const *entry_ptr;
221 bool bad_tc_usage = FALSE;
223 token_type = _nc_get_token(silent);
224 @@ -261,7 +276,12 @@ _nc_parse_entry(ENTRY * entryp, int literal, bool silent)
225 * results in the terminal type getting prematurely set to correspond
226 * to that of the next entry.
228 - _nc_set_type(_nc_first_name(entryp->tterm.term_names));
229 + name = _nc_first_name(entryp->tterm.term_names);
230 + if (!valid_entryname(name)) {
231 + _nc_warning("invalid entry name \"%s\"", name);
234 + _nc_set_type(name);
236 /* check for overly-long names and aliases */
237 for (base = entryp->tterm.term_names; (ptr = strchr(base, '|')) != 0;
238 @@ -283,13 +303,24 @@ _nc_parse_entry(ENTRY * entryp, int literal, bool silent)
239 bool is_use = (strcmp(_nc_curr_token.tk_name, "use") == 0);
240 bool is_tc = !is_use && (strcmp(_nc_curr_token.tk_name, "tc") == 0);
241 if (is_use || is_tc) {
242 + if (!VALID_STRING(_nc_curr_token.tk_valstring)
243 + || _nc_curr_token.tk_valstring[0] == '\0') {
244 + _nc_warning("missing name for use-clause");
246 + } else if (!valid_entryname(_nc_curr_token.tk_valstring)) {
247 + _nc_warning("invalid name for use-clause \"%s\"",
248 + _nc_curr_token.tk_valstring);
250 + } else if (entryp->nuses >= MAX_USES) {
251 + _nc_warning("too many use-clauses, ignored \"%s\"",
252 + _nc_curr_token.tk_valstring);
255 entryp->uses[entryp->nuses].name = _nc_save_str(_nc_curr_token.tk_valstring);
256 entryp->uses[entryp->nuses].line = _nc_curr_line;
257 - if (VALID_STRING(entryp->uses[entryp->nuses].name)) {
259 - if (entryp->nuses > 1 && is_tc) {
263 + if (entryp->nuses > 1 && is_tc) {
267 /* normal token lookup */
268 @@ -641,13 +672,6 @@ static const char C_BS[] = "\b";
269 static const char C_HT[] = "\t";
272 - * Note that WANTED and PRESENT are not simple inverses! If a capability
273 - * has been explicitly cancelled, it's not considered WANTED.
275 -#define WANTED(s) ((s) == ABSENT_STRING)
276 -#define PRESENT(s) (((s) != ABSENT_STRING) && ((s) != CANCELLED_STRING))
279 * This bit of legerdemain turns all the terminfo variable names into
280 * references to locations in the arrays Booleans, Numbers, and Strings ---
281 * precisely what's needed.
282 @@ -672,10 +696,10 @@ postprocess_termcap(TERMTYPE2 *tp, bool has_base)
284 /* if there was a tc entry, assume we picked up defaults via that */
286 - if (WANTED(init_3string) && termcap_init2)
287 + if (WANTED(init_3string) && PRESENT(termcap_init2))
288 init_3string = _nc_save_str(termcap_init2);
290 - if (WANTED(reset_2string) && termcap_reset)
291 + if (WANTED(reset_2string) && PRESENT(termcap_reset))
292 reset_2string = _nc_save_str(termcap_reset);
294 if (WANTED(carriage_return)) {
295 @@ -790,7 +814,7 @@ postprocess_termcap(TERMTYPE2 *tp, bool has_base)
296 if (init_tabs != 8 && init_tabs != ABSENT_NUMERIC)
297 _nc_warning("hardware tabs with a width other than 8: %d", init_tabs);
299 - if (tab && _nc_capcmp(tab, C_HT))
300 + if (PRESENT(tab) && _nc_capcmp(tab, C_HT))
301 _nc_warning("hardware tabs with a non-^I tab string %s",
304 @@ -867,17 +891,22 @@ postprocess_termcap(TERMTYPE2 *tp, bool has_base)
305 * The magic moment -- copy the mapped key string over,
306 * stripping out padding.
308 - for (dp = buf2, bp = tp->Strings[from_ptr->nte_index]; *bp; bp++) {
309 - if (bp[0] == '$' && bp[1] == '<') {
310 - while (*bp && *bp != '>') {
317 + bp = tp->Strings[from_ptr->nte_index];
318 + if (VALID_STRING(bp)) {
319 + for (dp = buf2; *bp; bp++) {
320 + if (bp[0] == '$' && bp[1] == '<') {
321 + while (*bp && *bp != '>') {
329 - tp->Strings[to_ptr->nte_index] = _nc_save_str(buf2);
330 + tp->Strings[to_ptr->nte_index] = _nc_save_str(buf2);
332 + tp->Strings[to_ptr->nte_index] = bp;
337 @@ -886,7 +915,7 @@ postprocess_termcap(TERMTYPE2 *tp, bool has_base)
338 * got mapped to kich1 and im to kIC to avoid a collision.
339 * If the description has im but not ic, hack kIC back to kich1.
341 - if (foundim && WANTED(key_ic) && key_sic) {
342 + if (foundim && WANTED(key_ic) && PRESENT(key_sic)) {
344 key_sic = ABSENT_STRING;
346 @@ -938,9 +967,9 @@ postprocess_termcap(TERMTYPE2 *tp, bool has_base)
347 acs_chars = _nc_save_str(buf2);
348 _nc_warning("acsc string synthesized from XENIX capabilities");
350 - } else if (acs_chars == 0
351 - && enter_alt_charset_mode != 0
352 - && exit_alt_charset_mode != 0) {
353 + } else if (acs_chars == ABSENT_STRING
354 + && PRESENT(enter_alt_charset_mode)
355 + && PRESENT(exit_alt_charset_mode)) {
356 acs_chars = _nc_save_str(VT_ACSC);
359 diff --git a/ncurses/tinfo/strings.c b/ncurses/tinfo/strings.c
360 index 393d8e7..10ec6c8 100644
361 --- a/ncurses/tinfo/strings.c
362 +++ b/ncurses/tinfo/strings.c
364 /****************************************************************************
365 - * Copyright (c) 2000-2007,2012 Free Software Foundation, Inc. *
366 + * Copyright (c) 2000-2012,2017 Free Software Foundation, Inc. *
368 * Permission is hereby granted, free of charge, to any person obtaining a *
369 * copy of this software and associated documentation files (the *
373 #include <curses.priv.h>
376 -MODULE_ID("$Id: strings.c,v 1.8 2012/02/22 22:34:31 tom Exp $")
377 +MODULE_ID("$Id: strings.c,v 1.9 2017/08/26 13:16:11 tom Exp $")
379 /****************************************************************************
380 * Useful string functions (especially for mvcur)
381 @@ -105,7 +106,7 @@ _nc_str_copy(string_desc * dst, string_desc * src)
383 _nc_safe_strcat(string_desc * dst, const char *src)
386 + if (PRESENT(src)) {
387 size_t len = strlen(src);
389 if (len < dst->s_size) {
390 @@ -126,7 +127,7 @@ _nc_safe_strcat(string_desc * dst, const char *src)
392 _nc_safe_strcpy(string_desc * dst, const char *src)
395 + if (PRESENT(src)) {
396 size_t len = strlen(src);
398 if (len < dst->s_size) {
399 diff --git a/ncurses/tinfo/trim_sgr0.c b/ncurses/tinfo/trim_sgr0.c
400 index 4cbcb65..4d92d15 100644
401 --- a/ncurses/tinfo/trim_sgr0.c
402 +++ b/ncurses/tinfo/trim_sgr0.c
407 -MODULE_ID("$Id: trim_sgr0.c,v 1.16 2017/04/05 22:33:07 tom Exp $")
408 +MODULE_ID("$Id: trim_sgr0.c,v 1.17 2017/08/26 14:54:16 tom Exp $")
412 @@ -263,7 +263,7 @@ _nc_trim_sgr0(TERMTYPE2 *tp)
414 * If rmacs is a substring of sgr(0), remove that chunk.
416 - if (exit_alt_charset_mode != 0) {
417 + if (PRESENT(exit_alt_charset_mode)) {
418 TR(TRACE_DATABASE, ("scan for rmacs %s", _nc_visbuf(exit_alt_charset_mode)));
420 k = strlen(exit_alt_charset_mode);
421 diff --git a/progs/tic.c b/progs/tic.c
422 index c5d78e5..6dd4678 100644
426 #include <parametrized.h>
427 #include <transform.h>
429 -MODULE_ID("$Id: tic.c,v 1.233 2017/07/15 17:40:19 tom Exp $")
430 +MODULE_ID("$Id: tic.c,v 1.243 2017/08/26 20:56:55 tom Exp $")
432 #define STDIN_NAME "<stdin>"
434 @@ -62,6 +62,10 @@ static bool showsummary = FALSE;
435 static char **namelst = 0;
436 static const char *to_remove;
439 +static bool using_extensions = FALSE;
442 static void (*save_check_termtype) (TERMTYPE2 *, bool);
443 static void check_termtype(TERMTYPE2 *tt, bool);
445 @@ -850,6 +854,7 @@ main(int argc, char *argv[])
448 use_extended_names(TRUE);
449 + using_extensions = TRUE;
453 @@ -2405,10 +2410,17 @@ check_conflict(TERMTYPE2 *tp)
454 const char *a = given[j].value;
457 + if (!VALID_STRING(a))
460 for (k = j + 1; given[k].keycode; k++) {
461 const char *b = given[k].value;
463 + if (!VALID_STRING(b))
468 if (!_nc_capcmp(a, b)) {
471 @@ -2431,6 +2443,67 @@ check_conflict(TERMTYPE2 *tp)
473 fprintf(stderr, "\n");
476 + if (using_extensions) {
479 + const char *xcurses;
480 + const char *shifted;
496 + * SVr4 curses defines the "xcurses" names listed above except for
497 + * the special cases in the "shifted" column. When using these
498 + * names for xterm's extensions, that was confusing, and resulted
499 + * in adding extended capabilities with "2" (shift) suffix. This
500 + * check warns about unnecessary use of extensions for this quirk.
502 + for (j = 0; given[j].keycode; ++j) {
503 + const char *find = given[j].name;
507 + if (!VALID_STRING(given[j].value))
510 + for (k = 0; table[k].xcurses; ++k) {
511 + const char *test = table[k].xcurses;
512 + size_t size = strlen(test);
514 + if (!strncmp(find, test, size) && strcmp(find, test)) {
515 + switch (sscanf(find + size, "%d%c", &value, &ch)) {
518 + _nc_warning("expected '%s' rather than '%s'",
522 + } else if (value < 2 || value > 15) {
523 + _nc_warning("expected numeric 2..15 '%s'", find);
527 + _nc_warning("expected numeric suffix for '%s'", find);