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

fix: add try/catch to real_path() in clean_path() #7195

Merged
merged 1 commit into from
Jan 29, 2023

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Jan 28, 2023

Description
From Slack and https://forum.codeigniter.com/showthread.php?tid=86511

If real_path() throws Exception, we cannot see the true backtrace.

Before:
Screenshot 2023-01-28 at 21-23-03 ErrorException

After:
Screenshot 2023-01-28 at 21-23-28 ValueError

Before:

CRITICAL - 2023-01-28 12:32:16 --> Uncaught ValueError: realpath(): Argument #1 ($path) must not contain any null bytes in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Common.php:94
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Common.php(94): realpath('\x13\x00#\xB6\t\xC5\xE6\xC9/C\xB4\xB5')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(524): clean_path('\x13\x00#\xB6\t\xC5\xE6\xC9/C\xB4\xB5')
#2 [internal function]: CodeIgniter\Debug\Exceptions::CodeIgniter\Debug\{closure}('\x13\x00#\xB6\t\xC5\xE6\xC9/C\xB4\xB5')
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(529): array_map(Object(Closure), Array)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(123): CodeIgniter\Debug\Exceptions::renderBacktrace(Array)
#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ValueError))
#6 {main}
  thrown
in SYSTEMPATH/Common.php on line 94.
 1 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()

After:

CRITICAL - 2023-01-28 12:32:44 --> realpath(): Argument #1 ($path) must not contain any null bytes
in APPPATH/Controllers/Home.php on line 9.
 1 APPPATH/Controllers/Home.php(9): realpath('error file path: %13%00%23%B6%09%C5%E6%C9%2FC%B4%B5')
 2 SYSTEMPATH/CodeIgniter.php(934): App\Controllers\Home->index()
 3 SYSTEMPATH/CodeIgniter.php(499): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Home))
 4 SYSTEMPATH/CodeIgniter.php(368): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
 5 FCPATH/index.php(67): CodeIgniter\CodeIgniter->run()
 6 SYSTEMPATH/Commands/Server/rewrite.php(47): require_once('FCPATH/index.php')

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • [] User guide updated
  • Conforms to style guide

@kenjis kenjis changed the title fix: add try/catch ValueError from real_path() fix: add try/catch to real_path() Jan 28, 2023
@kenjis kenjis changed the title fix: add try/catch to real_path() fix: add try/catch to real_path() in clean_path() Jan 28, 2023
@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Jan 28, 2023
@kenjis kenjis merged commit 8c8ed6d into codeigniter4:develop Jan 29, 2023
@kenjis kenjis deleted the fix-clean_path-error branch January 29, 2023 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants