]> granicus.if.org Git - php/commitdiff
Avoid ubsan warning due to memcpy null
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 16 Sep 2020 08:28:28 +0000 (10:28 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 16 Sep 2020 08:30:13 +0000 (10:30 +0200)
This showed up in ext/mysqli/tests/mysqli_change_user.phpt on azure
today. Not seeing it locally though, and also not sure why it decided
to show up now...

ext/mysqlnd/mysqlnd_wireprotocol.c

index ab7fc61f94771a5bd2d2d7ef46fa22ab616616b3..515526d11df587a2f7cc0fc93ea958aec6890b4c 100644 (file)
@@ -2144,7 +2144,9 @@ size_t php_mysqlnd_cached_sha2_result_write(MYSQLND_CONN_DATA * conn, void * _pa
                int1store(buffer + MYSQLND_HEADER_SIZE, '\2');
                sent = pfc->data->m.send(pfc, vio, buffer, 1, stats, error_info);
        } else {
-               memcpy(buffer + MYSQLND_HEADER_SIZE, packet->password, packet->password_len);
+               if (packet->password_len != 0) {
+                       memcpy(buffer + MYSQLND_HEADER_SIZE, packet->password, packet->password_len);
+               }
                sent = pfc->data->m.send(pfc, vio, buffer, packet->password_len, stats, error_info);
        }