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

Fixes #12514 - Uses sys_get_temp_dir in place of empty string for temporary file creation #12519

Closed
wants to merge 1 commit into from

Conversation

sudheesh001
Copy link
Contributor

@sudheesh001 sudheesh001 commented Aug 31, 2016

Fix for #12514

…ng for temporary file creation

Signed-off-by: Sudheesh Singanamalla <sudheesh1995@outlook.com>
@codecov-io
Copy link

codecov-io commented Aug 31, 2016

Current coverage is 54.33% (diff: 100%)

No coverage report found for master at f4d3704.

Powered by Codecov. Last update f4d3704...da60d4f

@nijel
Copy link
Contributor

nijel commented Sep 2, 2016

I think the code should be rather changed to share logic with File class, which does handle various openbasedir restrictions just fine, see https://github.com/phpmyadmin/phpmyadmin/blob/master/libraries/File.php#L465

@sudheesh001
Copy link
Contributor Author

@nijel So should this be rewritten as follows ?

$tmpfname = null;
if (! empty($GLOBALS['cfg']['TempDir']) && @is_writable($GLOBALS['cfg']['TempDir'])) {
        $tmp_subdir = $GLOBALS['cfg']['TempDir'];
} else {
        $tmp_subdir = ini_get('upload_tmp_dir');
        if (empty($tmp_subdir)) {
            $tmp_subdir = sys_get_temp_dir();
        }
        $tmp_subdir = rtrim($tmp_subdir, DIRECTORY_SEPARATOR);
}
$tmpfname = tempnam($tmp_subdir, $enc);

@nijel
Copy link
Contributor

nijel commented Sep 7, 2016

Rather File class should export this code and this method should should be used by both File class and here in the Kanji encoding code. We don't want similar code copied over to multiple places...

@sudheesh001
Copy link
Contributor Author

@nijel I've been looking through the code and realized that there's a todo that's put above the checkUploadedFile() function which says
@todo move check of $cfg['TempDir'] into Config?

So should this part be moved into a function inside Config.php as follows ?

public function getDefaultTempDirectory() {
    $tmp_subdir = null;
    if (! empty($GLOBALS['cfg']['TempDir']) && @is_writable($GLOBALS['cfg']['TempDir'])) {
        $tmp_subdir = $GLOBALS['cfg']['TempDir'];
    } else {
        $tmp_subdir = ini_get('upload_tmp_dir');
        if (empty($tmp_subdir)) {
            $tmp_subdir = sys_get_temp_dir();
        }
        $tmp_subdir = rtrim($tmp_subdir, DIRECTORY_SEPARATOR);
    }
    return $tmp_subdir;
}

And then call this by doing $this->getDefaultTempDirectory() in the Encoding.php and File.php functions ?

Is that the right way to do this ?

@nijel
Copy link
Contributor

nijel commented Sep 19, 2016

Yes, @sudheesh001 , that sounds like a good approach.

@nijel nijel self-assigned this Sep 19, 2016
@nijel
Copy link
Contributor

nijel commented Sep 26, 2016

@sudheesh001 will you get anytime soon to implementing described change?

@nijel nijel mentioned this pull request Nov 9, 2016
@nijel
Copy link
Contributor

nijel commented Nov 10, 2016

Closing due to no response, somebody else started to work on #12514 as well.

@nijel nijel closed this Nov 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants