KiCad PCB EDA Suite
Loading...
Searching...
No Matches
WX_FILENAME Class Reference

A wrapper around a wxFileName which is much more performant with a subset of the API. More...

#include <wx_filename.h>

Public Member Functions

 WX_FILENAME (const wxString &aPath, const wxString &aFilename)
 
void SetFullName (const wxString &aFileNameAndExtension)
 
void SetPath (const wxString &aPath)
 
wxString GetName () const
 
wxString GetFullName () const
 
wxString GetPath () const
 
wxString GetFullPath () const
 
long long GetTimestamp ()
 

Static Public Member Functions

static void ResolvePossibleSymlinks (wxFileName &aFilename)
 
static bool SplitArchiveEntryName (const wxString &aEntryName, wxArrayString &aParts)
 Split an untrusted archive entry name into its path components.
 
static bool IsSafeChildPath (const wxString &aChild)
 Check that a child path is safe to append to a parent directory.
 
static bool ResolveArchiveEntryPath (const wxString &aDestDir, const wxString &aEntryName, wxFileName &aResult)
 Resolve an untrusted archive entry name against the directory it is extracted into.
 

Private Member Functions

void resolve ()
 

Private Attributes

wxFileName m_fn
 
wxString m_path
 
wxString m_fullName
 

Detailed Description

A wrapper around a wxFileName which is much more performant with a subset of the API.

A wrapper around a wxFileName which avoids expensive calls to wxFileName::SplitPath() and string concatenations by caching the path and filename locally and only resolving the wxFileName when it has to.

Definition at line 45 of file wx_filename.h.

Constructor & Destructor Documentation

◆ WX_FILENAME()

WX_FILENAME::WX_FILENAME ( const wxString & aPath,
const wxString & aFilename )

Definition at line 26 of file wx_filename.cpp.

References m_fn, m_fullName, and m_path.

Member Function Documentation

◆ GetFullName()

wxString WX_FILENAME::GetFullName ( ) const

Definition at line 52 of file wx_filename.cpp.

References m_fullName.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetFullPath()

wxString WX_FILENAME::GetFullPath ( ) const

Definition at line 64 of file wx_filename.cpp.

References m_fullName, and m_path.

Referenced by BOOST_AUTO_TEST_CASE(), FP_CACHE::Load(), GPCB_FPL_CACHE::Load(), and FP_CACHE::Save().

◆ GetName()

wxString WX_FILENAME::GetName ( ) const

Definition at line 45 of file wx_filename.cpp.

References m_fullName.

Referenced by BOOST_AUTO_TEST_CASE(), FP_CACHE::Load(), and GPCB_FPL_CACHE::Load().

◆ GetPath()

wxString WX_FILENAME::GetPath ( ) const

Definition at line 58 of file wx_filename.cpp.

References m_path.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetTimestamp()

long long WX_FILENAME::GetTimestamp ( )

Definition at line 78 of file wx_filename.cpp.

References m_fn, and resolve().

Referenced by FP_CACHE::Save().

◆ IsSafeChildPath()

bool WX_FILENAME::IsSafeChildPath ( const wxString & aChild)
staticnodiscard

Check that a child path is safe to append to a parent directory.

Rejects rather than sanitizes: an empty name, a name containing a path separator, or "." or ".." is not safe. A safe name is a single path component, so appending it to a directory cannot escape that directory.

Parameters
aChildis the child path to check.
Returns
true if aChild is a single safe path component.

Definition at line 160 of file wx_filename.cpp.

References splitSafeRelativePath().

Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ resolve()

void WX_FILENAME::resolve ( )
private

Definition at line 70 of file wx_filename.cpp.

References m_fn, and m_fullName.

Referenced by GetTimestamp().

◆ ResolveArchiveEntryPath()

bool WX_FILENAME::ResolveArchiveEntryPath ( const wxString & aDestDir,
const wxString & aEntryName,
wxFileName & aResult )
static

Resolve an untrusted archive entry name against the directory it is extracted into.

If this function returns false, don't attempt to extract the given entry. Use the aResult parameter for the final destination to extract to otherwise.

Parameters
aDestDiris the directory the archive is being extracted into.
aEntryNameis the raw, untrusted name read from the archive.
aResultis set to the full path to write to when the call succeeds.
Returns
true if the entry resolves to a path inside aDestDir.

Definition at line 168 of file wx_filename.cpp.

References SplitArchiveEntryName().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), PCM_TASK_MANAGER::extract(), and PROJECT_ARCHIVER::Unarchive().

◆ ResolvePossibleSymlinks()

◆ SetFullName()

void WX_FILENAME::SetFullName ( const wxString & aFileNameAndExtension)

Definition at line 32 of file wx_filename.cpp.

References m_fullName.

Referenced by FP_CACHE::Load(), and GPCB_FPL_CACHE::Load().

◆ SetPath()

void WX_FILENAME::SetPath ( const wxString & aPath)

Definition at line 38 of file wx_filename.cpp.

References m_fn, and m_path.

◆ SplitArchiveEntryName()

bool WX_FILENAME::SplitArchiveEntryName ( const wxString & aEntryName,
wxArrayString & aParts )
static

Split an untrusted archive entry name into its path components.

Rejects rather than sanitizes: an absolute or volume qualified name, or a ".." component anywhere, fails.

Parameters
aEntryNameis the raw, untrusted name read from the archive.
aPartsis filled with the path components on success.
Returns
true if the name is safe to append to an extraction directory.

Definition at line 154 of file wx_filename.cpp.

References splitSafeRelativePath().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), PCM_TASK_MANAGER::extract(), and ResolveArchiveEntryPath().

Member Data Documentation

◆ m_fn

wxFileName WX_FILENAME::m_fn
private

Definition at line 107 of file wx_filename.h.

Referenced by GetTimestamp(), resolve(), SetPath(), and WX_FILENAME().

◆ m_fullName

wxString WX_FILENAME::m_fullName
private

Definition at line 109 of file wx_filename.h.

Referenced by GetFullName(), GetFullPath(), GetName(), resolve(), SetFullName(), and WX_FILENAME().

◆ m_path

wxString WX_FILENAME::m_path
private

Definition at line 108 of file wx_filename.h.

Referenced by GetFullPath(), GetPath(), SetPath(), and WX_FILENAME().


The documentation for this class was generated from the following files: