diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index 3f56357dc..9de529a14 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -2231,11 +2231,14 @@ stmt_execute_metadata_t * MySQL_Protocol::get_binds_from_pkt(void *ptr, unsigned uint8_t null_byte=null_bitmap[i/8]; uint8_t idx=i%8; my_bool is_null = (null_byte & ( 1 << idx )) >> idx; + if (binds[i].buffer_type == MYSQL_TYPE_NULL) + is_null = 1; is_nulls[i]=is_null; binds[i].is_null=&is_nulls[i]; // set length, defaults to 0 // for parameters with not fixed length, that will be assigned later // we moved this initialization here due to #3585 + binds[i].is_unsigned=0; lengths[i]=0; binds[i].length=&lengths[i]; // NOTE: We nullify buffers here to reflect that memory wasn't @@ -2307,11 +2310,13 @@ stmt_execute_metadata_t * MySQL_Protocol::get_binds_from_pkt(void *ptr, unsigned p++; MYSQL_TIME ts; memset(&ts,0,sizeof(MYSQL_TIME)); - memcpy(&ts.neg,p,1); - memcpy(&ts.day,p+1,4); - memcpy(&ts.hour,p+5,1); - memcpy(&ts.minute,p+6,1); - memcpy(&ts.second,p+7,1); + if (l) { + memcpy(&ts.neg,p,1); + memcpy(&ts.day,p+1,4); + memcpy(&ts.hour,p+5,1); + memcpy(&ts.minute,p+6,1); + memcpy(&ts.second,p+7,1); + } if (l>8) { memcpy(&ts.second_part,p+8,4); } @@ -2329,9 +2334,11 @@ stmt_execute_metadata_t * MySQL_Protocol::get_binds_from_pkt(void *ptr, unsigned p++; MYSQL_TIME ts; memset(&ts,0,sizeof(MYSQL_TIME)); - memcpy(&ts.year,p,2); - memcpy(&ts.month,p+2,1); - memcpy(&ts.day,p+3,1); + if (l) { + memcpy(&ts.year,p,2); + memcpy(&ts.month,p+2,1); + memcpy(&ts.day,p+3,1); + } if (l>4) { memcpy(&ts.hour,p+4,1); memcpy(&ts.minute,p+5,1); diff --git a/test/tap/tests/reg_test_3585-stmt_metadata-t.cpp b/test/tap/tests/reg_test_3585-stmt_metadata-t.cpp index f1c09758b..a5c0dff1b 100644 --- a/test/tap/tests/reg_test_3585-stmt_metadata-t.cpp +++ b/test/tap/tests/reg_test_3585-stmt_metadata-t.cpp @@ -315,7 +315,7 @@ int main(int argc, char** argv) { } int np = 4; // init + prepare - np += 21*2; // number of INSERT+SELECT + np += 25*2; // number of INSERT+SELECT plan(np); MYSQL* proxysql_mysql = mysql_init(NULL); @@ -414,6 +414,12 @@ int main(int argc, char** argv) { insert_and_check(stmti, stmts, 19, NULL, NULL, NULL, NULL, NULL, &i2); insert_and_check(stmti, stmts, 20, NULL, NULL, &i1, NULL, NULL, &i2); insert_and_check(stmti, stmts, 21, NULL, &ts1, &i1, NULL, NULL, &i2); + ts1.hour = 0; ts1.minute = 0; ts1.second=0; + ts2.hour = 0; ts2.minute = 0; ts2.second=0; + insert_and_check(stmti, stmts, 22, NULL, &ts1, NULL, (char *)"world22", &ts2, NULL); + insert_and_check(stmti, stmts, 23, (char *)"hello23", NULL, NULL, (char *)"world23", &ts2, NULL); + insert_and_check(stmti, stmts, 24, (char *)"hello24", NULL, &i1, NULL, NULL, &i2); + insert_and_check(stmti, stmts, 25, NULL, NULL, NULL, (char *)"world25", &ts2, &i2); mysql_close(proxysql_mysql); mysql_close(proxysql_admin);