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

Data race in rebuild_settings() #2855

Closed
euantorano opened this issue Oct 2, 2017 · 0 comments · Fixed by #2856
Closed

Data race in rebuild_settings() #2855

euantorano opened this issue Oct 2, 2017 · 0 comments · Fixed by #2856
Assignees
Labels
b:1.8 Branch: 1.8.x s:resolved Status: Resolved. Solution implemented or scheduled t:bug Type: Bug. An issue causing error / flaw / malfunction
Milestone

Comments

@euantorano
Copy link
Member

euantorano commented Oct 2, 2017

MyBB 1.8 has a race condition where if multiple admins update a setting, any setting, simultaneously then it could lead to settings.php getting corrupted. I spoke to Euan about it, and he suggested something like flock() or similar to solve the problem.

Here's the actual implementation of rebuild_settings():

function rebuild_settings()
{
    global $db, $mybb;
    if(!file_exists(MYBB_ROOT."inc/settings.php"))
    {
        $mode = "x";
    }
    else
    {
        $mode = "w";
    }
    $options = array(
        "order_by" => "title",
        "order_dir" => "ASC"
    );
    $query = $db->simple_select("settings", "value, name", "", $options);
    $settings = null;
    while($setting = $db->fetch_array($query))
    {
        $mybb->settings[$setting['name']] = $setting['value'];
        $setting['value'] = addcslashes($setting['value'], '\\"$');
        $settings .= "\$settings['{$setting['name']}'] = \"{$setting['value']}\";\n";
    }
    $settings = "<"."?php\n/*********************************\ \n  DO NOT EDIT THIS FILE, PLEASE USE\n  THE SETTINGS EDITOR\n\*********************************/\n\n$settings\n";
    $file = @fopen(MYBB_ROOT."inc/settings.php", $mode);
    @fwrite($file, $settings);
    @fclose($file);
    $GLOBALS['settings'] = &$mybb->settings;
} 

Original thread: Data race in rebuild_settings()

@euantorano euantorano added b:1.8 Branch: 1.8.x t:bug Type: Bug. An issue causing error / flaw / malfunction s:confirmed Status: Confirmed. Retested and found the issue exists labels Oct 2, 2017
@euantorano euantorano self-assigned this Oct 2, 2017
@Starpaul20 Starpaul20 added this to the 1.8.13 milestone Oct 2, 2017
@WildcardSearch WildcardSearch added s:resolved Status: Resolved. Solution implemented or scheduled and removed s:confirmed Status: Confirmed. Retested and found the issue exists labels Oct 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
b:1.8 Branch: 1.8.x s:resolved Status: Resolved. Solution implemented or scheduled t:bug Type: Bug. An issue causing error / flaw / malfunction
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants