]> BookStack Code Mirror - system-cli/commitdiff
Added escaping for MySQL config options 22-mysql-cred-escaping
authorDan Brown <redacted>
Wed, 14 May 2025 11:12:02 +0000 (12:12 +0100)
committerDan Brown <redacted>
Wed, 14 May 2025 11:12:02 +0000 (12:12 +0100)
Quotes string values and specifically escapes backslashes so they're not
misintepreted as special chars in the config.

For #22

src/Services/MySqlRunner.php

index d83f446b98a41df9134a700427e8271e7da0363f..e1c4a0fbf3529c10aaf64551988ddd5842eeddbe 100644 (file)
@@ -32,7 +32,8 @@ class MySqlRunner
     protected function createOptionsFile(): string
     {
         $path = tempnam(sys_get_temp_dir(), 'bs-cli-mysql-opts');
-        $contents = "[client]\nuser={$this->user}\nhost={$this->host}\nport={$this->port}\npassword={$this->password}\nprotocol=TCP";
+        $password = str_replace('\\', '\\\\', $this->password);
+        $contents = "[client]\nuser='{$this->user}'\nhost='{$this->host}'\nport={$this->port}\npassword='{$password}'\nprotocol=TCP";
         file_put_contents($path, $contents);
         chmod($path, 0600);
         return $path;