$OpenBSD: patch-src_motif_utils_cpp,v 1.1.1.1 2004/07/16 21:01:36 todd Exp $
--- src/motif/utils.cpp.orig	2003-09-20 20:24:35.000000000 +1000
+++ src/motif/utils.cpp	2003-10-04 13:24:11.000000000 +1000
@@ -225,26 +225,26 @@ int wxGetOsVersion(int *majorVsn, int *m
 // Read $HOME for what it says is home, if not
 // read $USER or $LOGNAME for user name else determine
 // the Real User, then determine the Real home dir.
-static char * GetIniFile (char *dest, const char *filename)
+static char * GetIniFile (char *dest, size_t size, const char *filename)
 {
     char *home = NULL;
     if (filename && wxIsAbsolutePath(filename))
     {
-        strcpy(dest, filename);
+        strlcpy(dest, filename, size);
     }
     else if ((home = wxGetUserHome("")) != NULL)
     {
-        strcpy(dest, home);
+        strlcpy(dest, home, size);
         if (dest[strlen(dest) - 1] != '/')
-            strcat (dest, "/");
+            strlcat (dest, "/", size);
         if (filename == NULL)
         {
             if ((filename = getenv ("XENVIRONMENT")) == NULL)
                 filename = ".Xdefaults";
         }
         else if (*filename != '.')
-            strcat (dest, ".");
-        strcat (dest, filename);
+            strlcat (dest, ".", size);
+        strlcat (dest, filename, size);
     } else
     {
         dest[0] = '\0';
@@ -252,20 +252,20 @@ static char * GetIniFile (char *dest, co
     return dest;
 }
 
-static char *GetResourcePath(char *buf, const char *name, bool create = FALSE)
+static char *GetResourcePath(char *buf, size_t buflen, const char *name, bool create = FALSE)
 {
     if (create && wxFileExists (name) ) {
-        strcpy(buf, name);
+        strlcpy(buf, name, buflen);
         return buf; // Exists so ...
     }
 
     if (*name == '/')
-        strcpy(buf, name);
+        strlcpy(buf, name, buflen);
     else {
         // Put in standard place for resource files if not absolute
-        strcpy (buf, DEFAULT_XRESOURCE_DIR);
-        strcat (buf, "/");
-        strcat (buf, (const char*) wxFileNameFromPath (name));
+        strlcpy (buf, DEFAULT_XRESOURCE_DIR, buflen);
+        strlcat (buf, "/", buflen);
+        strlcat (buf, (const char*) wxFileNameFromPath (name), buflen);
     }
 
     if (create) {
@@ -295,7 +295,7 @@ wxFlushResources (void)
     {
         const char *file = node->GetKeyString();
         // If file doesn't exist, create it first.
-        (void)GetResourcePath(nameBuffer, file, TRUE);
+        (void)GetResourcePath(nameBuffer, sizeof(nameBuffer), file, TRUE);
 
         XrmDatabase database = (XrmDatabase) node->Data ();
         XrmPutFileDatabase (database, nameBuffer);
@@ -314,7 +314,7 @@ bool wxWriteResource(const wxString& sec
 {
     char buffer[500];
 
-    (void) GetIniFile (buffer, file);
+    (void) GetIniFile (buffer, sizeof(buffer), file);
 
     XrmDatabase database;
     wxNode *node = wxResourceCache.Find (buffer);
@@ -327,9 +327,9 @@ bool wxWriteResource(const wxString& sec
     }
 
     char resName[300];
-    strcpy (resName, (const char*) section);
-    strcat (resName, ".");
-    strcat (resName, (const char*) entry);
+    strlcpy (resName, (const char*) section, sizeof(resName));
+    strlcat (resName, ".", sizeof(resName));
+    strlcat (resName, (const char*) entry, sizeof(resName));
 
     XrmPutStringResource (&database, resName, value);
     return TRUE;
@@ -338,21 +338,21 @@ bool wxWriteResource(const wxString& sec
 bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file)
 {
     char buf[50];
-    sprintf(buf, "%.4f", value);
+    snprintf(buf, sizeof(buf), "%.4f", value);
     return wxWriteResource(section, entry, buf, file);
 }
 
 bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file)
 {
     char buf[50];
-    sprintf(buf, "%ld", value);
+    snprintf(buf, sizeof(buf), "%ld", value);
     return wxWriteResource(section, entry, buf, file);
 }
 
 bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file)
 {
     char buf[50];
-    sprintf(buf, "%d", value);
+    snprintf(buf, sizeof(buf), "%d", value);
     return wxWriteResource(section, entry, buf, file);
 }
 
@@ -372,7 +372,7 @@ bool wxGetResource(const wxString& secti
 
         // Is this right? Trying to get it to look in the user's
         // home directory instead of current directory -- JACS
-        (void) GetIniFile (buffer, file);
+        (void) GetIniFile (buffer, sizeof(buffer), file);
 
         wxNode *node = wxResourceCache.Find (buffer);
         if (node)
@@ -389,9 +389,9 @@ bool wxGetResource(const wxString& secti
     XrmValue xvalue;
     char *str_type[20];
     char buf[150];
-    strcpy (buf, section);
-    strcat (buf, ".");
-    strcat (buf, entry);
+    strlcpy (buf, section, sizeof(buf));
+    strlcat (buf, ".", sizeof(buf));
+    strlcat (buf, entry, sizeof(buf));
 
     Bool success = XrmGetResource (database, buf, "*", str_type,
         &xvalue);
@@ -408,7 +408,7 @@ bool wxGetResource(const wxString& secti
             delete[] *value;
 
         *value = new char[xvalue.size + 1];
-        strncpy (*value, xvalue.addr, (int) xvalue.size);
+        strlcpy (*value, xvalue.addr, (int) xvalue.size);
         return TRUE;
     }
     return FALSE;
@@ -472,8 +472,8 @@ void wxXMergeDatabases (wxApp * theApp, 
     char *environment;
     wxString classname = theApp->GetClassName();
     char name[256];
-    (void) strcpy (name, "/usr/lib/X11/app-defaults/");
-    (void) strcat (name, (const char*) classname);
+    (void) strlcpy (name, "/usr/lib/X11/app-defaults/", sizeof(name));
+    (void) strlcat (name, (const char*) classname, sizeof(name));
 
     /* Get application defaults file, if any */
     applicationDB = XrmGetFileDatabase (name);
@@ -491,7 +491,7 @@ void wxXMergeDatabases (wxApp * theApp, 
     }
     else
     {
-        (void) GetIniFile (filename, NULL);
+        (void) GetIniFile (filenamebuf, sizeof(filenamebuf), NULL);
         serverDB = XrmGetFileDatabase (filename);
     }
     XrmMergeDatabases (serverDB, &wxResourceDatabase);
@@ -502,12 +502,10 @@ void wxXMergeDatabases (wxApp * theApp, 
 
     if ((environment = getenv ("XENVIRONMENT")) == NULL)
     {
-        size_t len;
-        environment = GetIniFile (filename, NULL);
-        len = strlen (environment);
+        GetIniFile (filenamebuf, sizeof(filenamebuf), NULL);
         wxString hostname = wxGetHostName();
         if ( !!hostname )
-            strncat(environment, hostname, 1024 - len);
+            strlcat(filenamebuf, hostname, sizeof(filenamebuf));
     }
     homeDB = XrmGetFileDatabase (environment);
     XrmMergeDatabases (homeDB, &wxResourceDatabase);
@@ -1162,17 +1160,17 @@ char * wxFindAccelerator (const char *s)
         {
             *p = '\0';
             if (buf[0])
-                strcat (buf, " ");
+                strlcat (buf, " ", sizeof(buf));
             if (strcmp (s, "Alt"))
-                strcat (buf, s);
+                strlcat (buf, s, sizeof(buf));
             else
-                strcat (buf, "Meta");
+                strlcat (buf, "Meta", sizeof(buf));
             s = p++;
         }
         else
         {
-            strcat (buf, "<Key>");
-            strcat (buf, s);
+            strlcat (buf, "<Key>", sizeof(buf));
+            strlcat (buf, s, sizeof(buf));
             break;
         }
     }
