Skip to content

Commit

Permalink
10.2 integration fixes
Browse files Browse the repository at this point in the history
  - changed plugin API to avoid crashes: Oracle/MariaDB changed
    structure several times without updating interface version.
  - ABI fixes: moved additional net items to net->extension (connection
    handler and com_multi buffer)
  • Loading branch information
9EOR9 committed Feb 22, 2016
1 parent dc1a871 commit d68b48f
Show file tree
Hide file tree
Showing 22 changed files with 168 additions and 84 deletions.
13 changes: 13 additions & 0 deletions include/ma_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ struct st_mysql_options_extension {
HASH userdata;
};

typedef struct st_connection_handler
{
struct st_ma_connection_plugin *plugin;
void *data;
my_bool active;
my_bool free_data;
} MA_CONNECTION_HANDLER;

struct st_mariadb_net_extension {
unsigned char *mbuff, *mbuff_end, *mbuff_pos;
MA_CONNECTION_HANDLER *conn_hdlr;
};

#define OPT_HAS_EXT_VAL(a,key) \
((a)->options.extension && (a)->options.extension->key)

Expand Down
2 changes: 2 additions & 0 deletions include/ma_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ extern MARIADB_CHARSET_INFO *get_charset(uint cs_number, myf flags);
extern MARIADB_CHARSET_INFO *get_charset_by_name(const char *cs_name);
extern MARIADB_CHARSET_INFO *get_charset_by_nr(uint cs_number);

/* string functions */
char *ma_strmake(register char *dst, register const char *src, size_t length);

/* statistics */
#ifdef TBR
Expand Down
18 changes: 5 additions & 13 deletions include/mariadb_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,11 @@ typedef struct st_ma_pvio MARIADB_PVIO;

struct st_ma_connection_plugin;

typedef struct st_connection_handler
{
struct st_ma_connection_plugin *plugin;
void *data;
my_bool active;
my_bool free_data;
} MA_CONNECTION_HANDLER;

