Skip to content
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

Safer CPL path functions (RFC 105 implementation) #11639

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from

Conversation

rouault
Copy link
Member

@rouault rouault commented Jan 11, 2025

Candidate implementation of RFC 105 "Add and use safe path manipulation functions" / #11640

@rouault rouault force-pushed the CPLFormFilenameSafe branch from 9700ce9 to 7474f93 Compare January 11, 2025 16:08
…t semantic change in Rename() where case-sensitive find() used instead of ifind(), change which is more logical
…ExtensionSafe(...).c_str(), ...)

Using
```
find frmts ogr  -name "*.cpp"  -exec sed -i "s/EQUAL(CPLGetExtension(\([a-zA-Z]*\)),/EQUAL(CPLGetExtensionSafe(\1).c_str(),/" {} \;
```
@rouault rouault force-pushed the CPLFormFilenameSafe branch 2 times, most recently from 45b2948 to 48542cf Compare January 12, 2025 16:30
@rouault rouault added the funded through GSP Work funded through the GDAL Sponsorship Program label Jan 12, 2025
@rouault rouault force-pushed the CPLFormFilenameSafe branch 2 times, most recently from 0b81ed3 to 3e1327c Compare January 12, 2025 17:23
@coveralls
Copy link
Collaborator

coveralls commented Jan 12, 2025

Coverage Status

coverage: 70.099% (+0.006%) from 70.093%
when pulling bab3feb on rouault:CPLFormFilenameSafe
into 493ed18 on OSGeo:master.

@rouault rouault marked this pull request as draft January 13, 2025 00:39
…anTrailingSlashSafe(), CPLGenerateTempFilenameSafe(), CPLExpandTildeSafe(), CPLLaunderForFilenameSafe()
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 rouault force-pushed the CPLFormFilenameSafe branch from 9a9d549 to 0f47eed Compare January 13, 2025 19:28
@rouault rouault force-pushed the CPLFormFilenameSafe branch from 0f47eed to 2c17139 Compare January 13, 2025 20:00
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(/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(/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/(^\s+os[a-zA-Z_][a-zA-Z0-9_]*\s*\ = )${func}(\((.*)\);)/\1${func}Safe\2/g" {} \;
done
```
…ename() with CPLProjectRelativeFilenameSafe()
@rouault rouault force-pushed the CPLFormFilenameSafe branch from 99e6b7a to 8e52de7 Compare January 14, 2025 21:20
@rouault rouault force-pushed the CPLFormFilenameSafe branch from 8e52de7 to 1374969 Compare January 14, 2025 22:01
@rouault rouault force-pushed the CPLFormFilenameSafe branch from 1374969 to 06be59b Compare January 14, 2025 22:11
@rouault rouault force-pushed the CPLFormFilenameSafe branch from 06be59b to df669f9 Compare January 14, 2025 22:46
@rouault rouault changed the title [WIP] Safer CPL path functions Safer CPL path functions (RFC 105 implementation) Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
funded through GSP Work funded through the GDAL Sponsorship Program
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants