php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #69489 tempnam() should raise notice if falling back to temp dir
Submitted: 2015-04-20 14:37 UTC Modified: 2016-06-09 21:40 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: cmb@php.net Assigned: ab (profile)
Status: Closed Package: Filesystem function related
PHP Version: 5.6.8 OS: *
Private report: No CVE-ID: None
 [2015-04-20 14:37 UTC] cmb@php.net
Description:
------------
As has been pointed out in bug #55804, tempnam() doesn't explicitly
indicate when it is falling back to the system's temp directory. It
might be appropriate to raise a notice in this case.

Test script:
---------------
<?php

tempnam('non/existing/directory', 'pre');

Expected result:
----------------
A file is created in the system's temp directory, and additionally a
notice is raised:

    Notice: tempnam(): file created in the system's temporary
    directory in ... on line ...

Actual result:
--------------
A file is created in the system's temp directory without any
notice.

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-20 14:42 UTC] laruence@php.net
make sense to me, maybe you can make a PR for that?
 [2015-04-21 14:12 UTC] laruence@php.net
okey, a quick patch is:

diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c
index a88c823..439e5e4 100644
--- a/main/php_open_temporary_file.c
+++ b/main/php_open_temporary_file.c
@@ -287,6 +287,7 @@ def_tmp:
 	fd = php_do_open_temporary_file(dir, pfx, opened_path_p);
 	if (fd == -1) {
 		/* Use default temporary directory. */
+		php_error_docref(NULL, E_NOTICE, "file created in the system's temporary directory");
 		goto def_tmp;
 	}
 	return fd;

thanks
 [2015-04-21 14:13 UTC] laruence@php.net
-Status: Open +Status: Analyzed
 [2015-04-21 16:11 UTC] cmb@php.net
@laruence: that's also what I came up with in the meantime. :)
However, I don't know what other functionality expect tempnam might
also be affected by this change, because php_open_temporary_fd(_ex)
seems to be part of the public API, and might be used by
extensions. If that is so, the notice might not be desired
everywhere.

Anyhow, the biggest issue with submitting a PR is that the PHP test
suite is not running stable on (my) Windows.
 [2015-05-12 12:02 UTC] jpauli@php.net
Cant we disable this Notice in extension code (if needed) ?
 [2016-06-09 21:40 UTC] ab@php.net
-Status: Analyzed +Status: Closed -Assigned To: +Assigned To: ab
 [2016-06-09 21:40 UTC] ab@php.net
The PR is merged in 7.1.

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC