-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Safer CPL path functions #11639
Draft
rouault
wants to merge
17
commits into
OSGeo:master
Choose a base branch
from
rouault:CPLFormFilenameSafe
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+2,147
−1,533
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixes https://issues.oss-fuzz.com/issues/388868487 This is just a band-aid... The use of CPLFormFilename() and friends is so dangerous with the rotating TLS buffers that may end up overwritten if too many calls are nested...
rouault
force-pushed
the
CPLFormFilenameSafe
branch
from
January 11, 2025 16:08
9700ce9
to
7474f93
Compare
…etExtensionSafe()
…), CPLGetExtensionSafe()
…t semantic change in Rename() where case-sensitive find() used instead of ifind(), change which is more logical
…,' with 'poOpenInfo->IsExtensionEqualToCI('
…ExtensionSafe(...).c_str(), ...) Using ``` find frmts ogr -name "*.cpp" -exec sed -i "s/EQUAL(CPLGetExtension(\([a-zA-Z]*\)),/EQUAL(CPLGetExtensionSafe(\1).c_str(),/" {} \; ```
rouault
force-pushed
the
CPLFormFilenameSafe
branch
from
January 11, 2025 21:18
7474f93
to
0221c26
Compare
…anTrailingSlashSafe(), CPLGenerateTempFilenameSafe(), CPLExpandTildeSafe(), CPLLaunderForFilenameSafe()
rouault
force-pushed
the
CPLFormFilenameSafe
branch
from
January 12, 2025 16:30
45b2948
to
48542cf
Compare
rouault
added
the
funded through GSP
Work funded through the GDAL Sponsorship Program
label
Jan 12, 2025
rouault
force-pushed
the
CPLFormFilenameSafe
branch
from
January 12, 2025 16:51
48542cf
to
0b81ed3
Compare
…r automation scripts
Done with following script: ```bash funcs=(CPLGetPath CPLGetDirname CPLGetBasename CPLGetExtension CPLFormFilename CPLFormCIFilename CPLResetExtension CPLProjectRelativeFilename CPLCleanTrailingSlash CPLGenerateTempFilename CPLExpandTilde CPLLaunderForFilename) for func in "${funcs[@]}"; do find frmts ogr -name "*.cpp" -exec sed -i -E "s/const char \*([a-zA-Z_][a-zA-Z0-9_]*)\(${func}\(([^()]*(\([^()]*\))?[^()]*)\)\);/const char *\1 = ${func}(\2);/g" {} \; done for func in "${funcs[@]}"; do find frmts ogr -name "*.cpp" -exec sed -i -E "s/CPLString\(${func}\(([^()]*(\([^()]*\))?[^()]*)\)\)/CPLString(${func}Safe(\1))/g" {} \; find frmts ogr -name "*.cpp" -exec sed -i -E "s/std::string\(${func}\(([^()]*(\([^()]*\))?[^()]*)\)\)/std::string(${func}Safe(\1))/g" {} \; done for func in "${funcs[@]}"; do find frmts ogr -name "*.cpp" -exec sed -i -E "s/(CPLString\s+[a-zA-Z_][a-zA-Z0-9_]*\s*\()${func}\((.*)\)/\1${func}Safe(\2)/g" {} \; find frmts ogr -name "*.cpp" -exec sed -i -E "s/(std::string\s+[a-zA-Z_][a-zA-Z0-9_]*\s*\()${func}\((.*)\)/\1${func}Safe(\2)/g" {} \; done for func in "${funcs[@]}"; do find frmts ogr -name "*.cpp" -exec sed -i -E "s/(std::string\s+[a-zA-Z_][a-zA-Z0-9_]*\s*\()${func}\(([^)]+)\)/\1${func}Safe(\2)/g" {} \; find frmts ogr -name "*.cpp" -exec sed -i -E "s/(CPLString\s+[a-zA-Z_][a-zA-Z0-9_]*\s*\()${func}\(([^)]+)\)/\1${func}Safe(\2)/g" {} \; done for func in "${funcs[@]}"; do find frmts ogr -name "*.cpp" -exec sed -i -E "s/\(${func}\(([^()]*(\([^()]*\))?[^()]*)\)/(${func}Safe(\1).c_str()/g" {} \; find frmts ogr -name "*.cpp" -exec sed -i -E "s/, ${func}\(([^()]*(\([^()]*\))?[^()]*)\)/, ${func}Safe(\1).c_str()/g" {} \; done ```
Done with following script: ```bash funcs=(CPLGetPath CPLGetDirname CPLGetBasename CPLGetExtension CPLFormFilename CPLFormCIFilename CPLResetExtension CPLProjectRelativeFilename CPLCleanTrailingSlash CPLGenerateTempFilename CPLExpandTilde CPLLaunderForFilename) for func in "${funcs[@]}"; do find frmts ogr -name "*.cpp" -exec sed -i -E "s/(CPLString\s+[a-zA-Z_][a-zA-Z0-9_]*\s*\ = )${func}\((.*)\)/\1${func}Safe(\2)/g" {} \; find frmts ogr -name "*.cpp" -exec sed -i -E "s/(std::string\s+[a-zA-Z_][a-zA-Z0-9_]*\s*\ = )${func}\((.*)\)/\1${func}Safe(\2)/g" {} \; done ```
rouault
force-pushed
the
CPLFormFilenameSafe
branch
from
January 12, 2025 17:23
0b81ed3
to
3e1327c
Compare
… CPLGetBasenameSafe()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Candidate implementation of RFC 105 "Add and use safe path manipulation functions" / #11640