openbsd-ports/x11/wxWidgets/patches/patch-src_common_filefn_cpp
todd b25888b419 wxWidgets 2.4.2, C++ cross-platform GUI toolkit
www: http://www.wxwidgets.org/

from Andrew Dalgleish   < openbsd at ajd dot net dot au >
many thanks for much persistence!
2004-07-16 21:01:35 +00:00

96 lines
4.2 KiB
Plaintext

$OpenBSD: patch-src_common_filefn_cpp,v 1.1.1.1 2004/07/16 21:01:35 todd Exp $
--- src/common/filefn.cpp.orig Sun Jun 8 17:58:14 2003
+++ src/common/filefn.cpp Thu Jun 26 11:05:10 2003
@@ -169,6 +169,8 @@ const off_t wxInvalidOffset = (off_t)-1;
// macros
// ----------------------------------------------------------------------------
+#define min(a, b) (((a) < (b)) ? (a) : (b))
+
// we need to translate Mac filenames before passing them to OS functions
#define OS_FILENAME(s) (s.fn_str())
@@ -299,8 +301,8 @@ wxString wxPathList::FindValidPath (cons
wxStrcpy (wxFileFunctionsBuffer, path);
wxChar ch = wxFileFunctionsBuffer[wxStrlen(wxFileFunctionsBuffer)-1];
if (ch != wxT('\\') && ch != wxT('/'))
- wxStrcat (wxFileFunctionsBuffer, wxT("/"));
- wxStrcat (wxFileFunctionsBuffer, filename);
+ strlcat (wxFileFunctionsBuffer, wxT("/"), sizeof(wxFileFunctionsBuffer));
+ strlcat (wxFileFunctionsBuffer, filename, sizeof(wxFileFunctionsBuffer));
#ifdef __WINDOWS__
wxUnix2DosFilename (wxFileFunctionsBuffer);
#endif
@@ -479,12 +481,12 @@ wxChar *wxCopyAbsolutePath(const wxStrin
wxChar ch = buf[wxStrlen(buf) - 1];
#ifdef __WXMSW__
if (ch != wxT('\\') && ch != wxT('/'))
- wxStrcat(buf, wxT("\\"));
+ strlcat(buf, wxT("\\"), sizeof(buf));
#else
if (ch != wxT('/'))
- wxStrcat(buf, wxT("/"));
+ strlcat(buf, wxT("/"), sizeof(buf));
#endif
- wxStrcat(buf, wxFileFunctionsBuffer);
+ strlcat(buf, wxFileFunctionsBuffer, sizeof(buf));
return copystring( wxRealPath(buf) );
}
return copystring( wxFileFunctionsBuffer );
@@ -684,12 +686,12 @@ wxContractPath (const wxString& filename
if (envname != WXSTRINGCAST NULL && (val = wxGetenv (WXSTRINGCAST envname)) != NULL &&
(tcp = wxStrstr (dest, val)) != NULL)
{
- wxStrcpy (wxFileFunctionsBuffer, tcp + wxStrlen (val));
- *tcp++ = wxT('$');
- *tcp++ = wxT('{');
- wxStrcpy (tcp, WXSTRINGCAST envname);
- wxStrcat (tcp, wxT("}"));
- wxStrcat (tcp, wxFileFunctionsBuffer);
+ strlcpy(wxFileFunctionsBuffer, dest, min(tcp-dest+1, sizeof(wxFileFunctionsBuffer)));
+ strlcat(wxFileFunctionsBuffer, wxT("${"), sizeof(wxFileFunctionsBuffer));
+ strlcat(wxFileFunctionsBuffer, WXSTRINGCAST envname, sizeof(wxFileFunctionsBuffer));
+ strlcat(wxFileFunctionsBuffer, wxT("}"), sizeof(wxFileFunctionsBuffer));
+ strlcat(wxFileFunctionsBuffer, tcp + strlen(val), sizeof(wxFileFunctionsBuffer));
+ strlcpy(dest, wxFileFunctionsBuffer, sizeof(dest));
}
// Handle User's home (ignore root homes!)
@@ -698,11 +700,11 @@ wxContractPath (const wxString& filename
(len = wxStrlen(val)) > 2 &&
wxStrncmp(dest, val, len) == 0)
{
- wxStrcpy(wxFileFunctionsBuffer, wxT("~"));
+ strlcpy(wxFileFunctionsBuffer, wxT("~"), sizeof(wxFileFunctionsBuffer));
if (user != wxT(""))
- wxStrcat(wxFileFunctionsBuffer, (const wxChar*) user);
- wxStrcat(wxFileFunctionsBuffer, dest + len);
- wxStrcpy (dest, wxFileFunctionsBuffer);
+ strlcat(wxFileFunctionsBuffer, (const wxChar*) user, sizeof(wxFileFunctionsBuffer));
+ strlcat(wxFileFunctionsBuffer, dest + len, sizeof(wxFileFunctionsBuffer));
+ strlcpy(dest, wxFileFunctionsBuffer, sizeof(dest));
}
return dest;
@@ -899,7 +901,7 @@ wxString wxMacFSSpec2MacFilename( const
if (theStatus == noErr) {
// append file name to path
// includes previously prepended path separator
- strcat(thePath, theFileName);
+ strlcat(thePath, theFileName, sizeof(thePath));
}
// create path string for return value
@@ -947,9 +949,8 @@ void wxMacFilename2FSSpec( const char *p
if ( strchr( path , ':' ) == NULL )
{
// try whether it is a volume / or a mounted volume
- strncpy( sMacFileNameConversion , path , 1000 ) ;
- sMacFileNameConversion[998] = 0 ;
- strcat( sMacFileNameConversion , ":" ) ;
+ strlcpy( sMacFileNameConversion , path , sizeof(sMacFileNameConversion)) ;
+ strlcat( sMacFileNameConversion , ":" , sizeof(sMacFileNameConversion)) ;
err = FSpLocationFromFullPath( strlen(sMacFileNameConversion) , sMacFileNameConversion , spec ) ;
}
else