diff options
author | Marcin Siodelski <marcin@isc.org> | 2019-08-21 20:33:27 +0200 |
---|---|---|
committer | Marcin Siodelski <marcin@isc.org> | 2019-08-21 20:33:27 +0200 |
commit | 434ebd0811a4b8bdcc45eee887526c7ae748ab42 (patch) | |
tree | ce92fbb2fb1be4fd3053d30cd0b887ee42b06279 /src/lib/mysql/mysql_binding.cc | |
parent | [#851,!24-p] Created unit test for MySQL binding holding empty string. (diff) | |
download | kea-434ebd0811a4b8bdcc45eee887526c7ae748ab42.tar.xz kea-434ebd0811a4b8bdcc45eee887526c7ae748ab42.zip |
[#851,!24-p] Avoid using empty buffer in the MySQL binding.
Prior to this change, the out of bound vector element would be referenced
and could lead to undefined behavior.
Diffstat (limited to 'src/lib/mysql/mysql_binding.cc')
-rw-r--r-- | src/lib/mysql/mysql_binding.cc | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/lib/mysql/mysql_binding.cc b/src/lib/mysql/mysql_binding.cc index 524206da17..37b0df95e8 100644 --- a/src/lib/mysql/mysql_binding.cc +++ b/src/lib/mysql/mysql_binding.cc @@ -292,7 +292,9 @@ MySqlBinding::convertFromDatabaseTime(const MYSQL_TIME& database_time) { MySqlBinding::MySqlBinding(enum_field_types buffer_type, const size_t length) - : buffer_(length), length_(length), + // Make sure that the buffer has non-zero length in case we need to + // reference its first element to assign it to the MySQL binding. + : buffer_(length > 0 ? length : 1), length_(length), null_value_(buffer_type == MYSQL_TYPE_NULL) { memset(&bind_, 0, sizeof(MYSQL_BIND)); bind_.buffer_type = buffer_type; |