Skip to content

Commit afe0823

Browse files
authored
Merge pull request jonhoo#10 from datafuse-extras/CLIENT_PROTOCOL_41
Refuse connection when client did not use CLIENT_PROTOCOL_41
2 parents ee90afd + a77301b commit afe0823

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,17 @@ impl<B: MysqlShim<W>, R: Read, W: Write> MysqlIntermediary<B, R, W> {
400400
})?
401401
.1;
402402

403+
if !handshake
404+
.capabilities
405+
.contains(CapabilityFlags::CLIENT_PROTOCOL_41)
406+
{
407+
let err = io::Error::new(
408+
io::ErrorKind::ConnectionAborted,
409+
"Required capability: CLIENT_PROTOCOL_41, please upgrade your MySQL client version",
410+
);
411+
return Err(err.into());
412+
}
413+
403414
self.client_capabilities = handshake.capabilities;
404415
let mut auth_response = handshake.auth_response.clone();
405416
let auth_plugin_expect = self.shim.auth_plugin_for_username(&handshake.username);
@@ -579,10 +590,9 @@ impl<B: MysqlShim<W>, R: Read, W: Write> MysqlIntermediary<B, R, W> {
579590
coltype: myc::constants::ColumnType::MYSQL_TYPE_SHORT,
580591
colflags: myc::constants::ColumnFlags::UNSIGNED_FLAG,
581592
}];
582-
writers::write_column_definitions(
593+
writers::write_column_definitions_41(
583594
cols,
584595
&mut self.writer,
585-
true,
586596
self.client_capabilities,
587597
)?;
588598
}

src/writers.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,15 @@ where
8080
w.write_u16::<LittleEndian>(0)?; // number of warnings
8181
w.end_packet()?;
8282

83-
write_column_definitions(pi, w, false, client_capabilities)?;
84-
write_column_definitions(ci, w, false, client_capabilities)
83+
write_column_definitions_41(pi, w, client_capabilities)?;
84+
write_column_definitions_41(ci, w, client_capabilities)
8585
}
8686

87-
pub(crate) fn write_column_definitions<'a, I, W>(
87+
/// works for Protocol::ColumnDefinition41 is set
88+
/// see: https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_query_response_text_resultset_column_definition.html
89+
pub(crate) fn write_column_definitions_41<'a, I, W>(
8890
i: I,
8991
w: &mut PacketWriter<W>,
90-
is_comm_field_list_response: bool,
9192
client_capabilities: CapabilityFlags,
9293
) -> io::Result<()>
9394
where
@@ -112,13 +113,6 @@ where
112113
w.write_all(&[0x00])?; // decimals
113114
w.write_all(&[0x00, 0x00])?; // unused
114115

115-
if is_comm_field_list_response {
116-
// We should write length encoded int with string size
117-
// followed by string with some "default values" (possibly it's column defaults).
118-
// But we just send NULL for simplicity
119-
w.write_u8(0xfb)?;
120-
}
121-
122116
w.end_packet()?;
123117
empty = false;
124118
}
@@ -143,5 +137,5 @@ where
143137
let i = i.into_iter();
144138
w.write_lenenc_int(i.len() as u64)?;
145139
w.end_packet()?;
146-
write_column_definitions(i, w, false, client_capabilities)
140+
write_column_definitions_41(i, w, client_capabilities)
147141
}

0 commit comments

Comments
 (0)