X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fread_entry.c;h=c8aae6009242860fbd470b634e6cb5bb5f36efb0;hp=4ff8cc48bf48ed002352aa3bf2311f2ff528015e;hb=b6d0d9ad9e372e856f01a4c283cf784a15993903;hpb=22fd3b236834311f1682b09d16eacec0d17f8683;ds=sidebyside diff --git a/ncurses/tinfo/read_entry.c b/ncurses/tinfo/read_entry.c index 4ff8cc48..c8aae600 100644 --- a/ncurses/tinfo/read_entry.c +++ b/ncurses/tinfo/read_entry.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc. * + * Copyright (c) 1998-2011,2012 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 * @@ -41,7 +41,7 @@ #include -MODULE_ID("$Id: read_entry.c,v 1.111 2011/09/24 20:15:12 tom Exp $") +MODULE_ID("$Id: read_entry.c,v 1.119 2012/02/22 22:40:24 tom Exp $") #define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts)) @@ -99,7 +99,7 @@ fake_read(char *src, int *offset, int limit, char *dst, unsigned want) if (have > 0) { if ((int) want > have) want = (unsigned) have; - memcpy(dst, src + *offset, want); + memcpy(dst, src + *offset, (size_t) want); *offset += (int) want; } else { want = 0; @@ -107,10 +107,10 @@ fake_read(char *src, int *offset, int limit, char *dst, unsigned want) return (int) want; } -#define Read(buf, count) fake_read(buffer, &offset, limit, buf, count) +#define Read(buf, count) fake_read(buffer, &offset, limit, buf, (unsigned) count) #define read_shorts(buf, count) \ - (Read(buf, (unsigned) (count)*2) == (int) (count)*2) + (Read(buf, (count)*2) == (int) (count)*2) #define even_boundary(value) \ if ((value) % 2 != 0) Read(buf, 1) @@ -175,7 +175,7 @@ _nc_read_termtype(TERMTYPE *ptr, char *buffer, int limit) ptr->str_table = string_table; ptr->term_names = string_table; if ((have = (unsigned) Read(ptr->term_names, want)) != want) { - memset(ptr->term_names + have, 0, want - have); + memset(ptr->term_names + have, 0, (size_t) (want - have)); } ptr->term_names[want] = '\0'; string_table += (want + 1); @@ -328,17 +328,18 @@ _nc_read_termtype(TERMTYPE *ptr, char *buffer, int limit) ext_str_limit, ptr->ext_str_table + base); } - T(("...done reading terminfo bool %d(%d) num %d(%d) str %d(%d)", - ptr->num_Booleans, ptr->ext_Booleans, - ptr->num_Numbers, ptr->ext_Numbers, - ptr->num_Strings, ptr->ext_Strings)); + TR(TRACE_DATABASE, + ("...done reading terminfo bool %d(%d) num %d(%d) str %d(%d)", + ptr->num_Booleans, ptr->ext_Booleans, + ptr->num_Numbers, ptr->ext_Numbers, + ptr->num_Strings, ptr->ext_Strings)); TR(TRACE_DATABASE, ("extend: num_Booleans:%d", ptr->num_Booleans)); } else #endif /* NCURSES_XNAMES */ { - T(("...done reading terminfo bool %d num %d str %d", - bool_count, num_count, str_count)); + TR(TRACE_DATABASE, ("...done reading terminfo bool %d num %d str %d", + bool_count, num_count, str_count)); #if NCURSES_XNAMES TR(TRACE_DATABASE, ("normal: num_Booleans:%d", ptr->num_Booleans)); #endif @@ -373,13 +374,13 @@ _nc_read_file_entry(const char *const filename, TERMTYPE *ptr) if (_nc_access(filename, R_OK) < 0 || (fp = fopen(filename, "rb")) == 0) { - T(("cannot open terminfo %s (errno=%d)", filename, errno)); + TR(TRACE_DATABASE, ("cannot open terminfo %s (errno=%d)", filename, errno)); code = TGETENT_NO; } else { if ((limit = (int) fread(buffer, sizeof(char), sizeof(buffer), fp)) > 0) { - T(("read terminfo %s", filename)); + TR(TRACE_DATABASE, ("read terminfo %s", filename)); if ((code = _nc_read_termtype(ptr, buffer, limit)) == TGETENT_NO) { _nc_free_termtype(ptr); } @@ -409,9 +410,9 @@ make_db_filename(char *filename, unsigned limit, const char *const path) if (test < limit) { if (size >= lens && !strcmp(path + size - lens, suffix)) - (void) strcpy(filename, path); + _nc_STRCPY(filename, path, limit); else - (void) sprintf(filename, "%s%s", path, suffix); + _nc_SPRINTF(filename, _nc_SLIMIT(limit) "%s%s", path, suffix); result = TRUE; } return result; @@ -427,12 +428,19 @@ make_dir_filename(char *filename, const char *const path, const char *name) { - unsigned need = (unsigned) (LEAF_LEN + 3 + strlen(path) + strlen(name)); bool result = FALSE; - if (need <= limit) { - (void) sprintf(filename, "%s/" LEAF_FMT "/%s", path, *name, name); - result = TRUE; +#if USE_TERMCAP + if (_nc_is_dir_path(path)) +#endif + { + unsigned need = (unsigned) (LEAF_LEN + 3 + strlen(path) + strlen(name)); + + if (need <= limit) { + _nc_SPRINTF(filename, _nc_SLIMIT(limit) + "%s/" LEAF_FMT "/%s", path, *name, name); + result = TRUE; + } } return result; } @@ -515,9 +523,10 @@ _nc_read_tic_entry(char *filename, code = _nc_read_file_entry(filename, tp); } #if USE_TERMCAP - if (code != TGETENT_YES) { + else if (code != TGETENT_YES) { code = _nc_read_termcap_entry(name, tp); - sprintf(filename, "%.*s", PATH_MAX - 1, _nc_get_source()); + _nc_SPRINTF(filename, _nc_SLIMIT(PATH_MAX) + "%.*s", PATH_MAX - 1, _nc_get_source()); } #endif return code; @@ -538,20 +547,24 @@ _nc_read_entry(const char *const name, char *const filename, TERMTYPE *const tp) { int code = TGETENT_NO; - sprintf(filename, "%.*s", PATH_MAX - 1, name); + _nc_SPRINTF(filename, _nc_SLIMIT(PATH_MAX) + "%.*s", PATH_MAX - 1, name); + if (strlen(name) == 0 || strcmp(name, ".") == 0 || strcmp(name, "..") == 0 || _nc_pathlast(name) != 0 || strchr(name, NCURSES_PATHSEP) != 0) { - T(("illegal or missing entry name '%s'", name)); + TR(TRACE_DATABASE, ("illegal or missing entry name '%s'", name)); } else { #if USE_DATABASE - DBDIRS state = dbdTIC; - int offset = 0; + DBDIRS state; + int offset; const char *path; + _nc_first_db(&state, &offset); while ((path = _nc_next_db(&state, &offset)) != 0) { + TR(TRACE_DATABASE, ("_nc_read_tic_entry path=%s, name=%s", path, name)); code = _nc_read_tic_entry(filename, PATH_MAX, path, name, tp); if (code == TGETENT_YES) { _nc_last_db(); @@ -561,7 +574,8 @@ _nc_read_entry(const char *const name, char *const filename, TERMTYPE *const tp) #elif USE_TERMCAP if (code != TGETENT_YES) { code = _nc_read_termcap_entry(name, tp); - sprintf(filename, "%.*s", PATH_MAX - 1, _nc_get_source()); + _nc_SPRINTF(filename, _nc_SLIMIT(PATH_MAX) + "%.*s", PATH_MAX - 1, _nc_get_source()); } #endif }