Bug #73819 Valgrind warnings " Syscall param write(buf) points to uninitialised byte(s)"
Submitted: 5 Sep 2014 17:15 Modified: 19 Nov 2019 23:59
Reporter: Sergei Golubchik Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.5, 5.5.40 OS:Any
Assigned to: CPU Architecture:Any

[5 Sep 2014 17:15] Sergei Golubchik
Description:
Run the test case below under valgrind, you'll get an warning:

==21346== Syscall param write(buf) points to uninitialised byte(s)
==21346==    at 0x5461CCD: ??? (syscall-template.S:82)
==21346==    by 0x8B8D4F: my_write (my_write.c:43)
==21346==    by 0x89AE74: inline_mysql_file_write (mysql_file.h:1134)
==21346==    by 0x89DC83: my_b_flush_io_cache (mf_iocache.c:1780)
==21346==    by 0x89D456: _my_b_write (mf_iocache.c:1549)
==21346==    by 0x918F16: _mi_write_static_record (mi_statrec.c:51)
==21346==    by 0x91B843: mi_write (mi_write.c:145)
==21346==    by 0x8D9D01: ha_myisam::write_row(unsigned char*) (ha_myisam.cc:831
==21346==    by 0x7534D8: handler::ha_write_row(unsigned char*) (handler.cc:5200
==21346==    by 0x62E556: create_myisam_from_heap(THD*, TABLE*, TMP_TABLE_PARAM*
==21346==    by 0x67E853: select_union::send_data(List<Item>&) (sql_union.cc:71)
==21346==    by 0x63171E: end_send(JOIN*, st_join_table*, bool) (sql_select.cc:1
==21346==    by 0x62FCC5: flush_cached_records(JOIN*, st_join_table*, bool) (sql

It's cased by marko.makela@oracle.com-20110810092524-of3gujchs18e2tzm -
InnoDB doesn't fully initialize a record buffer, later it goes into a MEMORY temporary table, on overflow it's written into MyISAM table on disk. At that moment valgrind complains.

How to repeat:
--source include/have_innodb.inc

CREATE TABLE city ( 
  id INT, 
  i1 INT, 
  i2 INT, 
  country_code VARCHAR(3), 
  name VARCHAR(35), 
  PRIMARY KEY (id), 
  INDEX (country_code,name)
) ENGINE=InnoDB; 
INSERT INTO city VALUES (3890,19,19,'USA','Glendale'),(3962,13,13,'USA','Grand Prairie'),
(3908,18,18,'USA','Henderson'),(3867,23,23,'USA','Hialeah'),(3947,14,14,'USA','Hollywood'),
(3838,37,37,'USA','Honolulu'),(3796,195,195,'USA','Houston'),(3893,19,19,'USA','Huntington Beach'),
(3920,16,16,'USA','Huntsville'),(3995,11,11,'USA','Independence'),(3804,79,79,'USA','Indianapolis'),
(3997,11,11,'USA','Inglewood'),(3940,14,14,'USA','Irvine'),(3892,19,19,'USA','Irving'),
(3901,18,18,'USA','Jackson'),(3806,74,74,'USA','Jacksonville'),(3864,24,24,'USA','Jersey City'),
(4014,11,11,'USA','Joliet'),(3828,44,44,'USA','Kansas City'),(3936,15,15,'USA','Kansas City'),
(4062,9,9,'USA','Kenosha'),(3910,17,17,'USA','Knoxville'),(4000,11,11,'USA','Lafayette'),
(3811,60,60,'USA','Milwaukee'),(3837,38,38,'USA','Minneapolis'),(4041,10,10,'USA','Mission Viejo'),
(3884,20,20,'USA','Mobile'),(3894,19,19,'USA','Modesto'),(3879,20,20,'USA','Montgomery'),
(3942,14,14,'USA','Moreno Valley'),(3959,13,13,'USA','Naperville'),(3814,57,57,'USA','Nashville-Davidson'),
(4044,9,9,'USA','New Bedford'),(3971,12,12,'USA','New Haven'),(3823,48,48,'USA','New Orleans'),
(3793,801,801,'USA','New York'),(3855,27,27,'USA','Newark'),(3905,18,18,'USA','Newport News'),
(3865,23,23,'USA','Norfolk'),(4046,9,9,'USA','Norman'),(3990,12,12,'USA','North Las Vegas'),
(4022,10,10,'USA','Norwalk'),(3833,40,40,'USA','Oakland'),(3918,16,16,'USA','Oceanside'),
(4064,9,9,'USA','Odessa'),(3821,51,51,'USA','Oklahoma City'),(3836,39,39,'USA','Omaha'),
(3921,16,16,'USA','Ontario'),(3958,13,13,'USA','Orange'),(3897,19,19,'USA','Orlando'),
(3933,15,15,'USA','Overland Park'),(3915,17,17,'USA','Oxnard'),(3986,12,12,'USA','Palmdale'),
(3967,12,12,'USA','Paradise'),(3943,14,14,'USA','Pasadena'),(3953,13,13,'USA','Pasadena'),
(3932,15,15,'USA','Paterson'),(3951,14,14,'USA','Pembroke Pines'),(3996,11,11,'USA','Peoria'),
(4007,11,11,'USA','Peoria'),(3797,152,152,'USA','Philadelphia'),(3798,132,132,'USA','Phoenix'),
(3844,33,33,'USA','Pittsburgh'),(3870,22,22,'USA','Plano'),(3930,15,15,'USA','Pomona'),
(3820,53,53,'USA','Portland'),(4035,10,10,'USA','Portsmouth'),(3912,17,17,'USA','Providence'),
(4016,11,11,'USA','Provo'),(4029,10,10,'USA','Pueblo'),(3854,28,28,'USA','Raleigh'),
(3961,13,13,'USA','Rancho Cucamonga'),(3904,18,18,'USA','Reno'),(3887,20,20,'USA','Richmond'),
(4047,9,9,'USA','Richmond'),(3859,26,26,'USA','Riverside'),(4050,9,9,'USA','Roanoke'),
(3871,22,22,'USA','Rochester'),(3929,15,15,'USA','Rockford'),(3832,41,41,'USA','Sacramento'),
(3841,35,35,'USA','Saint Louis'),(3851,29,29,'USA','Saint Paul'),(3860,25,25,'USA','Saint Petersburg'),
(3952,14,14,'USA','Salem'),(3927,15,15,'USA','Salinas'),(3903,18,18,'USA','Salt Lake City'),
(3801,114,114,'USA','San Antonio'),(3900,19,19,'USA','San Bernardino'),(4034,10,10,'USA','San Buenaventura'),
(3799,122,122,'USA','San Diego'),(3805,78,78,'USA','San Francisco'),(3803,89,89,'USA','San Jose'),
(4056,9,9,'USA','San Mateo'),(4030,10,10,'USA','Sandy'),(3843,34,34,'USA','Santa Ana'),
(4025,10,10,'USA','Santa Clara'),(3926,15,15,'USA','Santa Clarita'),(4060,9,9,'USA','Santa Monica'),
(3934,15,15,'USA','Santa Rosa'),(3956,13,13,'USA','Savannah'),(3878,20,20,'USA','Scottsdale'),
(3816,56,56,'USA','Seattle'),(3880,20,20,'USA','Shreveport'),(3999,11,11,'USA','Simi Valley'),
(3970,12,12,'USA','Sioux Falls'),(4008,11,11,'USA','South Bend'),(3889,20,20,'USA','Spokane'),
(3924,15,15,'USA','Springfield'),(3925,15,15,'USA','Springfield'),(3998,11,11,'USA','Springfield'),
(3983,12,12,'USA','Stamford'),(3969,12,12,'USA','Sterling Heights'),(3862,24,24,'USA','Stockton'),
(3955,13,13,'USA','Sunnyvale'),(4043,10,10,'USA','Sunrise Manor'),(3935,15,15,'USA','Syracuse'),
(3891,19,19,'USA','Tacoma'),(3928,15,15,'USA','Tallahassee'),(3849,30,30,'USA','Tampa'),
(3919,16,16,'USA','Tempe'),(3984,12,12,'USA','Thousand Oaks'),(3848,31,31,'USA','Toledo'),
(3972,12,12,'USA','Topeka'),(3949,14,14,'USA','Torrance'),(3822,49,49,'USA','Tucson'),
(3835,39,39,'USA','Tulsa'),(3985,12,12,'USA','Vallejo'),(3939,14,14,'USA','Vancouver'),
(3830,43,43,'USA','Virginia Beach'),(4057,9,9,'USA','Visalia'),(3993,11,11,'USA','Waco'),
(3948,14,14,'USA','Warren'),(3813,57,57,'USA','Washington'),(4010,11,11,'USA','Waterbury'),
(4017,11,11,'USA','West Covina'),(4004,11,11,'USA','West Valley City'),(4033,10,10,'USA','Westminster'),
(3842,34,34,'USA','Wichita'),(4018,10,10,'USA','Wichita Falls'),(3888,20,20,'USA','Yonkers'); 

CREATE TABLE country (
  code VARCHAR(3), 
  name VARCHAR(52), 
  PRIMARY KEY (code)
) ENGINE=InnoDB; 
INSERT INTO country VALUES ('USA','United States'),('CAN','Canada');

CREATE ALGORITHM=TEMPTABLE VIEW v AS SELECT c1.* FROM city c1, city c2;

send SELECT * FROM city, country, v;
[6 Sep 2014 10:39] MySQL Verification Team
Hello Sergei,

Thank you for the bug report and test case.
Verified as described with 5.5.40.

Thanks,
Umesh
[6 Sep 2014 10:40] MySQL Verification Team
// 5.5.40

==22279== Thread 13:
==22279== Syscall param write(buf) points to uninitialised byte(s)
==22279==    at 0x3B3BA0E6FD: ??? (in /lib64/libpthread-2.12.so)
==22279==    by 0x7A5B1E: my_write (my_write.c:43)
==22279==    by 0x790CF6: my_b_flush_io_cache (mysql_file.h:1134)
==22279==    by 0x792991: _my_b_write (mf_iocache.c:1549)
==22279==    by 0x9133B0: _mi_write_static_record (mi_statrec.c:51)
==22279==    by 0x916977: mi_write (mi_write.c:145)
==22279==    by 0x679AEC: handler::ha_write_row(unsigned char*) (handler.cc:5200)
==22279==    by 0x5AA47F: create_myisam_from_heap(THD*, TABLE*, TMP_TABLE_PARAM*, int, bool) (sql_select.cc:11353)
==22279==    by 0x5E6571: select_union::send_data(List<Item>&) (sql_union.cc:70)
==22279==    by 0x59FA73: end_send(JOIN*, st_join_table*, bool) (sql_select.cc:12763)
==22279==    by 0x5A35B8: flush_cached_records(JOIN*, st_join_table*, bool) (sql_select.cc:12112)
==22279==    by 0x5A3726: sub_select_cache(JOIN*, st_join_table*, bool) (sql_select.cc:11628)
==22279==    by 0x5A4197: do_select(JOIN*, List<Item>*, TABLE*, Procedure*) (sql_select.cc:11564)
==22279==    by 0x5B8424: JOIN::exec() (sql_select.cc:2385)
==22279==    by 0x5B41C2: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_
select_lex_unit*, st_select_lex*) (sql_select.cc:2604)
==22279==    by 0x55E199: mysql_derived_filling(THD*, LEX*, TABLE_LIST*) (sql_derived.cc:299)
==22279==  Address 0xd9c090f is 239 bytes inside a block of size 131,072 alloc'd
==22279==    at 0x4A069EE: malloc (vg_replace_malloc.c:270)
==22279==    by 0x7A2D31: my_malloc (my_malloc.c:38)
==22279==    by 0x7925BB: init_io_cache (mf_iocache.c:232)
==22279==    by 0x8FF0FC: mi_extra (mi_extra.c:137)
==22279==    by 0x5AA446: create_myisam_from_heap(THD*, TABLE*, TMP_TABLE_PARAM*, int, bool) (sql_select.cc:11342)
==22279==    by 0x5E6571: select_union::send_data(List<Item>&) (sql_union.cc:70)
==22279==    by 0x59FA73: end_send(JOIN*, st_join_table*, bool) (sql_select.cc:12763)
==22279==    by 0x5A35B8: flush_cached_records(JOIN*, st_join_table*, bool) (sql_select.cc:12112)
==22279==    by 0x5A3726: sub_select_cache(JOIN*, st_join_table*, bool) (sql_select.cc:11628)
==22279==    by 0x5A4197: do_select(JOIN*, List<Item>*, TABLE*, Procedure*) (sql_select.cc:11564)
==22279==    by 0x5B8424: JOIN::exec() (sql_select.cc:2385)
==22279==    by 0x5B41C2: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_
select_lex_unit*, st_select_lex*) (sql_select.cc:2604)
==22279==    by 0x55E199: mysql_derived_filling(THD*, LEX*, TABLE_LIST*) (sql_derived.cc:299)
==22279==    by 0x55DFE8: mysql_handle_derived(LEX*, bool (*)(THD*, LEX*, TABLE_LIST*)) (sql_derived.cc:60)
==22279==    by 0x545864: open_and_lock_tables(THD*, TABLE_LIST*, bool, unsigned int, Prelocking_strategy*) (sql_base.cc:5521)
==22279==    by 0x576A24: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_base.h:500)
==22279==
==22279== Syscall param write(buf) points to uninitialised byte(s)
==22279==    at 0x3B3BA0E6FD: ??? (in /lib64/libpthread-2.12.so)
==22279==    by 0x7A5B1E: my_write (my_write.c:43)
==22279==    by 0x790CF6: my_b_flush_io_cache (mysql_file.h:1134)
==22279==    by 0x79105C: end_io_cache (mf_iocache.c:1851)
==22279==    by 0x8FF3E5: mi_extra (mi_extra.c:156)
==22279==    by 0x5E5E74: select_union::flush() (sql_union.cc:87)
==22279==    by 0x55E1D0: mysql_derived_filling(THD*, LEX*, TABLE_LIST*) (sql_derived.cc:308)
==22279==    by 0x55DFE8: mysql_handle_derived(LEX*, bool (*)(THD*, LEX*, TABLE_LIST*)) (sql_derived.cc:60)
==22279==    by 0x545864: open_and_lock_tables(THD*, TABLE_LIST*, bool, unsigned int, Prelocking_strategy*) (sql_base.cc:5521)
==22279==    by 0x576A24: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_base.h:500)
==22279==    by 0x57D1DB: mysql_execute_command(THD*) (sql_parse.cc:2176)
==22279==    by 0x57E7B9: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:5662)
==22279==    by 0x580B0C: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1038)
==22279==    by 0x6193C6: do_handle_one_connection(THD*) (sql_connect.cc:862)
==22279==    by 0x619433: handle_one_connection (sql_connect.cc:781)
==22279==    by 0x8DC98A: pfs_spawn_thread (pfs.cc:1015)
==22279==  Address 0xd9c082b is 11 bytes inside a block of size 131,072 alloc'd
==22279==    at 0x4A069EE: malloc (vg_replace_malloc.c:270)
==22279==    by 0x7A2D31: my_malloc (my_malloc.c:38)
==22279==    by 0x7925BB: init_io_cache (mf_iocache.c:232)
==22279==    by 0x8FF0FC: mi_extra (mi_extra.c:137)
==22279==    by 0x5AA446: create_myisam_from_heap(THD*, TABLE*, TMP_TABLE_PARAM*, int, bool) (sql_select.cc:11342)
==22279==    by 0x5E6571: select_union::send_data(List<Item>&) (sql_union.cc:70)
==22279==    by 0x59FA73: end_send(JOIN*, st_join_table*, bool) (sql_select.cc:12763)
==22279==    by 0x5A35B8: flush_cached_records(JOIN*, st_join_table*, bool) (sql_select.cc:12112)
==22279==    by 0x5A3726: sub_select_cache(JOIN*, st_join_table*, bool) (sql_select.cc:11628)
==22279==    by 0x5A4197: do_select(JOIN*, List<Item>*, TABLE*, Procedure*) (sql_select.cc:11564)
==22279==    by 0x5B8424: JOIN::exec() (sql_select.cc:2385)
==22279==    by 0x5B41C2: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_
select_lex_unit*, st_select_lex*) (sql_select.cc:2604)
==22279==    by 0x55E199: mysql_derived_filling(THD*, LEX*, TABLE_LIST*) (sql_derived.cc:299)
==22279==    by 0x55DFE8: mysql_handle_derived(LEX*, bool (*)(THD*, LEX*, TABLE_LIST*)) (sql_derived.cc:60)
==22279==    by 0x545864: open_and_lock_tables(THD*, TABLE_LIST*, bool, unsigned int, Prelocking_strategy*) (sql_base.cc:5521)
==22279==    by 0x576A24: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_base.h:500)
==22279==
[19 Nov 2019 23:59] Roy Lyseng
Posted by developer:
 
Not reproducible in 5.7 and 8.0