Skip to content

Commit 4d14785

Browse files
committed
MDEV-20778 UBSAN: call to function free_rpl_filter() through pointer to incorrect function type
Proper C-style type erasure is done via void*, not via char* or something else. free_key_cache() free_rpl_filter(): types were fixed to avoid function pointer type cast which is still undefined behavior. Note, that casting from void* to any other pointer type is safe and correct.
1 parent f989c0c commit 4d14785

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

sql/keycaches.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ bool NAMED_ILIST::delete_element(const char *name, uint length, void (*free_elem
8484
DBUG_RETURN(1);
8585
}
8686

87-
void NAMED_ILIST::delete_elements(void (*free_element)(const char *name, uchar*))
87+
void NAMED_ILIST::delete_elements(void (*free_element)(const char *name, void*))
8888
{
8989
NAMED_ILINK *element;
9090
DBUG_ENTER("NAMED_ILIST::delete_elements");
@@ -156,9 +156,9 @@ KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
156156
}
157157

158158

159-
void free_key_cache(const char *name, KEY_CACHE *key_cache)
159+
void free_key_cache(const char *name, void *key_cache)
160160
{
161-
end_key_cache(key_cache, 1); // Can never fail
161+
end_key_cache(static_cast<KEY_CACHE *>(key_cache), 1); // Can never fail
162162
my_free(key_cache);
163163
}
164164

@@ -220,13 +220,12 @@ Rpl_filter *get_or_create_rpl_filter(const char *name, uint length)
220220
return filter;
221221
}
222222

223-
void free_rpl_filter(const char *name, Rpl_filter *filter)
223+
void free_rpl_filter(const char *name, void *filter)
224224
{
225-
delete filter;
226-
filter= 0;
225+
delete static_cast<Rpl_filter*>(filter);
227226
}
228227

229228
void free_all_rpl_filters()
230229
{
231-
rpl_filters.delete_elements((void (*)(const char*, uchar*)) free_rpl_filter);
230+
rpl_filters.delete_elements(free_rpl_filter);
232231
}

sql/keycaches.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class NAMED_ILINK;
3030
class NAMED_ILIST: public I_List<NAMED_ILINK>
3131
{
3232
public:
33-
void delete_elements(void (*free_element)(const char*, uchar*));
33+
void delete_elements(void (*free_element)(const char*, void*));
3434
bool delete_element(const char *name, uint length, void (*free_element)(const char*, uchar*));
3535
};
3636

@@ -42,7 +42,7 @@ extern NAMED_ILIST key_caches;
4242
KEY_CACHE *create_key_cache(const char *name, uint length);
4343
KEY_CACHE *get_key_cache(const LEX_STRING *cache_name);
4444
KEY_CACHE *get_or_create_key_cache(const char *name, uint length);
45-
void free_key_cache(const char *name, KEY_CACHE *key_cache);
45+
void free_key_cache(const char *name, void *key_cache);
4646
bool process_key_caches(process_key_cache_t func, void *param);
4747

4848
/* For Rpl_filter */
@@ -52,7 +52,6 @@ extern NAMED_ILIST rpl_filters;
5252
Rpl_filter *create_rpl_filter(const char *name, uint length);
5353
Rpl_filter *get_rpl_filter(LEX_STRING *filter_name);
5454
Rpl_filter *get_or_create_rpl_filter(const char *name, uint length);
55-
void free_rpl_filter(const char *name, Rpl_filter *filter);
5655
void free_all_rpl_filters(void);
5756

5857
#endif /* KEYCACHES_INCLUDED */

sql/mysqld.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2232,7 +2232,7 @@ void clean_up(bool print_message)
22322232
tdc_deinit();
22332233
mdl_destroy();
22342234
dflt_key_cache= 0;
2235-
key_caches.delete_elements((void (*)(const char*, uchar*)) free_key_cache);
2235+
key_caches.delete_elements(free_key_cache);
22362236
wt_end();
22372237
multi_keycache_free();
22382238
sp_cache_end();

0 commit comments

Comments
 (0)