[MDEV-20116] segfault on mysql_escape_string Created: 2019-07-22  Updated: 2019-08-08  Resolved: 2019-08-07

Status: Closed
Project: MariaDB Server
Component/s: Character Sets
Affects Version/s: 10.3.16
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Inada Naoki Assignee: Georg Richter
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

Ubuntu 19.04, Debian Buster



 Description   

When `mysql_escape_string` is called without creating any connections:

```
Program received signal SIGSEGV, Segmentation fault.
mysql_cset_escape_slashes (cset=0x0, newstr=0x7ffff7590d21 "\vY\367\377", escapestr=escapestr@entry=0x7ffff7590898 "1",
escapestr_len=escapestr_len@entry=1) at ./libmariadb/libmariadb/ma_charset.c:1040
1040 ./libmariadb/libmariadb/ma_charset.c: No such file or directory.
(gdb) bt 5
#0 mysql_cset_escape_slashes (cset=0x0, newstr=0x7ffff7590d21 "\vY\367\377", escapestr=escapestr@entry=0x7ffff7590898 "1",
escapestr_len=escapestr_len@entry=1) at ./libmariadb/libmariadb/ma_charset.c:1040
#1 0x00007ffff74d4a08 in mysql_escape_string (to=<optimized out>, from=from@entry=0x7ffff7590898 "1", length=length@entry=1)
at ./libmariadb/libmariadb/mariadb_lib.c:3428
```

In case of MySQL, default character set should be used, instead of segv.



 Comments   
Comment by Georg Richter [ 2019-08-07 ]

The default character set is zero. (cset=0x0). That means the library was not properly initialized and the default character set was not loaded.

See mysql_library_init() for more information.

Comment by Inada Naoki [ 2019-08-08 ]

Thank you for your answer.
I did not know mysql_library_init() because MySQL Connector/C works well without it.

Comment by Georg Richter [ 2019-08-08 ]

It doesn't work well without it, unless you call *mysql_init() *which checks if the library was initialized (and if not initializes the library).

Generated at Thu Feb 08 08:56:57 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.