Skip to content

Commit 172010a

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Don't use VLA in mysqlnd auth
2 parents 7a062cf + 9d31a42 commit 172010a

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

configure.ac

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -695,20 +695,6 @@ if test "$ac_cv__asm_goto" = yes; then
695695
AC_DEFINE(HAVE_ASM_GOTO,1,[Define if asm goto support])
696696
fi
697697

698-
dnl Check for variable length array support.
699-
AC_CACHE_CHECK([whether compiler supports VLA], ac_cv__compiler_c99_vla,
700-
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
701-
#include <stdlib.h>
702-
int main(void) {
703-
int i[rand()%10];
704-
return 0;
705-
}
706-
]])],[ac_cv__compiler_c99_vla=yes], [ac_cv__compiler_c99_vla=no], [ac_cv__compiler_c99_vla=no])])
707-
708-
if test "$ac_cv__compiler_c99_vla" = yes; then
709-
AC_DEFINE(HAVE_COMPILER_C99_VLA, 1, [Compiler supports VLA])
710-
fi
711-
712698
dnl Check valgrind support.
713699
PHP_ARG_WITH([valgrind],
714700
[whether to enable valgrind support],

ext/mysqlnd/mysqlnd_auth.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,8 @@ mysqlnd_sha256_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self
804804

805805
if (server_public_key) {
806806
int server_public_key_len;
807-
char xor_str[passwd_len + 1];
807+
ALLOCA_FLAG(use_heap);
808+
char *xor_str = do_alloca(passwd_len + 1, use_heap);
808809
memcpy(xor_str, passwd, passwd_len);
809810
xor_str[passwd_len] = '\0';
810811
mysqlnd_xor_string(xor_str, passwd_len, (char *) auth_plugin_data, auth_plugin_data_len);
@@ -817,6 +818,7 @@ mysqlnd_sha256_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self
817818
*/
818819
if ((size_t) server_public_key_len - 41 <= passwd_len) {
819820
/* password message is to long */
821+
free_alloca(xor_str, use_heap);
820822
SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, "password is too long");
821823
DBG_ERR("password is too long");
822824
DBG_RETURN(NULL);
@@ -826,6 +828,7 @@ mysqlnd_sha256_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self
826828
ret = malloc(*auth_data_len);
827829
RSA_public_encrypt(passwd_len + 1, (zend_uchar *) xor_str, ret, server_public_key, RSA_PKCS1_OAEP_PADDING);
828830
RSA_free(server_public_key);
831+
free_alloca(xor_str, use_heap);
829832
}
830833
}
831834

@@ -1023,7 +1026,8 @@ mysqlnd_caching_sha2_get_and_use_key(MYSQLND_CONN_DATA *conn,
10231026

10241027
if (server_public_key) {
10251028
int server_public_key_len;
1026-
char xor_str[passwd_len + 1];
1029+
ALLOCA_FLAG(use_heap)
1030+
char *xor_str = do_alloca(passwd_len + 1, use_heap);
10271031
memcpy(xor_str, passwd, passwd_len);
10281032
xor_str[passwd_len] = '\0';
10291033
mysqlnd_xor_string(xor_str, passwd_len, (char *) auth_plugin_data, SCRAMBLE_LENGTH);
@@ -1036,13 +1040,15 @@ mysqlnd_caching_sha2_get_and_use_key(MYSQLND_CONN_DATA *conn,
10361040
*/
10371041
if ((size_t) server_public_key_len - 41 <= passwd_len) {
10381042
/* password message is to long */
1043+
free_alloca(xor_str, use_heap);
10391044
SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, "password is too long");
10401045
DBG_ERR("password is too long");
10411046
DBG_RETURN(0);
10421047
}
10431048

10441049
*crypted = emalloc(server_public_key_len);
10451050
RSA_public_encrypt(passwd_len + 1, (zend_uchar *) xor_str, *crypted, server_public_key, RSA_PKCS1_OAEP_PADDING);
1051+
free_alloca(xor_str, use_heap);
10461052
DBG_RETURN(server_public_key_len);
10471053
}
10481054
DBG_RETURN(0);

ext/mysqlnd/mysqlnd_wireprotocol.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,12 +2139,8 @@ size_t php_mysqlnd_cached_sha2_result_write(MYSQLND_CONN_DATA * conn, void * _pa
21392139
MYSQLND_PFC * pfc = conn->protocol_frame_codec;
21402140
MYSQLND_VIO * vio = conn->vio;
21412141
MYSQLND_STATS * stats = conn->stats;
2142-
#if HAVE_COMPILER_C99_VLA
2143-
zend_uchar buffer[MYSQLND_HEADER_SIZE + packet->password_len + 1];
2144-
#else
21452142
ALLOCA_FLAG(use_heap)
21462143
zend_uchar *buffer = do_alloca(MYSQLND_HEADER_SIZE + packet->password_len + 1, use_heap);
2147-
#endif
21482144
size_t sent;
21492145

21502146
DBG_ENTER("php_mysqlnd_cached_sha2_result_write");
@@ -2157,10 +2153,7 @@ size_t php_mysqlnd_cached_sha2_result_write(MYSQLND_CONN_DATA * conn, void * _pa
21572153
sent = pfc->data->m.send(pfc, vio, buffer, packet->password_len, stats, error_info);
21582154
}
21592155

2160-
#if !HAVE_COMPILER_C99_VLA
21612156
free_alloca(buffer, use_heap);
2162-
#endif
2163-
21642157
DBG_RETURN(sent);
21652158
}
21662159

0 commit comments

Comments
 (0)