typedef struct st_net {
MARIADB_PVIO *pvio;
unsigned char *buff;
unsigned char *buff_end,*write_pos,*read_pos;
unsigned char *mbuff, *mbuff_end, *mbuff_pos;
my_socket fd; /* For Perl DBI/dbd */
unsigned long remain_in_buf,length;
unsigned long buf_length, where_b;
Expand All @@ -269,18 +261,18 @@ typedef struct st_net {
unsigned int *return_status;
unsigned char reading_or_writing;
char save_char;
my_bool unused_1, unused_2;
char unused_1;
my_bool unused_2;
my_bool compress;
my_bool unused_3;
MA_CONNECTION_HANDLER *conn_hdlr;
void *unused_4;
unsigned int last_errno;
unsigned char error;
my_bool unused_4;
my_bool unused_5;

my_bool unused_6;
char last_error[MYSQL_ERRMSG_SIZE];
char sqlstate[SQLSTATE_LENGTH+1];
void *extension;
struct st_mariadb_net_extension *extension;
} NET;

#define packet_error ((unsigned int) -1)
Expand Down
4 changes: 3 additions & 1 deletion include/mysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,10 @@ typedef struct character_set
const char *desc; \
unsigned int version[3]; \
const char *license; \
void *mariadb_api; \
int (*init)(char *, size_t, int, va_list); \
int (*deinit)();
int (*deinit)(); \
int (*options)(const char *option, const void *);
struct st_mysql_client_plugin
{
MYSQL_CLIENT_PLUGIN_HEADER
Expand Down
6 changes: 4 additions & 2 deletions include/mysql/client_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@
const char *desc; \
unsigned int version[3]; \
const char *license; \
void *mysql_api; \
int (*init)(char *, size_t, int, va_list); \
int (*deinit)();
int (*deinit)(); \
int (*options)(const char *option, const void *);
struct st_mysql_client_plugin
{
MYSQL_CLIENT_PLUGIN_HEADER
Expand All @@ -94,7 +96,7 @@ typedef struct st_ma_connection_plugin
MYSQL *(*connect)(MYSQL *mysql, const char *host, const char *user, const char *passwd,
const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag);
void (*close)(MYSQL *mysql);
int (*options)(MYSQL *mysql, enum mysql_option, void *arg);
int (*set_options)(MYSQL *mysql, enum mysql_option, void *arg);
int (*set_connection)(MYSQL *mysql,enum enum_server_command command, const char *arg,
size_t length, my_bool skipp_check, void *opt_arg);
my_bool (*reconnect)(MYSQL *mysql);
Expand Down
2 changes: 1 addition & 1 deletion libmariadb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ ma_alloc.c
ma_compress.c
ma_init.c
ma_password.c
ma_string.c
ma_ll2str.c
ma_sha1.c
mariadb_stmt.c
ma_loaddata.c
ma_stmt_codec.c
ma_string.c
${CMAKE_BINARY_DIR}/libmariadb/ma_client_plugin.c
ma_io.c
${SSL_SOURCES}
Expand Down
6 changes: 3 additions & 3 deletions libmariadb/ma_loaddata.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int mysql_local_infile_init(void **ptr, const char *filename, void *userdata)
if (mysql_errno(mysql) && !info->error_no)
{
info->error_no= mysql_errno(mysql);
strncpy(info->error_msg, mysql_error(mysql), MYSQL_ERRMSG_SIZE);
ma_strmake(info->error_msg, mysql_error(mysql), MYSQL_ERRMSG_SIZE);
}
else
{
Expand Down Expand Up @@ -127,11 +127,11 @@ int mysql_local_infile_error(void *ptr, char *error_buf, unsigned int error_buf_
MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr;

if (info) {
strncpy(error_buf, info->error_msg, error_buf_len);
ma_strmake(error_buf, info->error_msg, error_buf_len);
return(info->error_no);
}

strncpy(error_buf, "Unknown error", error_buf_len);
ma_strmake(error_buf, "Unknown error", error_buf_len);
return(CR_UNKNOWN_ERROR);
}
/* }}} */
Expand Down
50 changes: 28 additions & 22 deletions libmariadb/ma_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <errno.h>
#include <sys/types.h>
#include <ma_pvio.h>
#include <ma_common.h>
#ifndef _WIN32
#include <poll.h>
#endif
Expand Down Expand Up @@ -103,6 +104,11 @@ int ma_net_init(NET *net, MARIADB_PVIO* pvio)
if (!(net->buff=(uchar*) calloc(1, net_buffer_length)))
return 1;

if (!net->extension)
{
printf("Fatal\n");
exit(-1);
}
/* We don't allocate memory for multi buffer, since we don't know in advance if the server
* supports COM_MULTI comand. It will be allocated on demand in net_add_multi_command */
max_allowed_packet= net->max_packet_size= MAX(net_buffer_length, max_allowed_packet);
Expand Down Expand Up @@ -130,9 +136,9 @@ int ma_net_init(NET *net, MARIADB_PVIO* pvio)
void ma_net_end(NET *net)
{
free(net->buff);
free(net->mbuff);
free(net->extension->mbuff);
net->buff=0;
net->mbuff= 0;
net->extension->mbuff= 0;
}

/* Realloc the packet buffer */
Expand All @@ -151,7 +157,7 @@ static my_bool net_realloc(NET *net, my_bool is_multi, size_t length)
pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1);
/* reallocate buffer:
size= pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE */
if (!(buff=(uchar*) realloc(is_multi ? net->mbuff : net->buff,
if (!(buff=(uchar*) realloc(is_multi ? net->extension->mbuff : net->buff,
pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE)))
{
net->error=1;
Expand All @@ -164,8 +170,8 @@ static my_bool net_realloc(NET *net, my_bool is_multi, size_t length)
}
else
{
net->mbuff=net->mbuff_pos=buff;
net->mbuff_end=buff+(net->max_packet=(unsigned long)pkt_length);
net->extension->mbuff=net->extension->mbuff_pos=buff;
net->extension->mbuff_end=buff+(net->max_packet=(unsigned long)pkt_length);
}
return(0);
}
Expand All @@ -178,8 +184,8 @@ void ma_net_clear(NET *net)
ma_pvio_has_data(net->pvio, &len); */
net->compress_pkt_nr= net->pkt_nr=0; /* Ready for new command */
net->write_pos=net->buff;
if (net->mbuff)
net->mbuff_pos= net->mbuff;
if (net->extension->mbuff)
net->extension->mbuff_pos= net->extension->mbuff;
return;
}

Expand Down Expand Up @@ -326,42 +332,42 @@ int net_add_multi_command(NET *net, uchar command, const uchar *packet,

/* We didn't allocate memory in ma_net_init since it was to early to
* detect if the server supports COM_MULTI command */
if (!net->mbuff)
if (!net->extension->mbuff)
{
size_t alloc_size= (required_length + IO_SIZE - 1) & ~(IO_SIZE - 1);
if (!(net->mbuff= (char *)malloc(alloc_size)))
if (!(net->extension->mbuff= (char *)malloc(alloc_size)))
{
net->last_errno=ER_OUT_OF_RESOURCES;
net->error=2;
net->reading_or_writing=0;
return(1);
}
net->mbuff_pos= net->mbuff;
net->mbuff_end= net->mbuff + alloc_size;
net->extension->mbuff_pos= net->extension->mbuff;
net->extension->mbuff_end= net->extension->mbuff + alloc_size;
}

left_length= net->mbuff_end - net->mbuff_pos;
left_length= net->extension->mbuff_end - net->extension->mbuff_pos;

/* check if our buffer is large enough */
if (left_length < required_length)
{
current_length= net->mbuff_pos - net->mbuff;
current_length= net->extension->mbuff_pos - net->extension->mbuff;
if (net_realloc(net, 1, current_length + required_length))
goto error;
}
int3store(net->mbuff_pos, length + 1);
net->mbuff_pos+= 3;
*net->mbuff_pos= command;
net->mbuff_pos++;
memcpy(net->mbuff_pos, packet, length);
net->mbuff_pos+= length;
int3store(net->extension->mbuff_pos, length + 1);
net->extension->mbuff_pos+= 3;
*net->extension->mbuff_pos= command;
net->extension->mbuff_pos++;
memcpy(net->extension->mbuff_pos, packet, length);
net->extension->mbuff_pos+= length;
return 0;

error:
if (net->mbuff)
if (net->extension->mbuff)
{
free(net->mbuff);
net->mbuff= net->mbuff_pos= net->mbuff_end= 0;
free(net->extension->mbuff);
net->extension->mbuff= net->extension->mbuff_pos= net->extension->mbuff_end= 0;
}
return 1;
}
Expand Down
9 changes: 8 additions & 1 deletion libmariadb/ma_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,11 @@ void ma_dynstr_free(DYNAMIC_STRING *str)
}
}


char *ma_strmake(register char *dst, register const char *src, size_t length)
{
while (length--)
if (! (*dst++ = *src++))
return dst-1;
*dst=0;
return dst;
}
Loading

0 comments on commit d68b48f

Please sign in to comment.