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

MySQL auth: bad configuration causes panic #85

Open
hollymcr opened this issue Mar 19, 2024 · 5 comments
Open

MySQL auth: bad configuration causes panic #85

hollymcr opened this issue Mar 19, 2024 · 5 comments

Comments

@hollymcr
Copy link

Using some code based on cmd/single/main.go with MySQL configuration in .yml, every time a client connected to the broker resulted in "panic: runtime error: invalid memory address or nil pointer dereference"

I eventually traced this to a typo in the field names I had put in my .yml. The result was that the code:
a.authStmt, _ = sqlxDB.Preparex(authSql)
.. was failing as the SQL was invalid.

However there's no code to catch that error and so when the client connects,
err := a.authStmt.QueryRowx(key).Scan(&password, &allow)
.. in OnConnectAuthenticate was crashing.

This is the first time I've worked in Go so I'm not going to attempt to suggest a suitable fix - for now I'll just be careful about config file typos!

@wind-c
Copy link
Owner

wind-c commented Mar 21, 2024

Let me look at the contents of auth-mysql.yml.

@hollymcr
Copy link
Author

I don't have the file which failed any more but it should be easy to replicate. Simply change one of the field names in a working configuration to a non-existent field name.

The issue is that Preparex() can fail (there's probably lots of ways it could fail other than invalid fields) but as there is no error checking at that point a.authStmt is left as nil, and then later there's an attempt to call (nil).QueryRowx(key)

@wind-c
Copy link
Owner

wind-c commented Mar 21, 2024

Is the program running properly now?

@wind-c
Copy link
Owner

wind-c commented Mar 21, 2024

I'll try to replicate it and fix it.

@hollymcr
Copy link
Author

I'm running a heavily modified version to suit my application (for example I needed different MySQL schema details for different ports, and I've added PBKDF2 handling so that I can mimic/replicate the way Mosquitto's Go Auth package works).

But when I tested previously the code ran fine once I set the field names correctly. But a panic isn't the best way to report a user configuration issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants