When installing a fresh copy of 13.1.0, it fails. I found an error in the creation of the config file, in install.php and I made some changes to the code which let me complete the install.
Could someone - who knows better than I do - look at the changes and see if the production code should be altered.
This piece of code, from install.php line 310 to 329, is what you must find:
// writing the configuration file
if ( !($fp = @fopen( $config_file, 'w' )))
{
// make sure nobody can list files of _data directory
secure_directory(PHPWG_ROOT_PATH.$conf['data_location']);
$tmp_filename = md5(uniqid(time()));
$fh = @fopen( PHPWG_ROOT_PATH.$conf['data_location'] . 'pwg_' . $tmp_filename, 'w' );
@fputs($fh, $file_content, strlen($file_content));
@fclose($fh);
$template->assign(
array(
'config_creation_failed' => true,
'config_url' => 'install.php?dl='.$tmp_filename,
'config_file_content' => $file_content,
)
);
}
@fputs($fp, $file_content, strlen($file_content));
@fclose($fp);
I replaced it with this. The fputs needs to be inside the braces, I think. If it's outside, it may be trying to write to the file even though the open has failed.
// writing the configuration file
if ( ($fp = @fopen( $config_file, 'w' )))
{
// make sure nobody can list files of _data directory
secure_directory(PHPWG_ROOT_PATH.$conf['data_location']);
$tmp_filename = md5(uniqid(time()));
$tmp_fullfilename = PHPWG_ROOT_PATH.$conf['data_location'] . 'pwg_' . $tmp_filename;
$fh = @fopen( $tmp_fullfilename, 'w' );
if ( $fh == 0 )
{
@fclose($fp);
fatal_error("$tmp_fullfilename is not writeable. Ensure directory and file are accessible and writeable.");
}
@fputs($fh, $file_content, strlen($file_content));
@fclose($fh);
$template->assign(
array(
'config_creation_failed' => true,
'config_url' => 'install.php?dl='.$tmp_filename,
'config_file_content' => $file_content,
)
);
@fputs($fp, $file_content, strlen($file_content));
@fclose($fp);
}
else
{
fatal_error("Failed to open $config_file - Ensure directory and file are accessible and writeable.");
}
When installing a fresh copy of 13.1.0, it fails. I found an error in the creation of the config file, in install.php and I made some changes to the code which let me complete the install.
Could someone - who knows better than I do - look at the changes and see if the production code should be altered.
This piece of code, from install.php line 310 to 329, is what you must find:
-------------------------------
// writing the configuration file
if ( !($fp = @fopen( $config_file, 'w' )))
{
// make sure nobody can list files of _data directory
secure_directory(PHPWG_ROOT_PATH.$conf['data_location']);
$tmp_filename = md5(uniqid(time()));
$fh = @fopen( PHPWG_ROOT_PATH.$conf['data_location'] . 'pwg_' . $tmp_filename, 'w' );
@fputs($fh, $file_content, strlen($file_content));
@fclose($fh);
$template->assign(
array(
'config_creation_failed' => true,
'config_url' => 'install.php?dl='.$tmp_filename,
'config_file_content' => $file_content,
)
);
}
@fputs($fp, $file_content, strlen($file_content));
@fclose($fp);
-------------------------------
I replaced it with this. The fputs needs to be inside the braces, I think. If it's outside, it may be trying to write to the file even though the open has failed.
------------------------------------------------------------------
// writing the configuration file
if ( ($fp = @fopen( $config_file, 'w' )))
{
// make sure nobody can list files of _data directory
secure_directory(PHPWG_ROOT_PATH.$conf['data_location']);
$tmp_filename = md5(uniqid(time()));
$tmp_fullfilename = PHPWG_ROOT_PATH.$conf['data_location'] . 'pwg_' . $tmp_filename;
$fh = @fopen( $tmp_fullfilename, 'w' );
if ( $fh == 0 )
{
@fclose($fp);
fatal_error("$tmp_fullfilename is not writeable. Ensure directory and file are accessible and writeable.");
}
@fputs($fh, $file_content, strlen($file_content));
@fclose($fh);
$template->assign(
array(
'config_creation_failed' => true,
'config_url' => 'install.php?dl='.$tmp_filename,
'config_file_content' => $file_content,
)
);
@fputs($fp, $file_content, strlen($file_content));
@fclose($fp);
}
else
{
fatal_error("Failed to open $config_file - Ensure directory and file are accessible and writeable.");
}
------------------------------------------------------------------
<!-- github-sync-id:1439689461 -->
As explained in https://piwigo.org/forum/viewtopic.php?pid=184763#p184763 this patch may have workarounded in a single case but in general is wrong.
<!-- github-comment-id:1320873593 -->
The code above is not meant to be a patch. I had a very quick look through the code, and made changes that got me through the install. In the discussion in the thread you were saying the flow is wrong. I don't doubt that it is wrong in the case the directory is properly writable, (because I messed up the handling of the fp file pointer) but it was a read-only directory. The bug I am filing is intended to call attention to the fact that the code tries to open a mode 'w' file (the fh file pointer), fails, but just continues on its merry way without checking the return code. PHP then raises an exception when the error code of 0 is later used as if it is a valid file pointer. In the discussion you said the code will produce an file that shouldn't be there. It does not. It cannot, because my error resulted from the fact that the directory was not writeable, so the file you were worried about could not be created. My changes are intended to produce a message telling me that the directory must be made writeable. Right or wrong, these changes got me past this point to where the install hits another bug further on, but by then enough of the install had completed that I could figure out what needed to be done from there.
The bug in the handling of the fh pointer is still there in 13.2.0.
> As explained in https://piwigo.org/forum/viewtopic.php?pid=184763#p184763 this patch may have workarounded in a single case but in general is wrong.
The code above is not meant to be a patch. I had a very quick look through the code, and made changes that got me through the install. In the discussion in the thread you were saying the flow is wrong. I don't doubt that it is wrong in the case the directory is properly writable, (because I messed up the handling of the fp file pointer) but it was a read-only directory. The bug I am filing is intended to call attention to the fact that the code tries to open a mode 'w' file (the fh file pointer), fails, but just continues on its merry way without checking the return code. PHP then raises an exception when the error code of 0 is later used as if it is a valid file pointer. In the discussion you said the code will produce an file that shouldn't be there. It does not. It cannot, because my error resulted from the fact that the directory was not writeable, so the file you were worried about could not be created. My changes are intended to produce a message telling me that the directory must be made writeable. Right or wrong, these changes got me past this point to where the install hits another bug further on, but by then enough of the install had completed that I could figure out what needed to be done from there.
The bug in the handling of the fh pointer is still there in 13.2.0.
<!-- github-comment-id:1321069249 -->
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
When installing a fresh copy of 13.1.0, it fails. I found an error in the creation of the config file, in install.php and I made some changes to the code which let me complete the install.
Could someone - who knows better than I do - look at the changes and see if the production code should be altered.
This piece of code, from install.php line 310 to 329, is what you must find:
I replaced it with this. The fputs needs to be inside the braces, I think. If it's outside, it may be trying to write to the file even though the open has failed.
As explained in https://piwigo.org/forum/viewtopic.php?pid=184763#p184763 this patch may have workarounded in a single case but in general is wrong.
The code above is not meant to be a patch. I had a very quick look through the code, and made changes that got me through the install. In the discussion in the thread you were saying the flow is wrong. I don't doubt that it is wrong in the case the directory is properly writable, (because I messed up the handling of the fp file pointer) but it was a read-only directory. The bug I am filing is intended to call attention to the fact that the code tries to open a mode 'w' file (the fh file pointer), fails, but just continues on its merry way without checking the return code. PHP then raises an exception when the error code of 0 is later used as if it is a valid file pointer. In the discussion you said the code will produce an file that shouldn't be there. It does not. It cannot, because my error resulted from the fact that the directory was not writeable, so the file you were worried about could not be created. My changes are intended to produce a message telling me that the directory must be made writeable. Right or wrong, these changes got me past this point to where the install hits another bug further on, but by then enough of the install had completed that I could figure out what needed to be done from there.
The bug in the handling of the fh pointer is still there in 13.2.0.