[MDEV-687] LP:802400 - mysql help sends unchecked contents to mysqld Created: 2011-06-27 Updated: 2013-01-02 Resolved: 2013-01-02 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 5.5.29, 5.1.67, 5.2.14, 5.3.12 |
| Type: | Bug | Priority: | Minor |
| Reporter: | Daniël van Eeden (Inactive) | Assignee: | Sergei Golubchik |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | Launchpad | ||
| Attachments: |
|
| Description |
|
Oracle Bug: #12615411
|
| Comments |
| Comment by Daniël van Eeden (Inactive) [ 2011-06-27 ] | ||||||||||||||||||
|
Re: mysql help sends unchecked contents to mysqld [15 Jun 14:28] Shane Bester the problem seems to be that glob_buffer contains this incorrectly sprintf'd into the sprintf((char*) glob_buffer.ptr(), Now further down in the code, the is_empty() method still believes the String | ||||||||||||||||||
| Comment by Sergei Golubchik [ 2011-06-27 ] | ||||||||||||||||||
|
Re: mysql help sends unchecked contents to mysqld | ||||||||||||||||||
| Comment by Rasmus Johansson (Inactive) [ 2011-09-06 ] | ||||||||||||||||||
|
Re: mysql help sends unchecked contents to mysqld Regards | ||||||||||||||||||
| Comment by Rasmus Johansson (Inactive) [ 2012-09-05 ] | ||||||||||||||||||
|
Re: mysql help sends unchecked contents to mysqld Also, not related to glob_buffer or it being empty as suggested above. (even in normal case it is like that). The problem is in com_server_help: static int com_server_help(String *buffer _attribute_((unused)), if (help_arg[0] != '\'') (void) strxnmov(cmd_buf, sizeof(cmd_buf), "help '", help_arg, "'", NullS); if (!status.batch) { old_buffer= *buffer; old_buffer.copy(); }====== As you can see it explicitly checks for single quote and does some string filtering to finally append " help ' " and " ' " to it if does not have them already. The problem lies here – const char *server_cmd= buffer->ptr() If the string already starts with single quote, server_cmd ends up with value of glob_buffer like this: print server_cmd $10 = 0x98d660 "Your MySQL connection id is 11\nServer version: 5.5.27-rel28.0-debug-log Built by raghavendra at Tue Aug 21 00:41:10 IST 2012\n" and rest follows. Interesting to observe that the argument has been marked _attribute_((unused)) but is still used. This section === if (!status.batch) { old_buffer= *buffer; old_buffer.copy(); } ====== is also suspicious (because of unused attribute) but not directly relevant to this bug. (For curious, old_buffer is used in com_edit when \e is invoked, however, after the fix(below) I checked and \e along with \h was working fine: something like > select \h help 'contents' \e will copy select to $EDITOR's buffer Anyways, here is the fix: === modified file 'Percona-Server/client/mysql.cc' (void) strxnmov(cmd_buf, sizeof(cmd_buf), "help '", help_arg, "'", NullS);
After the fix: >>./client/mysql Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> help contents mysql> help 'contents' Also, with the test case: ./client/mysql Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create table t1 (`id` int(11) auto_increment, `name` varchar(255), primary key (`id`)); mysql> create table t1 (`id` int(11) auto_increment, `name` varchar(255), primary key (`id`)); mysql> INSERT INTO t1(`name`) VALUES ('test1'),('test2'),('test3'),('test4'); mysql> SELECT * FROM t1;
---
--- mysql> DELETE FROM t1 LIMIT 1; mysql> help 'contents' mysql> SELECT * FROM t1;
---
--- mysql> \q Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> help 'contents' mysql> mysql> =============================================================== | ||||||||||||||||||
| Comment by Rasmus Johansson (Inactive) [ 2012-09-05 ] | ||||||||||||||||||
|
Re: mysql help sends unchecked contents to mysqld print glob_buffer For some reason, str_length shows up as zero. However, I think it is something to do with String class used sql_string.h. Anyways, even in normal cases, it is like that, shouldn't be related to this. | ||||||||||||||||||
| Comment by Rasmus Johansson (Inactive) [ 2012-09-05 ] | ||||||||||||||||||
|
Launchpad bug id: 802400 | ||||||||||||||||||
| Comment by Sergei Golubchik [ 2013-01-02 ] | ||||||||||||||||||
|
merged from MySQL |