Skip to content

Commit

Permalink
ncurses 6.0 - patch 20170701
Browse files Browse the repository at this point in the history
+ modify update_getenv() in db_iterator.c to ensure that environment
  variables which are not initially set will be checked later if an
  application happens to set them (patch by Guillaume Maudoux).
+ remove initialization-check for calling napms() in the term-driver
  configuration; none is needed.
+ add help-screen to test/test_getstr.c and test/test_get_wstr.c
+ improve compatibility between different configurations of new_prescr,
  fixing a case with threaded code and term-driver where c++/demo did
  not work (cf: 20160213).
+ the fixes for Redhat #1464685 obscured a problem subsequently
  reported in Redhat #1464687; the given test-case was no longer
  reproducible.  Testing without the fixes for the earlier reports
  showed a problem with buffer overflow in dump_entry.c, which is
  addressed by reducing the use of a fixed-size buffer.
+ add/improve checks in tic's parser to address invalid input
  (Redhat #1464684, #1464685, #1464686, #1464691).
  + alloc_entry.c, add a check for a null-pointer.
  + parse_entry.c, add several checks for valid pointers as well as
    one check to ensure that a single character on a line is not
    treated as the 2-character termcap short-name.
+ fix a memory leak in delscreen() (report by Bai Junq).
+ improve tracemunch, showing thread identifiers as names.
+ fix a use-after-free in NCursesMenu::~NCursesMenu()
+ further amend incorrect calls for memory-leaks from 20170617 changes
  (report by Allen Hewes).
  • Loading branch information
ThomasDickey committed Jul 2, 2017
1 parent 3e7e5f8 commit b22573b
Show file tree
Hide file tree
Showing 33 changed files with 377 additions and 126 deletions.
29 changes: 28 additions & 1 deletion NEWS
Expand Up @@ -25,7 +25,7 @@
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
-------------------------------------------------------------------------------
-- $Id: NEWS,v 1.2866 2017/06/24 22:16:43 tom Exp $
-- $Id: NEWS,v 1.2878 2017/07/01 22:57:06 tom Exp $
-------------------------------------------------------------------------------

This is a log of changes that ncurses has gone through since Zeyd started
Expand All @@ -45,6 +45,33 @@ See the AUTHORS file for the corresponding full names.
Changes through 1.9.9e did not credit all contributions;
it is not possible to add this information.

20170701
+ modify update_getenv() in db_iterator.c to ensure that environment
variables which are not initially set will be checked later if an
application happens to set them (patch by Guillaume Maudoux).
+ remove initialization-check for calling napms() in the term-driver
configuration; none is needed.
+ add help-screen to test/test_getstr.c and test/test_get_wstr.c
+ improve compatibility between different configurations of new_prescr,
fixing a case with threaded code and term-driver where c++/demo did
not work (cf: 20160213).
+ the fixes for Redhat #1464685 obscured a problem subsequently
reported in Redhat #1464687; the given test-case was no longer
reproducible. Testing without the fixes for the earlier reports
showed a problem with buffer overflow in dump_entry.c, which is
addressed by reducing the use of a fixed-size buffer.
+ add/improve checks in tic's parser to address invalid input
(Redhat #1464684, #1464685, #1464686, #1464691).
+ alloc_entry.c, add a check for a null-pointer.
+ parse_entry.c, add several checks for valid pointers as well as
one check to ensure that a single character on a line is not
treated as the 2-character termcap short-name.
+ fix a memory leak in delscreen() (report by Bai Junq).
+ improve tracemunch, showing thread identifiers as names.
+ fix a use-after-free in NCursesMenu::~NCursesMenu()
+ further amend incorrect calls for memory-leaks from 20170617 changes
(report by Allen Hewes).

20170624
+ modify c++/etip.h.in to accommodate deprecation of throw() and
throws() in c++17 (prompted by patch by Romain Geissler).
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
5:0:9 6.0 20170624
5:0:9 6.0 20170701
6 changes: 3 additions & 3 deletions c++/cursesm.cc
@@ -1,6 +1,6 @@
// * this is for making emacs happy: -*-Mode: C++;-*-
/****************************************************************************
* Copyright (c) 1998-2005,2011 Free Software Foundation, Inc. *
* Copyright (c) 1998-2011,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
Expand Down Expand Up @@ -35,7 +35,7 @@
#include "cursesm.h"
#include "cursesapp.h"

MODULE_ID("$Id: cursesm.cc,v 1.23 2011/09/17 22:11:32 tom Exp $")
MODULE_ID("$Id: cursesm.cc,v 1.24 2017/06/26 08:32:53 tom Exp $")

NCursesMenuItem::~NCursesMenuItem()
{
Expand Down Expand Up @@ -180,8 +180,8 @@ NCursesMenu::~NCursesMenu()
UserHook* hook = reinterpret_cast<UserHook*>(::menu_userptr(menu));
delete hook;
if (b_sub_owner) {
delete sub;
::set_menu_sub(menu, static_cast<WINDOW *>(0));
delete sub;
}
if (menu) {
ITEM** itms = ::menu_items(menu);
Expand Down
4 changes: 2 additions & 2 deletions dist.mk
Expand Up @@ -25,7 +25,7 @@
# use or other dealings in this Software without prior written #
# authorization. #
##############################################################################
# $Id: dist.mk,v 1.1169 2017/06/18 23:13:28 tom Exp $
# $Id: dist.mk,v 1.1170 2017/06/25 16:16:02 tom Exp $
# Makefile for creating ncurses distributions.
#
# This only needs to be used directly as a makefile by developers, but
Expand All @@ -37,7 +37,7 @@ SHELL = /bin/sh
# These define the major/minor/patch versions of ncurses.
NCURSES_MAJOR = 6
NCURSES_MINOR = 0
NCURSES_PATCH = 20170624
NCURSES_PATCH = 20170701

# We don't append the patch to the version, since this only applies to releases
VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR)
Expand Down
10 changes: 8 additions & 2 deletions ncurses/base/lib_newterm.c
Expand Up @@ -48,7 +48,7 @@

#include <tic.h>

MODULE_ID("$Id: lib_newterm.c,v 1.96 2017/04/02 14:26:18 tom Exp $")
MODULE_ID("$Id: lib_newterm.c,v 1.99 2017/07/01 18:14:07 tom Exp $")

#ifdef USE_TERM_DRIVER
#define NumLabels InfoOf(SP_PARM).numlabels
Expand Down Expand Up @@ -349,6 +349,12 @@ NCURSES_SP_NAME(newterm) (NCURSES_SP_DCLx
NCURSES_EXPORT(SCREEN *)
newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp)
{
return NCURSES_SP_NAME(newterm) (CURRENT_SCREEN_PRE, name, ofp, ifp);
SCREEN *rc;
_nc_lock_global(prescreen);
START_TRACE();
rc = NCURSES_SP_NAME(newterm) (CURRENT_SCREEN_PRE, name, ofp, ifp);
_nc_forget_prescr();
_nc_unlock_global(prescreen);
return rc;
}
#endif
27 changes: 21 additions & 6 deletions ncurses/base/lib_set_term.c
Expand Up @@ -46,7 +46,7 @@
#undef CUR
#define CUR SP_TERMTYPE

MODULE_ID("$Id: lib_set_term.c,v 1.162 2017/04/15 21:44:03 tom Exp $")
MODULE_ID("$Id: lib_set_term.c,v 1.166 2017/07/01 16:37:24 tom Exp $")

#ifdef USE_TERM_DRIVER
#define MaxColors InfoOf(sp).maxcolors
Expand Down Expand Up @@ -182,6 +182,7 @@ delscreen(SCREEN *sp)
FreeIfNeeded(sp->_color_table);
FreeIfNeeded(sp->_color_pairs);

FreeIfNeeded(sp->_oldnum_list);
FreeIfNeeded(sp->oldhash);
FreeIfNeeded(sp->newhash);
FreeIfNeeded(sp->hashtab);
Expand All @@ -192,8 +193,9 @@ delscreen(SCREEN *sp)
NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx sp->_term);
FreeIfNeeded(sp->out_buffer);
if (_nc_prescreen.allocated == sp)
_nc_prescreen.allocated = 0;
if (_nc_find_prescr() == sp) {
_nc_forget_prescr();
}
free(sp);

/*
Expand Down Expand Up @@ -753,12 +755,15 @@ NCURSES_SP_NAME(_nc_ripoffline) (NCURSES_SP_DCLx
if (line == 0) {
code = OK;
} else {
if (safe_ripoff_sp == 0)
if (safe_ripoff_sp == 0) {
safe_ripoff_sp = safe_ripoff_stack;
}
if (safe_ripoff_sp < safe_ripoff_stack + N_RIPS) {
safe_ripoff_sp->line = line;
safe_ripoff_sp->hook = init;
(safe_ripoff_sp)++;
T(("ripped-off %d:%d chunks",
(int) (safe_ripoff_sp - safe_ripoff_stack), N_RIPS));
code = OK;
}
}
Expand All @@ -771,7 +776,12 @@ NCURSES_SP_NAME(_nc_ripoffline) (NCURSES_SP_DCLx
NCURSES_EXPORT(int)
_nc_ripoffline(int line, int (*init) (WINDOW *, int))
{
return NCURSES_SP_NAME(_nc_ripoffline) (CURRENT_SCREEN_PRE, line, init);
int rc;
_nc_lock_global(prescreen);
START_TRACE();
rc = NCURSES_SP_NAME(_nc_ripoffline) (CURRENT_SCREEN_PRE, line, init);
_nc_unlock_global(prescreen);
return rc;
}
#endif

Expand All @@ -790,6 +800,11 @@ NCURSES_SP_NAME(ripoffline) (NCURSES_SP_DCLx
NCURSES_EXPORT(int)
ripoffline(int line, int (*init) (WINDOW *, int))
{
return NCURSES_SP_NAME(ripoffline) (CURRENT_SCREEN_PRE, line, init);
int rc;
_nc_lock_global(prescreen);
START_TRACE();
rc = NCURSES_SP_NAME(ripoffline) (CURRENT_SCREEN_PRE, line, init);
_nc_unlock_global(prescreen);
return rc;
}
#endif
11 changes: 8 additions & 3 deletions ncurses/base/lib_slkinit.c
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. *
* Copyright (c) 1998-2009,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
Expand Down Expand Up @@ -40,7 +40,7 @@
*/
#include <curses.priv.h>

MODULE_ID("$Id: lib_slkinit.c,v 1.13 2009/10/31 00:10:46 tom Exp $")
MODULE_ID("$Id: lib_slkinit.c,v 1.14 2017/06/30 11:47:34 tom Exp $")

#ifdef USE_SP_RIPOFF
#define SoftkeyFormat SP_PARM->slk_format
Expand Down Expand Up @@ -75,6 +75,11 @@ NCURSES_SP_NAME(slk_init) (NCURSES_SP_DCLx int format)
NCURSES_EXPORT(int)
slk_init(int format)
{
return NCURSES_SP_NAME(slk_init) (CURRENT_SCREEN_PRE, format);
int rc;
_nc_lock_global(prescreen);
START_TRACE();
rc = NCURSES_SP_NAME(slk_init) (CURRENT_SCREEN_PRE, format);
_nc_unlock_global(prescreen);
return rc;
}
#endif
25 changes: 24 additions & 1 deletion ncurses/curses.priv.h
Expand Up @@ -34,7 +34,7 @@
****************************************************************************/

/*
* $Id: curses.priv.h,v 1.576 2017/06/24 15:08:46 tom Exp $
* $Id: curses.priv.h,v 1.580 2017/07/01 17:56:12 tom Exp $
*
* curses.priv.h
*
Expand Down Expand Up @@ -966,6 +966,9 @@ typedef struct {

#ifdef USE_PTHREADS
pthread_mutex_t mutex_curses;
pthread_mutex_t mutex_prescreen;
pthread_mutex_t mutex_screen;
pthread_mutex_t mutex_update;
pthread_mutex_t mutex_tst_tracef;
pthread_mutex_t mutex_tracef;
int nested_tracef;
Expand All @@ -984,12 +987,24 @@ extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals;

#define N_RIPS 5

#ifdef USE_PTHREADS
typedef struct _prescreen_list {
struct _prescreen_list *next;
pthread_t id;
struct screen *sp;
} PRESCREEN_LIST;
#endif

/*
* Global data which can be swept up into a SCREEN when one is created.
* It may be modified before the next SCREEN is created.
*/
typedef struct {
#ifdef USE_PTHREADS
PRESCREEN_LIST *allocated;
#else
struct screen * allocated;
#endif
bool use_env;
bool filter_mode;
attr_t previous_attr;
Expand Down Expand Up @@ -2019,6 +2034,14 @@ extern NCURSES_EXPORT(int) _nc_locale_breaks_acs(TERMINAL *);
extern NCURSES_EXPORT(int) _nc_setupterm(NCURSES_CONST char *, int, int *, int);
extern NCURSES_EXPORT(void) _nc_tinfo_cmdch(TERMINAL *, int);

#ifdef USE_PTHREADS
extern NCURSES_EXPORT(SCREEN *) _nc_find_prescr(void);
extern NCURSES_EXPORT(void) _nc_forget_prescr(void);
#else
#define _nc_find_prescr() _nc_prescreen.allocated
#define _nc_forget_prescr() _nc_prescreen.allocated = 0
#endif

/* lib_set_term.c */
extern NCURSES_EXPORT(int) _nc_ripoffline(int, int(*)(WINDOW*, int));

Expand Down
8 changes: 6 additions & 2 deletions ncurses/tinfo/alloc_entry.c
Expand Up @@ -47,7 +47,7 @@

#include <tic.h>

MODULE_ID("$Id: alloc_entry.c,v 1.59 2017/04/09 23:33:51 tom Exp $")
MODULE_ID("$Id: alloc_entry.c,v 1.60 2017/06/27 23:48:55 tom Exp $")

#define ABSENT_OFFSET -1
#define CANCELLED_OFFSET -2
Expand Down Expand Up @@ -96,7 +96,11 @@ _nc_save_str(const char *const string)
{
char *result = 0;
size_t old_next_free = next_free;
size_t len = strlen(string) + 1;
size_t len;

if (string == 0)
return _nc_save_str("");
len = strlen(string) + 1;

if (len == 1 && next_free != 0) {
/*
Expand Down
28 changes: 15 additions & 13 deletions ncurses/tinfo/db_iterator.c
Expand Up @@ -43,7 +43,7 @@
#include <hashed_db.h>
#endif

MODULE_ID("$Id: db_iterator.c,v 1.44 2017/02/04 23:27:01 tom Exp $")
MODULE_ID("$Id: db_iterator.c,v 1.46 2017/07/01 22:54:42 tom Exp $")

#define HaveTicDirectory _nc_globals.have_tic_directory
#define KeepTicDirectory _nc_globals.keep_tic_directory
Expand Down Expand Up @@ -123,19 +123,21 @@ update_getenv(const char *name, DBDIRS which)

if (which < dbdLAST) {
char *value;
char *cached_value = my_vars[which].value;
bool same_value;

if ((value = getenv(name)) == 0 || (value = strdup(value)) == 0) {
;
} else if (my_vars[which].name == 0 || strcmp(my_vars[which].name, name)) {
FreeIfNeeded(my_vars[which].value);
my_vars[which].name = name;
my_vars[which].value = value;
result = TRUE;
} else if ((my_vars[which].value != 0) ^ (value != 0)) {
FreeIfNeeded(my_vars[which].value);
my_vars[which].value = value;
result = TRUE;
} else if (value != 0 && strcmp(value, my_vars[which].value)) {
if ((value = getenv(name)) != 0) {
value = strdup(value);
}
same_value = ((value == 0 && cached_value == 0) ||
(value != 0 &&
cached_value != 0 &&
strcmp(value, cached_value) == 0));

/* Set variable name to enable checks in cache_expired(). */
my_vars[which].name = name;

if (!same_value) {
FreeIfNeeded(my_vars[which].value);
my_vars[which].value = value;
result = TRUE;
Expand Down
4 changes: 2 additions & 2 deletions ncurses/tinfo/entries.c
Expand Up @@ -37,7 +37,7 @@

#include <tic.h>

MODULE_ID("$Id: entries.c,v 1.23 2017/04/13 22:39:57 tom Exp $")
MODULE_ID("$Id: entries.c,v 1.25 2017/07/01 16:58:42 tom Exp $")

/****************************************************************************
*
Expand Down Expand Up @@ -126,7 +126,7 @@ _nc_leaks_tinfo(void)
if (TerminalOf(CURRENT_SCREEN) != 0) {
del_curterm(TerminalOf(CURRENT_SCREEN));
}
free(_nc_prescreen.allocated);
_nc_forget_prescr();

_nc_comp_captab_leaks();
_nc_free_entries(_nc_head);
Expand Down
8 changes: 7 additions & 1 deletion ncurses/tinfo/lib_data.c
Expand Up @@ -42,7 +42,7 @@

#include <curses.priv.h>

MODULE_ID("$Id: lib_data.c,v 1.72 2017/04/10 08:34:31 tom Exp $")
MODULE_ID("$Id: lib_data.c,v 1.74 2017/06/30 11:36:55 tom Exp $")

/*
* OS/2's native linker complains if we don't initialize public data when
Expand Down Expand Up @@ -199,6 +199,9 @@ NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals = {
#endif /* TRACE */
#ifdef USE_PTHREADS
PTHREAD_MUTEX_INITIALIZER, /* mutex_curses */
PTHREAD_MUTEX_INITIALIZER, /* mutex_prescreen */
PTHREAD_MUTEX_INITIALIZER, /* mutex_screen */
PTHREAD_MUTEX_INITIALIZER, /* mutex_update */
PTHREAD_MUTEX_INITIALIZER, /* mutex_tst_tracef */
PTHREAD_MUTEX_INITIALIZER, /* mutex_tracef */
0, /* nested_tracef */
Expand Down Expand Up @@ -294,6 +297,9 @@ init_global_mutexes(void)
if (!initialized) {
initialized = TRUE;
_nc_mutex_init(&_nc_globals.mutex_curses);
_nc_mutex_init(&_nc_globals.mutex_prescreen);
_nc_mutex_init(&_nc_globals.mutex_screen);
_nc_mutex_init(&_nc_globals.mutex_update);
_nc_mutex_init(&_nc_globals.mutex_tst_tracef);
_nc_mutex_init(&_nc_globals.mutex_tracef);
}
Expand Down

0 comments on commit b22573b

Please sign in to comment.