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

MEMORY_LEAK in phpdbg_prompt.c #12675

Closed
ellena13 opened this issue Nov 15, 2023 · 1 comment
Closed

MEMORY_LEAK in phpdbg_prompt.c #12675

ellena13 opened this issue Nov 15, 2023 · 1 comment

Comments

@ellena13
Copy link

ellena13 commented Nov 15, 2023

Description

Dynamic memory, referenced by res, is allocated at phpdbg_utils.c:154 :

PHPDBG_API char *phpdbg_resolve_path(const char *path) /* {{{ */
{
char resolved_name[MAXPATHLEN];
if (expand_filepath(path, resolved_name) == NULL) {
return NULL;
}
return strdup(resolved_name);
} /* }}} */

by calling function phpdbg_resolve_path at phpdbg_prompt.c:405 and lost at phpdbg_prompt.c:411 :

char *res = phpdbg_resolve_path(param->str);
size_t res_len = strlen(res);
if ((res_len != PHPDBG_G(exec_len)) || (memcmp(res, PHPDBG_G(exec), res_len) != SUCCESS)) {
if (PHPDBG_G(in_execution)) {
if (phpdbg_ask_user_permission("Do you really want to stop execution to set a new execution context?") == FAILURE) {
return FAILURE;
}

The allocated memory will be lost even if the condition at phpdbg_prompt.c:408 is false.

Found by Linux Verification Center (portal.linuxtesting.ru) with SVACE.

Author E. Bykhanova.

PHP Version

PHP 8.2.3

Operating System

ALT Linux

@ellena13 ellena13 changed the title MEMORY_LEAK in /sapi/phpdbg/phpdbg_prompt.c MEMORY_LEAK in phpdbg_prompt.c Nov 15, 2023
@nielsdos nielsdos self-assigned this Nov 15, 2023
@nielsdos
Copy link
Member

nielsdos commented Nov 15, 2023

There's even a second one in the Execution context not changed path. I'll get to it.
Thanks for reporting!

nielsdos added a commit to nielsdos/php-src that referenced this issue Nov 15, 2023
Have to use file_put_contents() instead of --FILE-- because we have to
actually load it using the exec command, *and* have to make multiple
files, and note that we can only load files relative from the current
directory, so we can't rely on files being in the sapi/phpdbg/tests
folder.
@nielsdos nielsdos linked a pull request Nov 15, 2023 that will close this issue
nielsdos added a commit to nielsdos/php-src that referenced this issue Nov 15, 2023
Have to use file_put_contents() instead of --FILE-- because we have to
actually load it using the exec command, *and* have to make multiple
files, and note that we can only load files relative from the current
directory, so we can't rely on files being in the sapi/phpdbg/tests
folder.
nielsdos added a commit that referenced this issue Nov 15, 2023
* PHP-8.2:
  Use __DIR__-relative path in tests
  Fix GH-12675: MEMORY_LEAK in phpdbg_prompt.c
nielsdos added a commit that referenced this issue Nov 15, 2023
* PHP-8.3:
  Use __DIR__-relative path in tests
  Fix GH-12675: MEMORY_LEAK in phpdbg_prompt.c
ramsey pushed a commit that referenced this issue Nov 23, 2023
Have to use file_put_contents() instead of --FILE-- because we have to
actually load it using the exec command, *and* have to make multiple
files, and note that we can only load files relative from the current
directory, so we can't rely on files being in the sapi/phpdbg/tests
folder.

Closes GH-12680.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants