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

Fixed issue #17982: Malformed DSN when using MySQL socket and DB name during installation #2311

Merged

Conversation

valerio-bozzolan
Copy link
Contributor

@valerio-bozzolan valerio-bozzolan commented Mar 23, 2022

How to reproduce

  • create a database
  • create an user@'%' identified by a password
  • grant all privileges to user@'%' to that database
  • install LimeSurvey and fill MySQL configuration
  • remove "localhost" as MySQL server and set a valid socket like "/var/run/mysqld/mysqld.sock"
  • set the database name normally
  • save

What it happens:

«Database doesn't exist!»

What should happen if the database exists and if the MySQL user can see the database:

Normal installation.

Cause of the problem

It seems that when the user selects a valid socket AND fills the database name,
then DSN is wrongly formatted, without the ';' separator between the socket path
and the database name:

mysql:unix_socket=/var/run/mysqld/mysqld.sockdbname=foo

This should be the correct DSN instead (note the ; before dbname):

mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=foo

This problem existed since the feature was originally introduced
here:

The fix consists in assuring that the DSN string ends with the ';' delimiter
also in the case of an user using a socket.

Some users never encountered this problem because they left the database name
blank and put the database name directly into the sock path.

P.S.

The commit includes also a strict string comparison using === operator that
is more appropriate when comparing a string with another string.

Fixed issue #17982

… during installation

How to reproduce:

* create a database
* create an user@'%' identified by a password
* grant all privileges to user@'%' to that database
* install LimeSurvey and fill MySQL configuration
* remove "localhost" as MySQL server and set a valid socket like "/var/run/mysqld/mysqld.sock"
* set the database name normally
* save

What it happens:

«Database doesn't exist!»

What should happen if the database exists and if the MySQL user can see the database:

Normal installation.

Cause of the problem:

It seems that when the user selects a valid socket AND fills the database name,
then DSN is wrongly formatted, without the ';' separator between the socket path
and the database name. This problem exists since the feature was originally introduced
here:

* 4f97fb0

The fix consists in assuring that the DSN string ends with the ';' delimiter
also in the case of an user using a socket.

Some users never encountered this problem because they left the database name
blank and put the database name directly into the sock path.

P.S.

The commit includes also a strict string comparison using `===` operator that
is more appropriate when comparing a string with another string.
@Shnoulle Shnoulle added Bugfix Needs testing Code review done Version checked for code issue without testing labels Mar 28, 2022
@glimz glimz added Tested OK This PR has been tested by QA and works as expected and removed Needs testing labels Mar 30, 2022
@olleharstedt olleharstedt merged commit d541048 into LimeSurvey:master Mar 30, 2022
@valerio-bozzolan
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code review done Version checked for code issue without testing Tested OK This PR has been tested by QA and works as expected
Projects
None yet
4 participants