Skip to content

[Bug] A configuration change is reported as saved when the file cannot be replaced #9579

Closed

Description

@Raed2180416

Describe the bug

Minz_Configuration::save() writes the configuration to a temporary file, copies the current file to a backup, and replaces the configuration file with rename():

$tmp_filename = $this->config_filename . '.tmp.php';
$back_filename = $this->config_filename . '.bak.php';
if (!file_put_contents($tmp_filename,
"<?php\nreturn " . var_export($this->data, true) . ';', LOCK_EX)) {
@unlink($tmp_filename);
return false;
}
if (!copy($this->config_filename, $back_filename)) {
@unlink($tmp_filename);

The result of the rename() is discarded, and the method returns true whatever happened.

When the replacement fails, the configuration file still holds the previous values and the temporary file stays next to it, but the caller is told that the configuration was saved.

To Reproduce

Run this script from the root of the repository:

<?php
require 'constants.php';
require LIB_PATH . '/lib_rss.php';

$dir = sys_get_temp_dir() . '/freshrss-save';
@mkdir($dir);
file_put_contents($dir . '/config.php', "<?php\nreturn ['title' => 'FreshRSS'];\n");
// A save that was interrupted leaves its temporary and backup files behind.
file_put_contents($dir . '/config.php.tmp.php', '');
file_put_contents($dir . '/config.php.bak.php', '');
chmod($dir, 0555);

Minz_Configuration::register('test', $dir . '/config.php');
$conf = Minz_Configuration::get('test');

var_dump($conf->save());                                // true
var_dump(file_get_contents($dir . '/config.php'));      // the previous values

The directory is not writable, so the configuration file cannot be replaced, yet save() reports success.

Expected behavior

save() returns false when the configuration file was not replaced, and removes its temporary file, as it already does when the temporary file cannot be written or the backup cannot be copied.

FreshRSS version

1.30.5-dev (edge, 735c369)

System information

  • Database version: any
  • PHP version: 8.5.12
  • Installation type: git
  • Web server type: any
  • Device: desktop
  • OS: Linux

Additional context

Any reason the replacement fails ends here: an unwritable data directory, a file replaced by a directory, or a failure from the filesystem.

app/Controllers/userController.php checks the return value in three places (115, 641 and 802). Every other caller ignores it, so a failed save is displayed as “saved” as well.

Activity

  1. added this to the 1.31.0 milestone on Nov 17, 2026
  2. Alkarex commented on Nov 18, 2026

    @Alkarex
    Member

    Thanks for the PR! You are welcome to just submit a PR without previously filing an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions