X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fwrite_entry.c;h=f7ae96fb584f5ee7305c7a2904b7c795080717a6;hp=0c992b66402e7ebe9bca5aa25f64c5524e7e5179;hb=952539d2f6aa5a3a29adc54488b0d3b66121c888;hpb=8b06e371ed1bce3dd6f37138e6becb5e1a562fe0 diff --git a/ncurses/tinfo/write_entry.c b/ncurses/tinfo/write_entry.c index 0c992b66..f7ae96fb 100644 --- a/ncurses/tinfo/write_entry.c +++ b/ncurses/tinfo/write_entry.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc. * + * Copyright (c) 1998-2012,2013 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 * @@ -47,7 +47,7 @@ #define TRACE_OUT(p) /*nothing */ #endif -MODULE_ID("$Id: write_entry.c,v 1.84 2012/02/22 22:40:24 tom Exp $") +MODULE_ID("$Id: write_entry.c,v 1.88 2013/07/27 15:52:18 tom Exp $") static int total_written; @@ -273,16 +273,21 @@ _nc_write_entry(TERMTYPE *const tp) char name_list[MAX_TERMINFO_LENGTH]; char *first_name, *other_names; char *ptr; + const char *term_names = tp->term_names; + size_t name_size = strlen(term_names); - assert(strlen(tp->term_names) != 0); - assert(strlen(tp->term_names) < sizeof(name_list)); + if (name_size == 0) { + _nc_syserr_abort("no terminal name found."); + } else if (name_size >= sizeof(name_list) - 1) { + _nc_syserr_abort("terminal name too long: %s", term_names); + } - _nc_STRCPY(name_list, tp->term_names, sizeof(name_list)); + _nc_STRCPY(name_list, term_names, sizeof(name_list)); DEBUG(7, ("Name list = '%s'", name_list)); first_name = name_list; - ptr = &name_list[strlen(name_list) - 1]; + ptr = &name_list[name_size - 1]; other_names = ptr + 1; while (ptr > name_list && *ptr != '|') @@ -316,8 +321,8 @@ _nc_write_entry(TERMTYPE *const tp) buffer[0] = 0; memset(&key, 0, sizeof(key)); - key.data = tp->term_names; - key.size = strlen(tp->term_names); + key.data = term_names; + key.size = name_size; memset(&data, 0, sizeof(data)); data.data = buffer; @@ -331,9 +336,9 @@ _nc_write_entry(TERMTYPE *const tp) key.size = strlen(name_list); _nc_STRCPY(buffer + 1, - tp->term_names, + term_names, sizeof(buffer) - 1); - data.size = strlen(tp->term_names) + 1; + data.size = name_size + 1; _nc_db_put(capdb, &key, &data); @@ -372,7 +377,22 @@ _nc_write_entry(TERMTYPE *const tp) if (start_time > 0 && stat(filename, &statbuf) >= 0 && statbuf.st_mtime >= start_time) { +#if HAVE_LINK && !USE_SYMLINKS + /* + * If the file has more than one link, the reason for the previous + * write could be that the current primary name used to be an alias for + * the previous entry. In that case, unlink the file so that we will + * not modify the previous entry as we write this one. + */ + if (statbuf.st_nlink > 1) { + _nc_warning("name redefined."); + unlink(filename); + } else { + _nc_warning("name multiply defined."); + } +#else _nc_warning("name multiply defined."); +#endif } check_writeable(first_name[0]);