diff options
author | Sven Sandberg <sven@mysql.com> | 2009-01-09 10:48:01 +0100 |
---|---|---|
committer | Sven Sandberg <sven@mysql.com> | 2009-01-09 10:48:01 +0100 |
commit | 5c92f27f63b0bd97448474fb26329504810fb978 (patch) | |
tree | c4cf61a0f647146ae6ec41465558fdadb62b8f97 /sql/log_event.cc | |
parent | 335e842d24083e8961b7f6b7e9563628dcb8956d (diff) | |
download | mariadb-git-5c92f27f63b0bd97448474fb26329504810fb978.tar.gz |
BUG#41961: Some log_event types do not skip post-header when reading
Problem: when the server reads a log_event from file, it should read
the post-header lengths from the format_description_log_event. Some
event types which currently have post-header length 0 did not do this,
and instead had a hard-coded zero length for the post-header. That
means the current server version will not be able to read future
versions of these events.
Fix: make the reader functions read the post-header.
sql/log_event.cc:
- Made Format_description_log_event constructor initialize all
post-header lengths explicitly, to make it easier to find them
in the source code.
- After this, it is no longer necessary to pass the MY_ZEROFILL
flag to my_malloc. I removed the flag and added a sanity-check
that will be executed only in debug-mode.
- Made INTVAR, RAND, USER_VAR, and XID events skip post_header_len
when reading from file.
sql/log_event.h:
Added explicit defines for the lengths of all event types.
Diffstat (limited to 'sql/log_event.cc')
-rw-r--r-- | sql/log_event.cc | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/sql/log_event.cc b/sql/log_event.cc index 74ad018df55..3d6585778cf 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -3425,7 +3425,8 @@ Format_description_log_event(uint8 binlog_ver, const char* server_ver) number_of_event_types= LOG_EVENT_TYPES; /* we'll catch my_malloc() error in is_valid() */ post_header_len=(uint8*) my_malloc(number_of_event_types*sizeof(uint8), - MYF(MY_ZEROFILL)); + MYF(0)); + /* This long list of assignments is not beautiful, but I see no way to make it nicer, as the right members are #defines, not array members, so @@ -3433,16 +3434,40 @@ Format_description_log_event(uint8 binlog_ver, const char* server_ver) */ if (post_header_len) { + // Allows us to sanity-check that all events initialized their + // events (see the end of this 'if' block). + IF_DBUG(memset(post_header_len, 255, + number_of_event_types*sizeof(uint8));); + + /* Note: all event types must explicitly fill in their lengths here. */ post_header_len[START_EVENT_V3-1]= START_V3_HEADER_LEN; post_header_len[QUERY_EVENT-1]= QUERY_HEADER_LEN; + post_header_len[STOP_EVENT-1]= STOP_HEADER_LEN; post_header_len[ROTATE_EVENT-1]= ROTATE_HEADER_LEN; + post_header_len[INTVAR_EVENT-1]= INTVAR_HEADER_LEN; post_header_len[LOAD_EVENT-1]= LOAD_HEADER_LEN; + post_header_len[SLAVE_EVENT-1]= SLAVE_HEADER_LEN; post_header_len[CREATE_FILE_EVENT-1]= CREATE_FILE_HEADER_LEN; post_header_len[APPEND_BLOCK_EVENT-1]= APPEND_BLOCK_HEADER_LEN; post_header_len[EXEC_LOAD_EVENT-1]= EXEC_LOAD_HEADER_LEN; post_header_len[DELETE_FILE_EVENT-1]= DELETE_FILE_HEADER_LEN; - post_header_len[NEW_LOAD_EVENT-1]= post_header_len[LOAD_EVENT-1]; + post_header_len[NEW_LOAD_EVENT-1]= NEW_LOAD_HEADER_LEN; + post_header_len[RAND_EVENT-1]= RAND_HEADER_LEN; + post_header_len[USER_VAR_EVENT-1]= USER_VAR_HEADER_LEN; post_header_len[FORMAT_DESCRIPTION_EVENT-1]= FORMAT_DESCRIPTION_HEADER_LEN; + post_header_len[XID_EVENT-1]= XID_HEADER_LEN; + post_header_len[BEGIN_LOAD_QUERY_EVENT-1]= BEGIN_LOAD_QUERY_HEADER_LEN; + post_header_len[EXECUTE_LOAD_QUERY_EVENT-1]= EXECUTE_LOAD_QUERY_HEADER_LEN; + /* + The PRE_GA events are never be written to any binlog, but + their lengths are included in Format_description_log_event. + Hence, we need to be assign some value here, to avoid reading + uninitialized memory when the array is written to disk. + */ + post_header_len[PRE_GA_WRITE_ROWS_EVENT-1] = 0; + post_header_len[PRE_GA_UPDATE_ROWS_EVENT-1] = 0; + post_header_len[PRE_GA_DELETE_ROWS_EVENT-1] = 0; + post_header_len[TABLE_MAP_EVENT-1]= TABLE_MAP_HEADER_LEN; post_header_len[WRITE_ROWS_EVENT-1]= ROWS_HEADER_LEN; post_header_len[UPDATE_ROWS_EVENT-1]= ROWS_HEADER_LEN; @@ -3462,9 +3487,14 @@ Format_description_log_event(uint8 binlog_ver, const char* server_ver) post_header_len[WRITE_ROWS_EVENT-1]= post_header_len[UPDATE_ROWS_EVENT-1]= post_header_len[DELETE_ROWS_EVENT-1]= 6;); - post_header_len[BEGIN_LOAD_QUERY_EVENT-1]= post_header_len[APPEND_BLOCK_EVENT-1]; - post_header_len[EXECUTE_LOAD_QUERY_EVENT-1]= EXECUTE_LOAD_QUERY_HEADER_LEN; post_header_len[INCIDENT_EVENT-1]= INCIDENT_HEADER_LEN; + + // Sanity-check that all post header lengths are initialized. + IF_DBUG({ + int i; + for (i=0; i<number_of_event_types; i++) + assert(post_header_len[i] != 255); + }); } break; @@ -4813,7 +4843,9 @@ Intvar_log_event::Intvar_log_event(const char* buf, const Format_description_log_event* description_event) :Log_event(buf, description_event) { - buf+= description_event->common_header_len; + /* The Post-Header is empty. The Varible Data part begins immediately. */ + buf+= description_event->common_header_len + + description_event->post_header_len[INTVAR_EVENT-1]; type= buf[I_TYPE_OFFSET]; val= uint8korr(buf+I_VAL_OFFSET); } @@ -4957,7 +4989,9 @@ Rand_log_event::Rand_log_event(const char* buf, const Format_description_log_event* description_event) :Log_event(buf, description_event) { - buf+= description_event->common_header_len; + /* The Post-Header is empty. The Variable Data part begins immediately. */ + buf+= description_event->common_header_len + + description_event->post_header_len[RAND_EVENT-1]; seed1= uint8korr(buf+RAND_SEED1_OFFSET); seed2= uint8korr(buf+RAND_SEED2_OFFSET); } @@ -5061,7 +5095,9 @@ Xid_log_event(const char* buf, const Format_description_log_event *description_event) :Log_event(buf, description_event) { - buf+= description_event->common_header_len; + /* The Post-Header is empty. The Variable Data part begins immediately. */ + buf+= description_event->common_header_len + + description_event->post_header_len[XID_EVENT-1]; memcpy((char*) &xid, buf, sizeof(xid)); } @@ -5207,7 +5243,9 @@ User_var_log_event(const char* buf, const Format_description_log_event* description_event) :Log_event(buf, description_event) { - buf+= description_event->common_header_len; + /* The Post-Header is empty. The Variable Data part begins immediately. */ + buf+= description_event->common_header_len + + description_event->post_header_len[USER_VAR_EVENT-1]; name_len= uint4korr(buf); name= (char *) buf + UV_NAME_LEN_SIZE; buf+= UV_NAME_LEN_SIZE + name_len; |