Skip to content

Commit

Permalink
Fix for CONC-543 (hash functions conflict with GnuTLS)
Browse files Browse the repository at this point in the history
To allow static linking with GnuTLS hash lookup functions are now
prefixed with ma_hashtbl_. The files hash.c and hash.h were renamed
to ma_hashtbl.c and ma_hashtbl.h
  • Loading branch information
9EOR9 committed Apr 13, 2021
1 parent 89d0c4b commit d19c7c6
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 88 deletions.
6 changes: 3 additions & 3 deletions include/ma_common.h
Expand Up @@ -21,7 +21,7 @@
#define _ma_common_h

#include <mysql.h>
#include <ma_hash.h>
#include <ma_hashtbl.h>

enum enum_multi_status {
COM_MULTI_OFF= 0,
Expand Down Expand Up @@ -54,7 +54,7 @@ struct st_mysql_options_extension {
char *ssl_crlpath;
char *server_public_key_path;
struct mysql_async_context *async_context;
HASH connect_attrs;
MA_HASHTBL connect_attrs;
size_t connect_attrs_len;
void (*report_progress)(const MYSQL *mysql,
unsigned int stage,
Expand All @@ -74,7 +74,7 @@ struct st_mysql_options_extension {
my_bool read_only;
char *connection_handler;
my_bool (*set_option)(MYSQL *mysql, const char *config_option, const char *config_value);
HASH userdata;
MA_HASHTBL userdata;
char *server_public_key;
char *proxy_header;
size_t proxy_header_len;
Expand Down
42 changes: 21 additions & 21 deletions include/ma_hash.h → include/ma_hashtbl.h
@@ -1,28 +1,28 @@
/************************************************************************************
Copyright (C) 2000, 2012 MySQL AB & MySQL Finland AB & TCX DataKonsult AB,
Monty Program AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not see <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
Part of this code includes code from the PHP project which
is freely available from http://www.php.net
*************************************************************************************/

#ifndef _ma_hash_h
#define _ma_hash_h
#ifndef _ma_hashtbl_h
#define _ma_hashtbl_h
#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -31,12 +31,12 @@ typedef uchar *(*hash_get_key)(const uchar *,uint*,my_bool);
typedef void (*hash_free_key)(void *);

/* flags for hash_init */
#define HASH_CASE_INSENSITIVE 1
#define MA_HASHTBL_CASE_INSENSITIVE 1

typedef struct st_hash_info {
uint next; /* index to next key */
uchar *data; /* data for current entry */
} HASH_LINK;
} MA_HASHTBL_LINK;

typedef struct st_hash {
uint key_offset,key_length; /* Length of key if const length */
Expand All @@ -46,23 +46,23 @@ typedef struct st_hash {
hash_get_key get_key;
void (*free)(void *);
uint (*calc_hashnr)(const uchar *key,uint length);
} HASH;
} MA_HASHTBL;

#define hash_init(A,B,C,D,E,F,G) _hash_init(A,B,C,D,E,F,G CALLER_INFO)
my_bool _hash_init(HASH *hash,uint default_array_elements, uint key_offset,
#define ma_hashtbl_init(A,B,C,D,E,F,G) _ma_hashtbl_init(A,B,C,D,E,F,G CALLER_INFO)
my_bool _ma_hashtbl_init(MA_HASHTBL *hash,uint default_array_elements, uint key_offset,
uint key_length, hash_get_key get_key,
void (*free_element)(void*), uint flags CALLER_INFO_PROTO);
void hash_free(HASH *tree);
uchar *hash_element(HASH *hash,uint idx);
void * hash_search(HASH *info,const uchar *key,uint length);
void * hash_next(HASH *info,const uchar *key,uint length);
my_bool hash_insert(HASH *info,const uchar *data);
my_bool hash_delete(HASH *hash,uchar *record);
my_bool hash_update(HASH *hash,uchar *record,uchar *old_key,uint old_key_length);
my_bool hash_check(HASH *hash); /* Only in debug library */
void ma_hashtbl_free(MA_HASHTBL *tree);
uchar *ma_hashtbl_element(MA_HASHTBL *hash,uint idx);
void * ma_hashtbl_search(MA_HASHTBL *info,const uchar *key,uint length);
void * ma_hashtbl_next(MA_HASHTBL *info,const uchar *key,uint length);
my_bool ma_hashtbl_insert(MA_HASHTBL *info,const uchar *data);
my_bool ma_hashtbl_delete(MA_HASHTBL *hash,uchar *record);
my_bool ma_hashtbl_update(MA_HASHTBL *hash,uchar *record,uchar *old_key,uint old_key_length);
my_bool ma_hashtbl_check(MA_HASHTBL *hash); /* Only in debug library */

#define hash_clear(H) memset((char*) (H), 0,sizeof(*(H)))
#define hash_inited(H) ((H)->array.buffer != 0)
#define ma_hashtbl_clear(H) memset((char*) (H), 0,sizeof(*(H)))
#define ma_hashtbl_inited(H) ((H)->array.buffer != 0)

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion libmariadb/CMakeLists.txt
Expand Up @@ -273,7 +273,7 @@ SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES}
${CC_SOURCE_DIR}/plugins/auth/my_auth.c
ma_array.c
ma_charset.c
ma_hash.c
ma_hashtbl.c
ma_net.c
mariadb_charset.c
ma_time.c
Expand Down
77 changes: 37 additions & 40 deletions libmariadb/ma_hash.c → libmariadb/ma_hashtbl.c
@@ -1,20 +1,20 @@
/************************************************************************************
Copyright (C) 2000, 2012 MySQL AB & MySQL Finland AB & TCX DataKonsult AB,
Monty Program AB, 2016 MariaDB Corporation AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not see <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
Part of this code includes code from the PHP project which
Expand All @@ -29,7 +29,7 @@
#include <ma_sys.h>
#include <ma_string.h>
#include <mariadb_ctype.h>
#include "ma_hash.h"
#include "ma_hashtbl.h"

#define NO_RECORD ((uint) -1)
#define LOWFIND 1
Expand All @@ -38,18 +38,18 @@
#define HIGHUSED 8

static uint hash_mask(uint hashnr,uint buffmax,uint maxlength);
static void movelink(HASH_LINK *array,uint pos,uint next_link,uint newlink);
static void movelink(MA_HASHTBL_LINK *array,uint pos,uint next_link,uint newlink);
static uint calc_hashnr(const uchar *key,uint length);
static uint calc_hashnr_caseup(const uchar *key,uint length);
static int hashcmp(HASH *hash,HASH_LINK *pos,const uchar *key,uint length);
static int hashcmp(MA_HASHTBL *hash,MA_HASHTBL_LINK *pos,const uchar *key,uint length);


my_bool _hash_init(HASH *hash,uint size,uint key_offset,uint key_length,
my_bool _ma_hashtbl_init(MA_HASHTBL *hash,uint size,uint key_offset,uint key_length,
hash_get_key get_key,
void (*free_element)(void*),uint flags CALLER_INFO_PROTO)
{
hash->records=0;
if (ma_init_dynamic_array_ci(&hash->array,sizeof(HASH_LINK),size,0))
if (ma_init_dynamic_array_ci(&hash->array,sizeof(MA_HASHTBL_LINK),size,0))
{
hash->free=0; /* Allow call to hash_free */
return(TRUE);
Expand All @@ -61,20 +61,20 @@ my_bool _hash_init(HASH *hash,uint size,uint key_offset,uint key_length,
hash->get_key=get_key;
hash->free=free_element;
hash->flags=flags;
if (flags & HASH_CASE_INSENSITIVE)
if (flags & MA_HASHTBL_CASE_INSENSITIVE)
hash->calc_hashnr=calc_hashnr_caseup;
else
hash->calc_hashnr=calc_hashnr;
return(0);
}


void hash_free(HASH *hash)
void ma_hashtbl_free(MA_HASHTBL *hash)
{
if (hash->free)
{
uint i,records;
HASH_LINK *data=dynamic_element(&hash->array,0,HASH_LINK*);
MA_HASHTBL_LINK *data=dynamic_element(&hash->array,0,MA_HASHTBL_LINK*);
for (i=0,records=hash->records ; i < records ; i++)
(*hash->free)(data[i].data);
hash->free=0;
Expand All @@ -92,7 +92,7 @@ void hash_free(HASH *hash)
*/

static inline char*
hash_key(HASH *hash,const uchar *record,uint *length,my_bool first)
hash_key(MA_HASHTBL *hash,const uchar *record,uint *length,my_bool first)
{
if (hash->get_key)
return (char *)(*hash->get_key)(record,(uint *)length,first);
Expand All @@ -108,15 +108,15 @@ static uint hash_mask(uint hashnr,uint buffmax,uint maxlength)
return (hashnr & ((buffmax >> 1) -1));
}

static uint hash_rec_mask(HASH *hash,HASH_LINK *pos,uint buffmax,
static uint hash_rec_mask(MA_HASHTBL *hash,MA_HASHTBL_LINK *pos,uint buffmax,
uint maxlength)
{
uint length;
uchar *key= (uchar*) hash_key(hash,pos->data,&length,0);
return hash_mask((*hash->calc_hashnr)(key,length),buffmax,maxlength);
}

#ifndef NEW_HASH_FUNCTION
#ifndef NEW_MA_HASHTBL_FUNCTION

/* Calc hashvalue for a key */

Expand Down Expand Up @@ -191,7 +191,7 @@ uint calc_hashnr_caseup(const uchar *key, uint len)
#ifndef __SUNPRO_C /* SUNPRO can't handle this */
static inline
#endif
unsigned int rec_hashnr(HASH *hash,const uchar *record)
unsigned int rec_hashnr(MA_HASHTBL *hash,const uchar *record)
{
uint length;
uchar *key= (uchar*) hash_key(hash,record,&length,0);
Expand All @@ -202,9 +202,9 @@ unsigned int rec_hashnr(HASH *hash,const uchar *record)
/* Search after a record based on a key */
/* Sets info->current_ptr to found record */

void* hash_search(HASH *hash,const uchar *key,uint length)
void* ma_hashtbl_search(MA_HASHTBL *hash,const uchar *key,uint length)
{
HASH_LINK *pos;
MA_HASHTBL_LINK *pos;
uint flag,idx;

flag=1;
Expand All @@ -215,7 +215,7 @@ void* hash_search(HASH *hash,const uchar *key,uint length)
hash->blength,hash->records);
do
{
pos= dynamic_element(&hash->array,idx,HASH_LINK*);
pos= dynamic_element(&hash->array,idx,MA_HASHTBL_LINK*);
if (!hashcmp(hash,pos,key,length))
{
hash->current_record= idx;
Expand All @@ -237,14 +237,14 @@ void* hash_search(HASH *hash,const uchar *key,uint length)
/* Get next record with identical key */
/* Can only be called if previous calls was hash_search */

void *hash_next(HASH *hash,const uchar *key,uint length)
void *ma_hashtbl_next(MA_HASHTBL *hash,const uchar *key,uint length)
{
HASH_LINK *pos;
MA_HASHTBL_LINK *pos;
uint idx;

if (hash->current_record != NO_RECORD)
{
HASH_LINK *data=dynamic_element(&hash->array,0,HASH_LINK*);
MA_HASHTBL_LINK *data=dynamic_element(&hash->array,0,MA_HASHTBL_LINK*);
for (idx=data[hash->current_record].next; idx != NO_RECORD ; idx=pos->next)
{
pos=data+idx;
Expand All @@ -262,9 +262,9 @@ void *hash_next(HASH *hash,const uchar *key,uint length)

/* Change link from pos to new_link */

static void movelink(HASH_LINK *array,uint find,uint next_link,uint newlink)
static void movelink(MA_HASHTBL_LINK *array,uint find,uint next_link,uint newlink)
{
HASH_LINK *old_link;
MA_HASHTBL_LINK *old_link;
do
{
old_link=array+next_link;
Expand All @@ -276,7 +276,7 @@ static void movelink(HASH_LINK *array,uint find,uint next_link,uint newlink)

/* Compare a key in a record to a whole key. Return 0 if identical */

static int hashcmp(HASH *hash,HASH_LINK *pos,const uchar *key,uint length)
static int hashcmp(MA_HASHTBL *hash,MA_HASHTBL_LINK *pos,const uchar *key,uint length)
{
uint rec_keylength;
uchar *rec_key= (uchar*) hash_key(hash,pos->data,&rec_keylength,1);
Expand All @@ -287,22 +287,22 @@ static int hashcmp(HASH *hash,HASH_LINK *pos,const uchar *key,uint length)

/* Write a hash-key to the hash-index */

my_bool hash_insert(HASH *info,const uchar *record)
my_bool ma_hashtbl_insert(MA_HASHTBL *info,const uchar *record)
{
int flag;
uint halfbuff,hash_nr,first_index,idx;
uchar *ptr_to_rec= NULL,*ptr_to_rec2= NULL;
HASH_LINK *data,*empty,*gpos= NULL,*gpos2 = NULL,*pos;
MA_HASHTBL_LINK *data,*empty,*gpos= NULL,*gpos2 = NULL,*pos;

LINT_INIT(gpos); LINT_INIT(gpos2);
LINT_INIT(ptr_to_rec); LINT_INIT(ptr_to_rec2);

flag=0;
if (!(empty=(HASH_LINK*) ma_alloc_dynamic(&info->array)))
if (!(empty=(MA_HASHTBL_LINK*) ma_alloc_dynamic(&info->array)))
return(TRUE); /* No more memory */

info->current_record= NO_RECORD;
data=dynamic_element(&info->array,0,HASH_LINK*);
data=dynamic_element(&info->array,0,MA_HASHTBL_LINK*);
halfbuff= info->blength >> 1;

idx=first_index=info->records-halfbuff;
Expand Down Expand Up @@ -421,15 +421,15 @@ my_bool hash_insert(HASH *info,const uchar *record)
** if there is a free-function it's called for record if found
******************************************************************************/

my_bool hash_delete(HASH *hash,uchar *record)
my_bool ma_hashtbl_delete(MA_HASHTBL *hash,uchar *record)
{
uint blength,pos2,pos_hashnr,lastpos_hashnr,idx,empty_index;
HASH_LINK *data,*lastpos,*gpos,*pos,*pos3,*empty;
MA_HASHTBL_LINK *data,*lastpos,*gpos,*pos,*pos3,*empty;
if (!hash->records)
return(1);

blength=hash->blength;
data=dynamic_element(&hash->array,0,HASH_LINK*);
data=dynamic_element(&hash->array,0,MA_HASHTBL_LINK*);
/* Search after record with key */
pos=data+ hash_mask(rec_hashnr(hash,record),blength,hash->records);
gpos = 0;
Expand Down Expand Up @@ -508,12 +508,12 @@ my_bool hash_delete(HASH *hash,uchar *record)
This is much more efficient than using a delete & insert.
*/

my_bool hash_update(HASH *hash,uchar *record,uchar *old_key,uint old_key_length)
my_bool ma_hashtbl_update(MA_HASHTBL *hash,uchar *record,uchar *old_key,uint old_key_length)
{
uint idx,new_index,new_pos_index,blength,records,empty;
HASH_LINK org_link,*data,*previous,*pos;
MA_HASHTBL_LINK org_link,*data,*previous,*pos;

data=dynamic_element(&hash->array,0,HASH_LINK*);
data=dynamic_element(&hash->array,0,MA_HASHTBL_LINK*);
blength=hash->blength; records=hash->records;

/* Search after record with key */
Expand Down Expand Up @@ -572,12 +572,9 @@ my_bool hash_update(HASH *hash,uchar *record,uchar *old_key,uint old_key_length)
}


uchar *hash_element(HASH *hash,uint idx)
uchar *ma_hashtbl_element(MA_HASHTBL *hash,uint idx)
{
if (idx < hash->records)
return dynamic_element(&hash->array,idx,HASH_LINK*)->data;
return dynamic_element(&hash->array,idx,MA_HASHTBL_LINK*)->data;
return 0;
}



2 changes: 1 addition & 1 deletion libmariadb/mariadb_dyncol.c
Expand Up @@ -64,7 +64,7 @@
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_string.h>
#include <ma_hash.h>
//#include <ma_hashtbl.h>
#include <mariadb_dyncol.h>
#include <mysql.h>

Expand Down

0 comments on commit d19c7c6

Please sign in to comment.