Browse Source

* sltermin.c (): Avoid strncpy, home_ti is 1K long and
nobody really needs it whole cleared

Andrew V. Samoilov 20 years ago
parent
commit
ef67afe62d
2 changed files with 11 additions and 3 deletions
  1. 5 0
      slang/ChangeLog
  2. 6 3
      slang/sltermin.c

+ 5 - 0
slang/ChangeLog

@@ -1,3 +1,8 @@
+2004-09-04  Pavel S. Shirshov  <pavelsh@mail.ru>
+
+	* sltermin.c (): Avoid strncpy, home_ti is 1K long and 
+	nobody really needs it whole cleared
+
 2004-08-31  Pavel S. Shirshov  <pavelsh@mail.ru>
 
 	* include/slang.h: Revert last changes - it breaks compiling

+ 6 - 3
slang/sltermin.c

@@ -267,9 +267,12 @@ SLterminfo_Type *_SLtt_tigetent (char *term)
 
    if (NULL != (home = getenv ("HOME")))
      {
-	strncpy (home_ti, home, sizeof (home_ti) - 11);
-	home_ti [sizeof(home_ti) - 11] = 0;
-	strcat (home_ti, "/.terminfo");
+	size_t len = strlen (home);
+
+	if (len > sizeof (home_ti) - sizeof ("/.terminfo"))
+	    len = sizeof (home_ti) - sizeof ("/.terminfo");
+	memcpy (home_ti, home, len);
+	memcpy (home_ti + len, "/.terminfo", sizeof ("/.terminfo"));
 	Terminfo_Dirs [0] = home_ti;
      }