$OpenBSD: patch-Source_kwsys_SystemTools_cxx,v 1.7 2008/01/26 21:26:32 espie Exp $
--- Source/kwsys/SystemTools.cxx.orig	Mon Jan 21 19:59:55 2008
+++ Source/kwsys/SystemTools.cxx	Sat Jan 26 20:47:18 2008
@@ -371,7 +371,9 @@ bool SystemTools::MakeDirectory(const char* path)
   while((pos = dir.find('/', pos)) != kwsys_stl::string::npos)
     {
     topdir = dir.substr(0, pos);
-    Mkdir(topdir.c_str());
+    if (pos > 0 &&  !SystemTools::FileIsDirectory(topdir.c_str())) {
+	Mkdir(topdir.c_str());
+    }
     pos++;
     }
   if(dir[dir.size()-1] == '/')
@@ -963,13 +965,14 @@ char* SystemTools::AppendStrings(const char* str1, con
     return SystemTools::DuplicateString(str1);
     }
   size_t len1 = strlen(str1);
-  char *newstr = new char[len1 + strlen(str2) + 1];
+  size_t tot = len1 + strlen(str2) + 1;
+  char *newstr = new char[tot];
   if (!newstr)
     {
     return 0;
     }
-  strcpy(newstr, str1);
-  strcat(newstr + len1, str2);
+  strlcpy(newstr, str1, tot);
+  strlcat(newstr + len1, str2, tot - len1);
   return newstr;
 }
 
@@ -990,14 +993,15 @@ char* SystemTools::AppendStrings(
     }
 
   size_t len1 = strlen(str1), len2 = strlen(str2);
-  char *newstr = new char[len1 + len2 + strlen(str3) + 1];
+  size_t tot = len1 + len2 + strlen(str3) + 1;
+  char *newstr = new char[tot];
   if (!newstr)
     {
     return 0;
     }
-  strcpy(newstr, str1);
-  strcat(newstr + len1, str2);
-  strcat(newstr + len1 + len2, str3);
+  strlcpy(newstr, str1, tot);
+  strlcat(newstr + len1, str2, tot - len1);
+  strlcat(newstr + len1 + len2, str3, tot - len1 - len2);
   return newstr;
 }
 
@@ -1165,8 +1169,10 @@ char* SystemTools::DuplicateString(const char* str)
 {
   if (str)
     {
-    char *newstr = new char [strlen(str) + 1];
-    return strcpy(newstr, str);
+    size_t sz = strlen(str)+1;
+    char *newstr = new char [sz];
+    strlcpy(newstr, str, sz);
+    return newstr;
     }
   return NULL;
 }
@@ -1863,7 +1869,7 @@ bool SystemTools::ConvertDateMacroString(const char *s
   static char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
 
   char buffer[12];
-  strcpy(buffer, str);
+  strlcpy(buffer, str, sizeof buffer);
 
   buffer[3] = 0;
   char *ptr = strstr(month_names, buffer);
@@ -1914,7 +1920,7 @@ bool SystemTools::ConvertTimeStampMacroString(const ch
   static char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
 
   char buffer[27];
-  strcpy(buffer, str);
+  strlcpy(buffer, str, sizeof buffer);
 
   buffer[7] = 0;
   char *ptr = strstr(month_names, buffer + 4);
@@ -3412,12 +3418,12 @@ bool SystemTools::GetShortPath(const char* path, kwsys
   // if the path passed in has quotes around it, first remove the quotes
   if (path[0] == '"' && path[strlen(path)-1] == '"')
     {
-    strcpy(tempPath,path+1);
+    strlcpy(tempPath,path+1, size);
     tempPath[strlen(tempPath)-1] = '\0';
     }
   else
     {
-    strcpy(tempPath,path);
+    strlcpy(tempPath,path, size);
     }
   
   buffer[0] = 0;
