]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#851,!24-p] Avoid using empty buffer in the MySQL binding.
authorMarcin Siodelski <marcin@isc.org>
Wed, 21 Aug 2019 18:33:27 +0000 (20:33 +0200)
committerMarcin Siodelski <marcin@isc.org>
Wed, 21 Aug 2019 18:33:27 +0000 (20:33 +0200)
Prior to this change, the out of bound vector element would be referenced
and could lead to undefined behavior.

src/lib/mysql/mysql_binding.cc

index 524206da17d1513e2dab1a632c48a2e84b0a2ca4..37b0df95e8b24457fb205bc8d37a8ebe2dde1729 100644 (file)
@@ -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;