Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 1484274 - There is an infinite loop in comp_scan.c of libncurses.
There is an infinite loop in comp_scan.c of libncurses.
Status: CLOSED DUPLICATE of bug 1488915
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: ncurses (Show other bugs)
7.5-Alt
Unspecified Unspecified
unspecified Severity unspecified
: rc
: ---
Assigned To: Miroslav Lichvar
qe-baseos-daemons
:
Depends On:
Blocks: CVE-2017-13728
  Show dependency treegraph
 
Reported: 2017-08-23 03:43 EDT by owl337
Modified: 2018-07-27 11:24 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2018-07-27 11:24:05 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Triggered by " ./tic POC7 " (122 bytes, application/x-rar)
2017-08-23 03:43 EDT, owl337
no flags Details

  None (edit)
Description owl337 2017-08-23 03:43:37 EDT
Created attachment 1316974 [details]
Triggered by " ./tic POC7 "

Description of problem:

There is an infinite loop in comp_scan.c of libncurses. 

Version-Release number of selected component (if applicable):

<= latest version

How reproducible:

./tic POC7

Steps to Reproduce:


$ ./tic POC7
"fuzz/info2cap_output/crashes/id:000000,sig:11,src:000041,op:havoc,rep:32", line 1, col 9, terminal 'a+du1': Illegal character (expected alphanumeric or @%&*!#) - '/'
"fuzz/info2cap_output/crashes/id:000000,sig:11,src:000041,op:havoc,rep:32", line 2, col 18, terminal 'a+du1': Illegal character (expected alphanumeric or @%&*!#) - '/'


The GDB debugging information is as follows:

(gdb) r
...
Breakpoint 2, next_char () at ../ncurses/./tinfo/comp_scan.c:209
209			if (fgets(result + used, (int) (allocated - used), yyin) != 0) {
(gdb) bt 
#0  next_char () at ../ncurses/./tinfo/comp_scan.c:209
#1  0x000000000043fa3d in _nc_get_token (silent=false) at ../ncurses/./tinfo/comp_scan.c:392
#2  0x0000000000442a20 in _nc_parse_entry (entryp=0x7fffffffaf48, literal=0, silent=false)
    at ../ncurses/./tinfo/parse_entry.c:216
#3  0x000000000043db23 in _nc_read_entry_source (fp=<optimized out>, buf=<optimized out>, literal=0, silent=false, 
    hook=0x40e230 <immedhook>) at ../ncurses/./tinfo/comp_parse.c:225
#4  0x0000000000403039 in main (argc=<optimized out>, argv=<optimized out>) at ../progs/tic.c:958
...

The vulnerability was triggered in function:
next_char () at ../ncurses/./tinfo/comp_scan.c:223
223			if ((bufptr = bufstart) != 0) {

Code:
194		do {
195		    size_t used = 0;
196		    bufstart = 0;
197		    do {
198			if (used + (LEXBUFSIZ / 4) >= allocated) {
199			    allocated += (allocated + LEXBUFSIZ);
200			    result = typeRealloc(char, allocated, result);
201			    if (result == 0)
202				return (EOF);
203			    if (bufstart)
204				bufstart = result;
205			}
206			if (used == 0)
207			    _nc_curr_file_pos = ftell(yyin);
208	
209			if (fgets(result + used, (int) (allocated - used), yyin) != 0) {
210			    bufstart = result;
211			    if (used == 0) {
212				if (_nc_curr_line == 0
213				    && IS_TIC_MAGIC(result)) {
214				    _nc_err_abort("This is a compiled terminal description, not a source");
215				}
216				_nc_curr_line++;
217				_nc_curr_col = 0;
218			    }
219			} else {
220			    if (used != 0)
221				_nc_STRCAT(result, "\n", allocated);
222			}
223			if ((bufptr = bufstart) != 0) {
224			    used = strlen(bufptr);
225			    while (iswhite(*bufptr)) {
226				if (*bufptr == '\t') {
227				    _nc_curr_col = (_nc_curr_col | 7) + 1;
228				} else {
229				    _nc_curr_col++;
230				}
231				bufptr++;
232			    }
233	
234			    /*
235			     * Treat a trailing <cr><lf> the same as a <newline> so we
236			     * can read files on OS/2, etc.
237			     */
238			    if ((len = strlen(bufptr)) > 1) {
239				if (bufptr[len - 1] == '\n'
240				    && bufptr[len - 2] == '\r') {
241				    len--;
242				    bufptr[len - 1] = '\n';
243				    bufptr[len] = '\0';
244				}
245			    }
246			} else {
247			    return (EOF);
248			}
249		    } while (bufptr[len - 1] != '\n');	/* complete a line */
250		} while (result[0] == '#');	/* ignore comments */
251	    } else if (*bufptr == '\t') {

Actual results:

crash

Expected results:

crash

Additional info:

Credits:

This vulnerability is detected by team OWL337, with our custom fuzzer collAFL. Please contact ganshuitao@gmail.com   and chaoz@tsinghua.edu.cn if you need more info about the team, the tool or the vulnerability.
Comment 2 Thomas E. Dickey 2017-08-23 17:44:53 EDT
I made a fix which will be in the next set of updates.
Comment 3 Thomas E. Dickey 2017-08-23 18:00:14 EDT
By the way, the relevant code is in libtic, both for RHEL7 and Fedora.  You might find it helpful when reporting bugs in RHEL to use the same configuration details as their packages.

Note You need to log in before you can comment on or make changes to this bug.