[CONC-334] mysql_stmt_result_metadata() returns uninitialized memory and cause SEGFAULT Created: 2018-05-28 Updated: 2018-06-14 Resolved: 2018-06-05 |
|
| Status: | Closed |
| Project: | MariaDB Connector/C |
| Component/s: | None |
| Affects Version/s: | 2.3.5, 3.0.4 |
| Fix Version/s: | 2.3.6, 3.0.5 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Pali | Assignee: | Georg Richter |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Attachments: |
|
| Description |
|
Values name_length and table_length from mysql_fetch_field() returned by mysql_stmt_result_metadata() are sometime zero and sometimes uninitialized. Running application under valgrind resulted that reading name_length or table_length caused either "Use of uninitialised value of size 8" or "Conditional jump or move depends on uninitialised value(s)". This defect in MariaDB was found when developing Perl DBI driver DBD::MariaDB: http://github.com/gooddata/DBD-MariaDB. And is causing SEGFAULT of perl process when trying to use name_length from mysql_fetch_field(). All versions of MariaDB 10.3 series are affected. Affected is also MariaDB 10.2 series since version 10.2.4. 10.2.3 and older works fine. Also all versions in MariaDB 5.5 series work fine. And affected are also all MariaDB Connector/C versions in 2.3 and 3.0 series. Simple C application for reproducing this problem is in the attachment. Compile it with: Output for MariaDB 10.2.4 (affected):
According to documentation name_length should be length of name (strlen), not zero or uninitialised value. Output for MariaDB 10.2.3 (not affected)
Here with older version it is correct. Note that MySQL 5.5, 5.6, 5.7 and 8.0 do not have this problem. It is MariaDB-only. This problems makes implementation of DBD::MariaDB perl driver problematic. |
| Comments |
| Comment by Pali [ 2018-05-28 ] |
|
As a workaround for DBD::MariaDB to prevent crashing I added code which recalculates those length fields: |
| Comment by Pali [ 2018-06-14 ] |
|
Thanks for quick fix. Now I would like to know two things: In which MariaDB releases will be this problem fixed? And what is that correct #ifdef way to check in C source code if fixed version of Connector/C (that is 2.3.6 or 3.0.5) is in use? |
| Comment by Georg Richter [ 2018-06-14 ] |
|
Hi Pali, you need to check MARIADB_PACKAGE_VERSION_ID, which is defined in mariadb_version.h include file. |