Skip to content

Commit ecf51a2

Browse files
committed
Bug#28787273: FIX -WCAST-QUAL COMPILATION WARNINGS
Avoid casting away constness using C-style cast. Either use const consistently or explicitly remove const with const_cast. Patch 11. Change-Id: I9f627e2857b75e90e323f84668ec552890cd937f
1 parent 421e2be commit ecf51a2

31 files changed

+473
-488
lines changed

include/crypt_genhash_impl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -43,7 +43,7 @@
4343

4444
#include "my_macros.h"
4545

46-
int extract_user_salt(char **salt_begin, char **salt_end);
46+
int extract_user_salt(const char **salt_begin, const char **salt_end);
4747
char *my_crypt_genhash(char *ctbuffer, size_t ctbufflen, const char *plaintext,
4848
size_t plaintext_len, const char *switchsalt,
4949
const char **params, unsigned int *num_rounds = NULL);

include/sql_string.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ class String {
232232
const CHARSET_INFO *charset() const { return m_charset; }
233233
size_t length() const { return m_length; }
234234
size_t alloced_length() const { return m_alloced_length; }
235-
char &operator[](size_t i) const { return m_ptr[i]; }
235+
const char &operator[](size_t i) const { return m_ptr[i]; }
236+
char &operator[](size_t i) { return m_ptr[i]; }
236237
void length(size_t len) { m_length = len; }
237238
bool is_empty() const { return (m_length == 0); }
238239
void mark_as_const() { m_alloced_length = 0; }

mysys_ssl/crypt_genhash_impl.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -191,8 +191,8 @@ static uint getrounds(const char *s) {
191191
@return The size of the salt identified
192192
*/
193193

194-
int extract_user_salt(char **salt_begin, char **salt_end) {
195-
char *it = *salt_begin;
194+
int extract_user_salt(const char **salt_begin, const char **salt_end) {
195+
const char *it = *salt_begin;
196196
int delimiter_count = 0;
197197
while (it != *salt_end) {
198198
if (*it == '$') {

sql/auth/auth_common.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,8 @@ bool reload_acl_caches(THD *thd);
698698
ulong acl_get(THD *thd, const char *host, const char *ip, const char *user,
699699
const char *db, bool db_is_pattern);
700700
bool is_acl_user(THD *thd, const char *host, const char *user);
701-
bool acl_getroot(THD *thd, Security_context *sctx, char *user, char *host,
702-
char *ip, const char *db);
701+
bool acl_getroot(THD *thd, Security_context *sctx, const char *user,
702+
const char *host, const char *ip, const char *db);
703703
bool check_acl_tables_intact(THD *thd);
704704
bool check_acl_tables_intact(THD *thd, TABLE_LIST *tables);
705705
void notify_flush_event(THD *thd);
@@ -819,7 +819,8 @@ ulong get_global_acl_cache_size();
819819
#if defined(HAVE_OPENSSL) && !defined(HAVE_WOLFSSL)
820820
extern bool opt_auto_generate_certs;
821821
bool do_auto_cert_generation(ssl_artifacts_status auto_detection_status,
822-
char **ssl_ca, char **ssl_key, char **ssl_cert);
822+
const char **ssl_ca, const char **ssl_key,
823+
const char **ssl_cert);
823824
#endif /* HAVE_OPENSSL && !HAVE_WOLFSSL */
824825

825826
#define DEFAULT_SSL_CA_CERT "ca.pem"

sql/auth/password_policy_service.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -44,7 +44,7 @@
4444
Static name of the built in plugin used by mysql_password_policy_service_st
4545
for password validation.
4646
*/
47-
LEX_CSTRING validate_password_plugin = {C_STRING_WITH_LEN("validate_password")};
47+
LEX_CSTRING validate_password_plugin = {STRING_WITH_LEN("validate_password")};
4848

4949
/**
5050
Invoke the component/plugin to validate the input password.

sql/auth/role_tables.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -72,9 +72,9 @@ extern Role_index_map *g_authid_to_vertex;
7272
TABLE *open_role_edges_table(THD *thd) {
7373
DBUG_ENTER("open_role_edges_table");
7474
TABLE_LIST tablelst;
75-
tablelst.init_one_table(C_STRING_WITH_LEN("mysql"),
76-
C_STRING_WITH_LEN("role_edges"), "role_edges",
77-
TL_WRITE, MDL_SHARED_NO_READ_WRITE);
75+
tablelst.init_one_table(STRING_WITH_LEN("mysql"),
76+
STRING_WITH_LEN("role_edges"), "role_edges", TL_WRITE,
77+
MDL_SHARED_NO_READ_WRITE);
7878
tablelst.next_local = tablelst.next_global = 0;
7979

8080
if (open_and_lock_tables(thd, &tablelst, MYSQL_LOCK_IGNORE_TIMEOUT)) {
@@ -89,8 +89,8 @@ TABLE *open_role_edges_table(THD *thd) {
8989
TABLE *open_default_role_table(THD *thd) {
9090
DBUG_ENTER("open_role_edges_table");
9191
TABLE_LIST tablelst;
92-
tablelst.init_one_table(C_STRING_WITH_LEN("mysql"),
93-
C_STRING_WITH_LEN("default_roles"), "default_roles",
92+
tablelst.init_one_table(STRING_WITH_LEN("mysql"),
93+
STRING_WITH_LEN("default_roles"), "default_roles",
9494
TL_WRITE, MDL_SHARED_NO_READ_WRITE);
9595
tablelst.next_local = tablelst.next_global = 0;
9696

sql/auth/service_security_context.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ my_svc_bool security_context_lookup(MYSQL_SECURITY_CONTEXT ctx,
179179
if (!tmp_thd) return true;
180180
}
181181

182-
retval = acl_getroot(tmp_thd ? tmp_thd : current_thd, ctx, (char *)user,
183-
(char *)host, (char *)ip, db)
182+
retval = acl_getroot(tmp_thd ? tmp_thd : current_thd, ctx, user, host, ip, db)
184183
? true
185184
: false;
186185

sql/auth/sha2_password.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -1074,7 +1074,8 @@ static int caching_sha2_password_authenticate(MYSQL_PLUGIN_VIO *vio,
10741074
strlen(g_caching_sha2_rsa_keys->get_public_key_as_pem()));
10751075
if (vio->write_packet(
10761076
vio,
1077-
(unsigned char *)g_caching_sha2_rsa_keys->get_public_key_as_pem(),
1077+
pointer_cast<const uchar *>(
1078+
g_caching_sha2_rsa_keys->get_public_key_as_pem()),
10781079
pem_length))
10791080
DBUG_RETURN(CR_ERROR);
10801081
/* Get the encrypted response from the client */

sql/auth/sql_auth_cache.cc

+25-27
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,10 @@ const char *ACL_HOST_AND_IP::calc_ip(const char *ip_arg, long *val, char end) {
231231
@param host_arg Value to be stored
232232
*/
233233
void ACL_HOST_AND_IP::update_hostname(const char *host_arg) {
234-
hostname = (char *)host_arg; // This will not be modified!
234+
hostname = host_arg; // This will not be modified!
235235
hostname_length = hostname ? strlen(hostname) : 0;
236-
if (!host_arg ||
237-
(!(host_arg = (char *)calc_ip(host_arg, &ip, '/')) ||
238-
!(host_arg = (char *)calc_ip(host_arg + 1, &ip_mask, '\0')))) {
236+
if (!host_arg || (!(host_arg = calc_ip(host_arg, &ip, '/')) ||
237+
!(host_arg = calc_ip(host_arg + 1, &ip_mask, '\0')))) {
239238
ip = ip_mask = 0; // Not a masked ip
240239
}
241240
}
@@ -743,7 +742,7 @@ GRANT_NAME::GRANT_NAME(TABLE *form, bool is_routine) {
743742
host.update_hostname(get_field(&memex, form->field[0]));
744743
db = get_field(&memex, form->field[1]);
745744
user = get_field(&memex, form->field[2]);
746-
if (!user) user = (char *)"";
745+
if (!user) user = "";
747746
sort = get_sort(3, host.get_host(), db, user);
748747
tname = get_field(&memex, form->field[3]);
749748
if (!db || !tname) {
@@ -1286,8 +1285,8 @@ void rebuild_check_host(void) {
12861285
true Error
12871286
*/
12881287

1289-
bool acl_getroot(THD *thd, Security_context *sctx, char *user, char *host,
1290-
char *ip, const char *db) {
1288+
bool acl_getroot(THD *thd, Security_context *sctx, const char *user,
1289+
const char *host, const char *ip, const char *db) {
12911290
int res = 1;
12921291
ACL_USER *acl_user = 0;
12931292
DBUG_ENTER("acl_getroot");
@@ -1954,32 +1953,31 @@ bool acl_reload(THD *thd) {
19541953
To avoid deadlocks we should obtain table locks before
19551954
obtaining acl_cache->lock mutex.
19561955
*/
1957-
tables[0].init_one_table(C_STRING_WITH_LEN("mysql"),
1958-
C_STRING_WITH_LEN("user"), "user", TL_READ,
1959-
MDL_SHARED_READ_ONLY);
1956+
tables[0].init_one_table(STRING_WITH_LEN("mysql"), STRING_WITH_LEN("user"),
1957+
"user", TL_READ, MDL_SHARED_READ_ONLY);
19601958
/*
19611959
For a TABLE_LIST element that is inited with a lock type TL_READ
19621960
the type MDL_SHARED_READ_ONLY of MDL is requested for.
19631961
Acquiring strong MDL lock allows to avoid deadlock and timeout errors
19641962
from SE level.
19651963
*/
1966-
tables[1].init_one_table(C_STRING_WITH_LEN("mysql"), C_STRING_WITH_LEN("db"),
1964+
tables[1].init_one_table(STRING_WITH_LEN("mysql"), STRING_WITH_LEN("db"),
19671965
"db", TL_READ, MDL_SHARED_READ_ONLY);
19681966

1969-
tables[2].init_one_table(C_STRING_WITH_LEN("mysql"),
1970-
C_STRING_WITH_LEN("proxies_priv"), "proxies_priv",
1967+
tables[2].init_one_table(STRING_WITH_LEN("mysql"),
1968+
STRING_WITH_LEN("proxies_priv"), "proxies_priv",
19711969
TL_READ, MDL_SHARED_READ_ONLY);
19721970

1973-
tables[3].init_one_table(C_STRING_WITH_LEN("mysql"),
1974-
C_STRING_WITH_LEN("global_grants"), "global_grants",
1971+
tables[3].init_one_table(STRING_WITH_LEN("mysql"),
1972+
STRING_WITH_LEN("global_grants"), "global_grants",
19751973
TL_READ, MDL_SHARED_READ_ONLY);
19761974

1977-
tables[4].init_one_table(C_STRING_WITH_LEN("mysql"),
1978-
C_STRING_WITH_LEN("role_edges"), "role_edges",
1979-
TL_READ, MDL_SHARED_READ_ONLY);
1975+
tables[4].init_one_table(STRING_WITH_LEN("mysql"),
1976+
STRING_WITH_LEN("role_edges"), "role_edges", TL_READ,
1977+
MDL_SHARED_READ_ONLY);
19801978

1981-
tables[5].init_one_table(C_STRING_WITH_LEN("mysql"),
1982-
C_STRING_WITH_LEN("default_roles"), "default_roles",
1979+
tables[5].init_one_table(STRING_WITH_LEN("mysql"),
1980+
STRING_WITH_LEN("default_roles"), "default_roles",
19831981
TL_READ, MDL_SHARED_READ_ONLY);
19841982

19851983
tables[0].next_local = tables[0].next_global = tables + 1;
@@ -2428,15 +2426,15 @@ bool grant_reload(THD *thd) {
24282426
Acquiring strong MDL lock allows to avoid deadlock and timeout errors
24292427
from SE level.
24302428
*/
2431-
tables[0].init_one_table(C_STRING_WITH_LEN("mysql"),
2432-
C_STRING_WITH_LEN("tables_priv"), "tables_priv",
2429+
tables[0].init_one_table(STRING_WITH_LEN("mysql"),
2430+
STRING_WITH_LEN("tables_priv"), "tables_priv",
24332431
TL_READ, MDL_SHARED_READ_ONLY);
2434-
tables[1].init_one_table(C_STRING_WITH_LEN("mysql"),
2435-
C_STRING_WITH_LEN("columns_priv"), "columns_priv",
2436-
TL_READ, MDL_SHARED_READ_ONLY);
2437-
tables[2].init_one_table(C_STRING_WITH_LEN("mysql"),
2438-
C_STRING_WITH_LEN("procs_priv"), "procs_priv",
2432+
tables[1].init_one_table(STRING_WITH_LEN("mysql"),
2433+
STRING_WITH_LEN("columns_priv"), "columns_priv",
24392434
TL_READ, MDL_SHARED_READ_ONLY);
2435+
tables[2].init_one_table(STRING_WITH_LEN("mysql"),
2436+
STRING_WITH_LEN("procs_priv"), "procs_priv", TL_READ,
2437+
MDL_SHARED_READ_ONLY);
24402438

24412439
tables[0].next_local = tables[0].next_global = tables + 1;
24422440
tables[1].next_local = tables[1].next_global = tables + 2;

sql/auth/sql_auth_cache.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Restrictions;
6565
/* Classes */
6666

6767
class ACL_HOST_AND_IP {
68-
char *hostname;
68+
const char *hostname;
6969
size_t hostname_length;
7070
long ip, ip_mask; // Used with masked ip:s
7171

@@ -119,7 +119,7 @@ class ACL_HOST : public ACL_ACCESS {
119119
class Acl_credential {
120120
public:
121121
Acl_credential() {
122-
m_auth_string = {(char *)"", 0};
122+
m_auth_string = {const_cast<char *>(""), 0};
123123
memset(m_salt, 0, SCRAMBLE_LENGTH + 1);
124124
m_salt_len = 0;
125125
}
@@ -291,7 +291,9 @@ class GRANT_COLUMN {
291291
class GRANT_NAME {
292292
public:
293293
ACL_HOST_AND_IP host;
294-
char *db, *user, *tname;
294+
char *db;
295+
const char *user;
296+
char *tname;
295297
ulong privs;
296298
ulong sort;
297299
std::string hash_key;

0 commit comments

Comments
 (0)