]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/read_termcap.c
ncurses 6.2 - patch 20210626
[ncurses.git] / ncurses / tinfo / read_termcap.c
index ecf76d9be751e2be4019724fa6af24fd94ee9eb5..418dc3f802551ab87ba63cb1a55a8cdd34fc74ea 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2018,2019 Free Software Foundation, Inc.              *
+ * Copyright 2018-2020,2021 Thomas E. Dickey                                *
+ * Copyright 1998-2016,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            *
@@ -56,7 +57,7 @@
 #include <sys/types.h>
 #include <tic.h>
 
-MODULE_ID("$Id: read_termcap.c,v 1.97 2019/01/26 20:07:30 tom Exp $")
+MODULE_ID("$Id: read_termcap.c,v 1.101 2021/06/26 19:43:17 tom Exp $")
 
 #if !PURE_TERMINFO
 
@@ -802,7 +803,7 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name)
     /*
      * TERMCAP can have one of two things in it.  It can be the name of a file
      * to use instead of /etc/termcap.  In this case it better start with a
-     * "/".  Or it can be an entry to use so we don't have to read the file. 
+     * "/".  Or it can be an entry to use so we don't have to read the file.
      * In this case it has to already have the newlines crunched out.  If
      * TERMCAP does not hold a file name then a path of names is searched
      * instead.  The path is found in the TERMPATH variable, or becomes
@@ -1063,14 +1064,16 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE2 *const tp)
            }
        }
 
-#define PRIVATE_CAP "%s/.termcap"
+#define PRIVATE_CAP "%.*s/.termcap"
 
        if (use_terminfo_vars() && (h = getenv("HOME")) != NULL && *h != '\0'
            && (strlen(h) + sizeof(PRIVATE_CAP)) < PATH_MAX) {
            /* user's .termcap, if any, should override it */
            _nc_STRCPY(envhome, h, sizeof(envhome));
            _nc_SPRINTF(pathbuf, _nc_SLIMIT(sizeof(pathbuf))
-                       PRIVATE_CAP, envhome);
+                       PRIVATE_CAP,
+                       (int) (sizeof(pathbuf) - sizeof(PRIVATE_CAP)),
+                       envhome);
            ADD_TC(pathbuf, filecount);
        }
     }
@@ -1123,7 +1126,7 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE2 *const tp)
 
            TR(TRACE_DATABASE, ("Looking for %s in %s", tn, termpaths[i]));
            if (_nc_access(termpaths[i], R_OK) == 0
-               && (fp = fopen(termpaths[i], "r")) != (FILE *) 0) {
+               && (fp = safe_fopen(termpaths[i], "r")) != (FILE *) 0) {
                _nc_set_source(termpaths[i]);
 
                /*
@@ -1163,7 +1166,7 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE2 *const tp)
                _nc_free_entry(_nc_head, &(ep->tterm));
 
                /*
-                * OK, now try to write the type to user's terminfo directory. 
+                * OK, now try to write the type to user's terminfo directory.
                 * Next time he loads this, it will come through terminfo.
                 *
                 * Advantage:  Second and subsequent fetches of this entry will