[MDEV-27620] my_b_write_quoted() doesn't escape single quote and slash which breaks formatting Created: 2022-01-25  Updated: 2023-04-27

Status: Confirmed
Project: MariaDB Server
Component/s: None
Affects Version/s: 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8
Fix Version/s: 10.4, 10.5, 10.6

Type: Bug Priority: Minor
Reporter: Yury Chaikou Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None


 Description   

sql/log_event_client.cc (in older versions it is sql/log_event.cc)

The first test in the if/else block in the for loop looks for chars > 0x1f, but ' and \ are both > 0x1f, so the specialized output for them never gets used.

if (*s > 0x1F)
      my_b_write_byte(file, *s);
else if (*s == '\'')
      my_b_write(file, (uchar*)"\\'", 2);
else if (*s == '\\')
      my_b_write(file, (uchar*)"\\\\", 2);

Please consider changing to:

if (*s == '\'')
    my_b_write(file, (uchar*)"\\'", 2);
else if (*s == '\\')
    my_b_write(file, (uchar*)"\\\\", 2);
else if (isprint(*s))
    my_b_write_byte(file, *s);

Using of isprint() function would also cover some special cases.



 Comments   
Comment by Sergei Golubchik [ 2022-01-25 ]

it's only used when printing comments with column values of row events. It's clearly against the original intention, but it's safe, doesn't break anything. One can even argue that it's better this way, more readable:

# at 765
#220125 21:21:47 server id 1  end_log_pos 765 CRC32 0x1b274a69  Annotate_rows:
#Q> insert t1 values ("tick ' backslash \\ <<")
#220125 21:21:47 server id 1  end_log_pos 812 CRC32 0x3197354a  Table_map: `test`.`t1` mapped to number 20
# at 812
#220125 21:21:47 server id 1  end_log_pos 868 CRC32 0xeb324180  Write_rows: table id 20 flags: STMT_END_F
BINLOG '
21vwYRMBAAAALwAAACwDAAAAABQAAAAAAAEABHRlc3QAAnQxAAEPAmQAAUo1lzE=
21vwYRcBAAAAOAAAAGQDAAAAABQAAAAAAAEAAf/+FXRpY2sgJyBiYWNrc2xhc2ggXCA8PIBBMus=
'/*!*/;
### INSERT INTO `test`.`t1`
### SET
###   @1='tick ' backslash \ <<' /* VARSTRING(100) meta=100 nullable=1 is_null=0 */
# Number of rows: 1

Generated at Thu Feb 08 09:54:18 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.