[CONC-289] mariadb_reconnect causes segfault Created: 2017-10-19 Updated: 2020-07-31 Resolved: 2017-10-20 |
|
| Status: | Closed |
| Project: | MariaDB Connector/C |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Brian Evans | Assignee: | Georg Richter |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Gentoo Linux; MariaDB 10.2.9 |
||
| Attachments: |
|
| Description |
|
This bug is easily demonstrated by running the Perl DBD-mysql tests. Backtrace:
|
| Comments |
| Comment by Georg Richter [ 2017-10-19 ] | ||
|
I'm able to reproduce this issue, however this is a bug in DBD-mysql or 15reconnect test. 1) the test calls mysql_close():
2) the test calls mysql_real_query() with the same handle:
According to the documentation mysql handle has to be initialized by mysql_init()/mysql_real_connect() before, but it was already freed by mysql_close(). That it doesn't crash with libmysql from 10.1 is just concidence: If you do some memory allocations between mysql_close() and mysql_real_query() the freed memory will be overwritten and lead to crashes or unexpected results. Also valgrind reports a lot of invalid reads when running 15reconnect.t | ||
| Comment by Georg Richter [ 2017-10-20 ] | ||
|
The bug is in the DBD-mysql driver: Perl keeps a copy of the mysql handle, set socket to invalid and calls mysql_close(). Another good example why not abusing internals. I'm already talking to the DBD-mysql maintainers how to fix that. | ||
| Comment by Dianne Skoll [ 2020-07-31 ] | ||
|
Hi, I was asked to look into this. While arguably it's a DBD::mysql bug, I think that mysql_close() should set mysql->net.extension and mysql->extension to NULL after it frees them. This is just good defensive programming practice. The attached patch seems to fix the bug reported at https://github.com/perl5-dbi/DBD-mysql/issues/306 null-out-freed-pointers-in-mysql-close.patch |