Skip to content

Commit

Permalink
- fixed buffer overrun in case of very long paths - removed dead code…
Browse files Browse the repository at this point in the history
… - properly include CoreFoundation on OS X - removed some obsolete comments
  • Loading branch information
seanm authored and malaterre committed Jan 19, 2016
1 parent e73a310 commit ea48a8a
Showing 1 changed file with 3 additions and 54 deletions.
57 changes: 3 additions & 54 deletions Source/Common/gdcmSystem.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
Copyright (c) 2006-2016 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
Expand Down Expand Up @@ -43,9 +43,7 @@
#define snprintf _snprintf
#endif
#ifdef __APPLE__
#include <CoreFoundation/CFBase.h>
#include <CoreFoundation/CFBundle.h>
#include <CoreFoundation/CFURL.h>
#include <CoreFoundation/CoreFoundation.h>
#endif // __APPLE__

#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) ||defined(__BORLANDC__) || defined(__MINGW32__))
Expand Down Expand Up @@ -398,61 +396,13 @@ size_t System::FileSize(const char* filename)
return size2;
}

#if 0
const char *System::GetCurrentDataDirectory()
{
#ifdef _WIN32
static char path[MAX_PATH];
gdcm::Filename fn( GetCurrentProcessFileName() );
if ( !fn.IsEmpty() )
{
std::string str = fn.GetPath();
str += "/../" GDCM_INSTALL_DATA_DIR;
strcpy(path, str.c_str());
return path;
}
#else

static char path[PATH_MAX];

#ifdef __APPLE__
Boolean success = false;
CFURLRef pathURL = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
if (pathURL != NULL)
{
success = CFURLGetFileSystemRepresentation(pathURL, true /*resolveAgainstBase*/, (unsigned char*) path, PATH_MAX);
CFRelease(pathURL);
}
if (success)
{
strncat(path, "/" GDCM_INSTALL_DATA_DIR, PATH_MAX);
return path;
}
#endif

gdcm::Filename fn( GetCurrentProcessFileName() );
if ( !fn.IsEmpty() )
{
std::string str = fn.GetPath();
str += "/../" GDCM_INSTALL_DATA_DIR;
strcpy(path, str.c_str());
return path;
}
#endif
return 0;
}
#endif

/*
* TODO:
* check cygwin
* check beos : get_next_image_info
* check solaris
* check hpux
* check os2: DosGetInfoBlocks / DosQueryModuleName
* check macosx :
* ProcessSerialNumber psn = {kNoProcess, kCurrentProcess};
* GetProcessInformation -> FSMakeFSSpec
* ...
*/
const char *System::GetCurrentProcessFileName()
Expand All @@ -464,7 +414,6 @@ const char *System::GetCurrentProcessFileName()
return buf;
}
#elif defined(__APPLE__)
// _NSGetExecutablePath()
static char buf[PATH_MAX];
Boolean success = false;
CFURLRef pathURL = CFBundleCopyExecutableURL(CFBundleGetMainBundle());
Expand Down Expand Up @@ -544,7 +493,7 @@ const char *System::GetCurrentResourcesDirectory()
}
if (success)
{
strncat(path, "/" GDCM_INSTALL_DATA_DIR, PATH_MAX);
strlcat(path, "/" GDCM_INSTALL_DATA_DIR, PATH_MAX);
return path;
}
#endif
Expand Down

0 comments on commit ea48a8a

Please sign in to comment.