Skip to content

ext/mysqli: Use tempnam to make tracefiles unique #17473

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ext/mysqli/tests/mysqli_debug.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ if (defined('MYSQLI_DEBUG_TRACE_ENABLED') && !MYSQLI_DEBUG_TRACE_ENABLED)
<?php
require_once 'connect.inc';

$trace_file = tempnam(sys_get_temp_dir(), "mysqli_debug_phpt");

// NOTE: documentation is not clear on this: function always return NULL or TRUE
if (true !== ($tmp = mysqli_debug(sprintf('d:t:O,%s/mysqli_debug_phpt.trace', sys_get_temp_dir()))))
if (true !== ($tmp = mysqli_debug(sprintf('d:t:O,%s', $trace_file))))
printf("[002] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);

// table.inc will create a database connection and run some SQL queries, therefore
// the debug file should have entries
require_once 'table.inc';

clearstatcache();
$trace_file = sprintf('%s/mysqli_debug_phpt.trace', sys_get_temp_dir());
if (!file_exists($trace_file))
printf("[003] Trace file '%s' has not been created\n", $trace_file);
if (filesize($trace_file) < 50)
Expand Down
5 changes: 3 additions & 2 deletions ext/mysqli/tests/mysqli_debug_append.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ if (substr(PHP_OS, 0, 3) == 'WIN') die("skip this test is not for Windows platfo
<?php
require_once 'connect.inc';

if (true !== ($tmp = mysqli_debug(sprintf('d:t:O,%s/mysqli_debug_phpt.trace', sys_get_temp_dir()))))
$trace_file = tempnam(sys_get_temp_dir(), "mysqli_debug_phpt");

if (true !== ($tmp = mysqli_debug(sprintf('d:t:O,%s', $trace_file))))
printf("[001] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);

// table.inc will create a database connection and run some SQL queries, therefore
// the debug file should have entries
require_once 'table.inc';

clearstatcache();
$trace_file = sprintf('%s/mysqli_debug_phpt.trace', sys_get_temp_dir());
if (!file_exists($trace_file))
printf("[002] Trace file '%s' has not been created\n", $trace_file);
if (filesize($trace_file) < 50)
Expand Down
2 changes: 1 addition & 1 deletion ext/mysqli/tests/mysqli_debug_control_string.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if (defined('MYSQLI_DEBUG_TRACE_ENABLED') && !MYSQLI_DEBUG_TRACE_ENABLED)
unlink($trace_file);
}

$trace_file = sprintf('%s%s%s', sys_get_temp_dir(), DIRECTORY_SEPARATOR, 'mysqli_debug_phpt.trace');
$trace_file = tempnam(sys_get_temp_dir(), "mysqli_debug_phpt");
try_control_string($link, 't:,,:o,' . $trace_file, $trace_file, 10);
try_control_string($link, ':' . chr(0) . 'A,' . $trace_file, $trace_file, 20);
try_control_string($link, 't:o,' . $trace_file . ':abc', $trace_file, 30);
Expand Down
4 changes: 2 additions & 2 deletions ext/mysqli/tests/mysqli_debug_mysqlnd_control_string.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if (defined('MYSQLI_DEBUG_TRACE_ENABLED') && !MYSQLI_DEBUG_TRACE_ENABLED)
return trim(substr(file_get_contents($trace_file), 0, 100024));
}

$trace_file = sprintf('%s%s%s', sys_get_temp_dir(), DIRECTORY_SEPARATOR, 'mysqli_debug_phpt.trace');
$trace_file = tempnam(sys_get_temp_dir(), "mysqli_debug_phpt");

$trace = try_control_string($link, 't:O,' . $trace_file, $trace_file, 10);
if (!strstr($trace, 'SELECT * FROM test') && !strstr($trace, 'mysql_real_query'))
Expand Down Expand Up @@ -218,5 +218,5 @@ if (defined('MYSQLI_DEBUG_TRACE_ENABLED') && !MYSQLI_DEBUG_TRACE_ENABLED)
require_once 'clean_table.inc';
?>
--EXPECTF--
[083][control string 'n:O,%smysqli_debug_phpt.trace'] Trace file has not been written.
[083][control string 'n:O,%s'] Trace file has not been written.
done%s
2 changes: 1 addition & 1 deletion ext/mysqli/tests/mysqli_debug_mysqlnd_only.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if (defined('MYSQLI_DEBUG_TRACE_ENABLED') && !MYSQLI_DEBUG_TRACE_ENABLED)
'_mysqlnd_pemalloc',
'_mysqlnd_perealloc',
);
$trace_file = sprintf('%s%s%s', sys_get_temp_dir(), DIRECTORY_SEPARATOR, 'mysqli_debug_phpt.trace');
$trace_file = tempnam(sys_get_temp_dir(), "mysqli_debug_phpt");

$trace = try_control_string($link, 't:m:O,' . $trace_file, $trace_file, 10);
if (!strstr($trace, 'SELECT * FROM test') && !strstr($trace, 'mysql_real_query'))
Expand Down
Loading