1 change: 1 addition & 0 deletions include/ma_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#cmakedefine HAVE_THR_YIELD 1
#cmakedefine HAVE_VASPRINTF 1
#cmakedefine HAVE_VSNPRINTF 1
#cmakedefine HAVE_CUSERID 1

/*
* types and sizes
Expand Down
6 changes: 6 additions & 0 deletions include/ma_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,12 @@ typedef unsigned long long intptr;
#define IF_WIN(A,B) B
#endif

#if defined(SOLARIS) || defined(__sun)
#define IF_SOLARIS(A,B) A
#else
#define IF_SOLARIS(A,B) B
#endif

#ifndef RTLD_NOW
#define RTLD_NOW 1
#endif
Expand Down
21 changes: 20 additions & 1 deletion include/ma_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,27 @@

void free_rows(MYSQL_DATA *cur);
int ma_multi_command(MYSQL *mysql, enum enum_multi_status status);
MYSQL_FIELD * unpack_fields(MYSQL_DATA *data,
MYSQL_FIELD * unpack_fields(const MYSQL *mysql, MYSQL_DATA *data,
MA_MEM_ROOT *alloc,uint fields,
my_bool default_value);

static inline my_bool ma_has_extended_type_info(const MYSQL *mysql)
{
return ((mysql->extension->mariadb_server_capabilities) &
(MARIADB_CLIENT_EXTENDED_METADATA >> 32)) != 0;
}

static inline uint ma_extended_type_info_rows(const MYSQL *mysql)
{
return ma_has_extended_type_info(mysql) ? 1 : 0;
}

static inline uint ma_result_set_rows(const MYSQL *mysql)
{
return ma_has_extended_type_info(mysql) ? 9 : 8;
}

MA_FIELD_EXTENSION *ma_field_extension_deep_dup(MA_MEM_ROOT *memroot,
const MA_FIELD_EXTENSION *from);

#endif
5 changes: 4 additions & 1 deletion include/mariadb_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,16 @@ enum enum_server_command
#define MARIADB_CLIENT_PROGRESS (1ULL << 32)
#define MARIADB_CLIENT_COM_MULTI (1ULL << 33)
#define MARIADB_CLIENT_STMT_BULK_OPERATIONS (1ULL << 34)
/* support of extended data type/format information, since 10.5.0 */
#define MARIADB_CLIENT_EXTENDED_METADATA (1ULL << 35)

#define IS_MARIADB_EXTENDED_SERVER(mysql)\
!(mysql->server_capabilities & CLIENT_MYSQL)

#define MARIADB_CLIENT_SUPPORTED_FLAGS (MARIADB_CLIENT_PROGRESS |\
MARIADB_CLIENT_COM_MULTI |\
MARIADB_CLIENT_STMT_BULK_OPERATIONS)
MARIADB_CLIENT_STMT_BULK_OPERATIONS|\
MARIADB_CLIENT_EXTENDED_METADATA)

#define CLIENT_SUPPORTED_FLAGS (CLIENT_MYSQL |\
CLIENT_FOUND_ROWS |\
Expand Down
4 changes: 2 additions & 2 deletions include/mariadb_rpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ typedef struct st_mariadb_rpl_event
/* Function prototypes */
MARIADB_RPL * STDCALL mariadb_rpl_init_ex(MYSQL *mysql, unsigned int version);

int STDCALL mariadb_rpl_optionsv(MARIADB_RPL *rpl, enum mariadb_rpl_option, ...);
int STDCALL mariadb_rpl_get_optionsv(MARIADB_RPL *rpl, enum mariadb_rpl_option, ...);
int mariadb_rpl_optionsv(MARIADB_RPL *rpl, enum mariadb_rpl_option, ...);
int mariadb_rpl_get_optionsv(MARIADB_RPL *rpl, enum mariadb_rpl_option, ...);

int STDCALL mariadb_rpl_open(MARIADB_RPL *rpl);
void STDCALL mariadb_rpl_close(MARIADB_RPL *rpl);
Expand Down
22 changes: 22 additions & 0 deletions include/mysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ typedef int my_socket;
#include "ma_list.h"
#include "mariadb_ctype.h"


typedef struct st_ma_const_string
{
const char *str;
size_t length;
} MARIADB_CONST_STRING;


#ifndef ST_MA_USED_MEM_DEFINED
#define ST_MA_USED_MEM_DEFINED
typedef struct st_ma_used_mem { /* struct for once_alloc */
Expand Down Expand Up @@ -383,6 +391,20 @@ typedef struct
void *extension;
} MYSQL_PARAMETERS;


enum mariadb_field_attr_t
{
MARIADB_FIELD_ATTR_DATA_TYPE_NAME= 0,
MARIADB_FIELD_ATTR_FORMAT_NAME= 1
};

#define MARIADB_FIELD_ATTR_LAST MARIADB_FIELD_ATTR_FORMAT_NAME


int STDCALL mariadb_field_attr(MARIADB_CONST_STRING *attr,
const MYSQL_FIELD *field,
enum mariadb_field_attr_t type);

#ifndef _mysql_time_h_
enum enum_mysql_timestamp_type
{
Expand Down
2 changes: 1 addition & 1 deletion include/mysqld_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
#define ER_REQUIRES_PRIMARY_KEY 1173
#define ER_NO_RAID_COMPILED 1174
#define ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE 1175
#define ER_KEY_DOES_NOT_EXITS 1176
#define ER_KEY_DOES_NOT_EXISTS 1176
#define ER_CHECK_NO_SUCH_TABLE 1177
#define ER_CHECK_NOT_IMPLEMENTED 1178
#define ER_CANT_DO_THIS_DURING_AN_TRANSACTION 1179
Expand Down
12 changes: 7 additions & 5 deletions libmariadb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ SET(MARIADB_LIB_SYMBOLS
mariadb_rpl_fetch
mariadb_rpl_optionsv
mariadb_rpl_get_optionsv
mariadb_free_rpl_event)
mariadb_free_rpl_event
mariadb_field_attr
)
IF(WITH_SSL)
SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} mariadb_deinitialize_ssl)
ENDIF()
Expand Down Expand Up @@ -397,11 +399,11 @@ IF(UNIX)
SET_TARGET_PROPERTIES(libmariadb PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}")
ELSE()
ADD_LIBRARY(libmariadb SHARED ${libmariadb_RC} mariadbclient.def)
TARGET_LINK_LIBRARIES(libmariadb mariadbclient)
TARGET_LINK_LIBRARIES(libmariadb LINK_PRIVATE mariadbclient)
SET_TARGET_PROPERTIES(libmariadb PROPERTIES LINKER_LANGUAGE C)
ENDIF()

TARGET_LINK_LIBRARIES(libmariadb ${SYSTEM_LIBS})
TARGET_LINK_LIBRARIES(libmariadb LINK_PRIVATE ${SYSTEM_LIBS})

SIGN_TARGET(libmariadb)

Expand All @@ -412,7 +414,7 @@ ENDIF()
IF(CMAKE_SYSTEM_NAME MATCHES "Linux" OR
CMAKE_SYSTEM_NAME MATCHES "GNU")
IF (NOT WITH_ASAN AND NOT WITH_TSAN AND NOT WITH_UBSAN AND NOT WITH_MSAN)
TARGET_LINK_LIBRARIES (libmariadb "-Wl,--no-undefined")
TARGET_LINK_LIBRARIES (libmariadb LINK_PRIVATE "-Wl,--no-undefined")
ENDIF()
SET_TARGET_PROPERTIES(libmariadb PROPERTIES LINK_FLAGS "${CC_BINARY_DIR}/libmariadb/mariadbclient.def")
ENDIF()
Expand Down Expand Up @@ -455,7 +457,7 @@ INSTALL(TARGETS libmariadb
DESTINATION ${INSTALL_LIBDIR})


IF(WIN32)
IF(MSVC)
# On Windows, install PDB
INSTALL(FILES $<TARGET_PDB_FILE:libmariadb> DESTINATION "${INSTALL_LIBDIR}"
CONFIGURATIONS Debug RelWithDebInfo
Expand Down
16 changes: 8 additions & 8 deletions libmariadb/ma_charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ static unsigned int check_mb_gb18030_valid(const char * start, const char * end)
const MARIADB_CHARSET_INFO mariadb_compiled_charsets[] =
{
{ 1, 1, "big5","big5_chinese_ci", "", 950, "BIG5", 1, 2, mysql_mbcharlen_big5, check_mb_big5},
{ 3, 1, "dec8", "dec8_swedisch_ci", "", 0, "DEC", 1, 1, NULL, NULL},
{ 3, 1, "dec8", "dec8_swedish_ci", "", 0, "DEC", 1, 1, NULL, NULL},
{ 4, 1, "cp850", "cp850_general_ci", "", 850, "CP850", 1, 1, NULL, NULL},
{ 6, 1, "hp8", "hp8_english_ci", "", 0, "HP-ROMAN8", 1, 1, NULL, NULL},
{ 7, 1, "koi8r", "koi8r_general_ci", "", 20866, "KOI8R", 1, 1, NULL, NULL},
Expand Down Expand Up @@ -583,15 +583,15 @@ const MARIADB_CHARSET_INFO mariadb_compiled_charsets[] =
{ 95, 1, "cp932", "cp932_japanese_ci", "", 932, "CP932", 1, 2, mysql_mbcharlen_cp932, check_mb_cp932},
{ 97, 1, "eucjpms", "eucjpms_japanese_ci", "", 932, "EUC-JP-MS", 1, 3, mysql_mbcharlen_eucjpms, check_mb_eucjpms},
{ 2, 1, "latin2", "latin2_czech_cs", "", 852, "LATIN2", 1, 1, NULL, NULL},
{ 5, 1, "latin1", "latin1_german_ci", "", 1252, "LATIN1", 1, 1, NULL, NULL},
{ 5, 1, "latin1", "latin1_german1_ci", "", 1252, "LATIN1", 1, 1, NULL, NULL},
{ 14, 1, "cp1251", "cp1251_bulgarian_ci", "", 1251, "CP1251", 1, 1, NULL, NULL},
{ 15, 1, "latin1", "latin1_danish_ci", "", 1252, "LATIN1", 1, 1, NULL, NULL},
{ 17, 1, "filename", "filename", "", 0, "", 1, 5, NULL, NULL},
{ 20, 1, "latin7", "latin7_estonian_cs", "", 28603, "LATIN7", 1, 1, NULL, NULL},
{ 21, 1, "latin2", "latin2_hungarian_ci", "", 852, "LATIN2", 1, 1, NULL, NULL},
{ 23, 1, "cp1251", "cp1251_ukrainian_ci", "", 1251, "CP1251", 1, 1, NULL, NULL},
{ 27, 1, "latin2", "latin2_croatian_ci", "", 852, "LATIN2", 1, 1, NULL, NULL},
{ 29, 1, "cp1257", "cp1257_lithunian_ci", "", 1257, "CP1257", 1, 1, NULL, NULL},
{ 29, 1, "cp1257", "cp1257_lithuanian_ci", "", 1257, "CP1257", 1, 1, NULL, NULL},
{ 31, 1, "latin1", "latin1_german2_ci", "", 1252, "LATIN1", 1, 1, NULL, NULL},
{ 34, 1, "cp1250", "cp1250_czech_cs", "", 1250, "CP1250", 1, 1, NULL, NULL},
{ 42, 1, "latin7", "latin7_general_cs", "", 28603, "LATIN7", 1, 1, NULL, NULL},
Expand Down Expand Up @@ -682,7 +682,7 @@ const MARIADB_CHARSET_INFO mariadb_compiled_charsets[] =
{ 137, 1, "ucs2", "ucs2_turkish_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2},
{ 138, 1, "ucs2", "ucs2_czech_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2},
{ 139, 1, "ucs2", "ucs2_danish_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2},
{ 140, 1, "ucs2", "ucs2_lithunian_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2},
{ 140, 1, "ucs2", "ucs2_lithuanian_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2},
{ 141, 1, "ucs2", "ucs2_slovak_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2},
{ 142, 1, "ucs2", "ucs2_spanish2_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2},
{ 143, 1, "ucs2", "ucs2_roman_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2},
Expand All @@ -707,7 +707,7 @@ const MARIADB_CHARSET_INFO mariadb_compiled_charsets[] =
{ 169, 1, "utf32", "utf32_turkish_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32},
{ 170, 1, "utf32", "utf32_czech_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32},
{ 171, 1, "utf32", "utf32_danish_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32},
{ 172, 1, "utf32", "utf32_lithunian_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32},
{ 172, 1, "utf32", "utf32_lithuanian_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32},
{ 173, 1, "utf32", "utf32_slovak_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32},
{ 174, 1, "utf32", "utf32_spanish_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32},
{ 175, 1, "utf32", "utf32_roman_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32},
Expand All @@ -733,15 +733,15 @@ const MARIADB_CHARSET_INFO mariadb_compiled_charsets[] =
{ 201, 1, UTF8_MB3, UTF8_MB3"_turkish_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
{ 202, 1, UTF8_MB3, UTF8_MB3"_czech_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
{ 203, 1, UTF8_MB3, UTF8_MB3"_danish_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid },
{ 204, 1, UTF8_MB3, UTF8_MB3"_lithunian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid },
{ 204, 1, UTF8_MB3, UTF8_MB3"_lithuanian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid },
{ 205, 1, UTF8_MB3, UTF8_MB3"_slovak_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
{ 206, 1, UTF8_MB3, UTF8_MB3"_spanish2_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
{ 207, 1, UTF8_MB3, UTF8_MB3"_roman_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
{ 208, 1, UTF8_MB3, UTF8_MB3"_persian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
{ 209, 1, UTF8_MB3, UTF8_MB3"_esperanto_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
{ 210, 1, UTF8_MB3, UTF8_MB3"_hungarian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
{ 211, 1, UTF8_MB3, UTF8_MB3"_sinhala_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
{ 212, 1, UTF8_MB3, UTF8_MB3"_german_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
{ 212, 1, UTF8_MB3, UTF8_MB3"_german2_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
{ 214, 1, UTF8_MB3, UTF8_MB3"_unicode_520_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
{ 215, 1, UTF8_MB3, UTF8_MB3"_vietnamese_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
{ 213, 1, UTF8_MB3, UTF8_MB3"_croatian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, /*MDB*/
Expand Down Expand Up @@ -1451,7 +1451,7 @@ size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, MARIAD
*errorcode= errno;
goto error;
}
if ((rc= iconv(conv, IF_WIN(,(char **))&from, from_len, &to, to_len)) == (size_t)-1)
if ((rc= iconv(conv, IF_WIN(,IF_SOLARIS(,(char **)))&from, from_len, &to, to_len)) == (size_t)-1)
{
*errorcode= errno;
goto error;
Expand Down
4 changes: 4 additions & 0 deletions libmariadb/ma_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ char **get_default_configuration_dirs()
if ((env= getenv("MYSQL_HOME")) &&
add_cfg_dir(configuration_dirs, env))
goto error;
/* CONC-449: Check $MARIADB_HOME/my.cnf in addition to $MYSQL_HOME/my.cnf */
if ((env= getenv("MARIADB_HOME")) &&
add_cfg_dir(configuration_dirs, env))
goto error;
end:
return configuration_dirs;
error:
Expand Down
5 changes: 3 additions & 2 deletions libmariadb/ma_dtoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ static Bigint *d2b(U *d, int *e, int *bits, Stack_alloc *alloc)
if ((k= lo0bits(&y)))
{
x[0]= y | z << (32 - k);
z>>= k;
z>>= (k == 32) ? (--k) : k;
}
else
x[0]= y;
Expand Down Expand Up @@ -1906,7 +1906,8 @@ static char *dtoa(double dd, int mode, int ndigits, int *decpt, int *sign,
s++;
}
ret:
Bfree(S, &alloc);
if (S != NULL)
Bfree(S, &alloc);
if (mhi)
{
if (mlo && mlo != mhi)
Expand Down
171 changes: 89 additions & 82 deletions libmariadb/ma_stmt_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <mariadb_ctype.h>
#include "mysql.h"
#include <math.h> /* ceil() */
#include <limits.h>

#ifdef WIN32
#include <malloc.h>
Expand All @@ -72,6 +73,8 @@
#define LONGLONG_MAX ((long long) 0x7FFFFFFFFFFFFFFFLL)
#endif

#define MAX_DBL_STR 3 + DBL_MANT_DIG - DBL_MIN_EXP

#if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)
/* First check for ANSI C99 definition: */
#ifdef ULLONG_MAX
Expand Down Expand Up @@ -254,19 +257,25 @@ static unsigned long long my_atoull(const char *str, const char *end_str, int *e
double my_atod(const char *number, const char *end, int *error)
{
double val= 0.0;
char buffer[255];
char buffer[MAX_DBL_STR + 1];
int len= (int)(end - number);

if (len > 254)
*error= errno= 0;

if (len > MAX_DBL_STR)
{
*error= 1;
len= MAX_DBL_STR;
}

len= MIN(len, 254);
memcpy(&buffer, number, len);
memcpy(buffer, number, len);
buffer[len]= '\0';

val= strtod(buffer, NULL);
/* if (!*error)
*error= errno; */

if (errno)
*error= errno;

return val;
}

Expand Down Expand Up @@ -570,21 +579,24 @@ static void convert_froma_string(MYSQL_BIND *r_param, char *buffer, size_t len)
case MYSQL_TYPE_NEWDECIMAL:
default:
{
char *start= buffer + r_param->offset; /* stmt_fetch_column sets offset */
char *end= buffer + len;
size_t copylen= 0;

if (start < end)
if (len >= r_param->offset)
{
copylen= end - start;
if (r_param->buffer_length)
memcpy(r_param->buffer, start, MIN(copylen, r_param->buffer_length));
}
if (copylen < r_param->buffer_length)
((char *)r_param->buffer)[copylen]= 0;
*r_param->error= (copylen > r_param->buffer_length);
char *start= buffer + r_param->offset; /* stmt_fetch_column sets offset */
char *end= buffer + len;
size_t copylen= 0;

if (start < end)
{
copylen= end - start;
if (r_param->buffer_length)
memcpy(r_param->buffer, start, MIN(copylen, r_param->buffer_length));
}
if (copylen < r_param->buffer_length)
((char *)r_param->buffer)[copylen]= 0;
*r_param->error= (copylen > r_param->buffer_length);

*r_param->length= (ulong)len;
}
*r_param->length= (ulong)len;
}
break;
}
Expand Down Expand Up @@ -657,7 +669,7 @@ static void convert_from_long(MYSQL_BIND *r_param, const MYSQL_FIELD *field, lon
if (display_width < r_param->buffer_length)
{
ma_bmove_upp(buffer + display_width, buffer + len, len);
/* coverity [bad_memset] */
/* coverity[bad_memset] */
memset((void*) buffer, (int) '0', display_width - len);
len= display_width;
}
Expand Down Expand Up @@ -880,7 +892,7 @@ static void convert_from_float(MYSQL_BIND *r_param, const MYSQL_FIELD *field, fl
if (field->length < length || field->length > MAX_DOUBLE_STRING_REP_LENGTH - 1)
break;
ma_bmove_upp(buff + field->length, buff + length, length);
/* coverity [bad_memset] */
/* coverity[bad_memset] */
memset((void*) buff, (int) '0', field->length - length);
length= field->length;
}
Expand Down Expand Up @@ -1103,74 +1115,68 @@ void ps_fetch_datetime(MYSQL_BIND *r_param, const MYSQL_FIELD * field,
unsigned int len= net_field_length(row);

switch (r_param->buffer_type) {
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_TIMESTAMP:
convert_to_datetime(t, row, len, field->type);
break;
case MYSQL_TYPE_DATE:
convert_to_datetime(t, row, len, field->type);
break;
case MYSQL_TYPE_TIME:
convert_to_datetime(t, row, len, field->type);
t->year= t->day= t->month= 0;
break;
case MYSQL_TYPE_YEAR:
{
MYSQL_TIME tm;
convert_to_datetime(&tm, row, len, field->type);
shortstore(r_param->buffer, tm.year);
break;
}
default:
{
char dtbuffer[60];
MYSQL_TIME tm;
size_t length;
convert_to_datetime(&tm, row, len, field->type);
/*
if (tm.time_type== MYSQL_TIMESTAMP_TIME && tm.day)
{
tm.hour+= tm.day * 24;
tm.day=0;
}
*/
switch(field->type) {
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_TIMESTAMP:
convert_to_datetime(t, row, len, field->type);
break;
case MYSQL_TYPE_DATE:
length= sprintf(dtbuffer, "%04u-%02u-%02u", tm.year, tm.month, tm.day);
convert_to_datetime(t, row, len, field->type);
break;
case MYSQL_TYPE_TIME:
length= sprintf(dtbuffer, "%s%02u:%02u:%02u", (tm.neg ? "-" : ""), tm.hour, tm.minute, tm.second);
if (field->decimals && field->decimals <= 6)
{
char ms[8];
sprintf(ms, ".%06lu", tm.second_part);
if (field->decimals < 6)
ms[field->decimals + 1]= 0;
length+= strlen(ms);
strcat(dtbuffer, ms);
}
convert_to_datetime(t, row, len, field->type);
t->year= t->day= t->month= 0;
break;
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_TIMESTAMP:
length= sprintf(dtbuffer, "%04u-%02u-%02u %02u:%02u:%02u", tm.year, tm.month, tm.day, tm.hour, tm.minute, tm.second);
if (field->decimals && field->decimals <= 6)
{
char ms[8];
sprintf(ms, ".%06lu", tm.second_part);
if (field->decimals < 6)
ms[field->decimals + 1]= 0;
length+= strlen(ms);
strcat(dtbuffer, ms);
case MYSQL_TYPE_YEAR:
{
MYSQL_TIME tm;
convert_to_datetime(&tm, row, len, field->type);
shortstore(r_param->buffer, tm.year);
break;
}
default:
{
char dtbuffer[60];
MYSQL_TIME tm;
size_t length;
convert_to_datetime(&tm, row, len, field->type);

switch(field->type) {
case MYSQL_TYPE_DATE:
length= sprintf(dtbuffer, "%04u-%02u-%02u", tm.year, tm.month, tm.day);
break;
case MYSQL_TYPE_TIME:
length= sprintf(dtbuffer, "%s%02u:%02u:%02u", (tm.neg ? "-" : ""), tm.hour, tm.minute, tm.second);
if (field->decimals && field->decimals <= 6)
{
char ms[8];
sprintf(ms, ".%06lu", tm.second_part);
if (field->decimals < 6)
ms[field->decimals + 1]= 0;
length+= strlen(ms);
strcat(dtbuffer, ms);
}
break;
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_TIMESTAMP:
length= sprintf(dtbuffer, "%04u-%02u-%02u %02u:%02u:%02u", tm.year, tm.month, tm.day, tm.hour, tm.minute, tm.second);
if (field->decimals && field->decimals <= 6)
{
char ms[8];
sprintf(ms, ".%06lu", tm.second_part);
if (field->decimals < 6)
ms[field->decimals + 1]= 0;
length+= strlen(ms);
strcat(dtbuffer, ms);
}
break;
default:
dtbuffer[0]= 0;
length= 0;
break;
}
convert_froma_string(r_param, dtbuffer, length);
break;
default:
dtbuffer[0]= 0;
length= 0;
break;
}
convert_froma_string(r_param, dtbuffer, length);
break;
}
}
(*row) += len;
}
Expand Down Expand Up @@ -1353,3 +1359,4 @@ void mysql_init_ps_subsystem(void)
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/

289 changes: 229 additions & 60 deletions libmariadb/mariadb_lib.c

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions libmariadb/mariadb_rpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,14 @@ MARIADB_RPL_EVENT * STDCALL mariadb_rpl_fetch(MARIADB_RPL *rpl, MARIADB_RPL_EVEN
}
break;
default:
free(rpl_event);
return NULL;
break;
}
return rpl_event;
}
mem_error:
free(rpl_event);
SET_CLIENT_ERROR(rpl->mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0);
return 0;
}
Expand All @@ -407,7 +409,7 @@ void STDCALL mariadb_rpl_close(MARIADB_RPL *rpl)
return;
}

int STDCALL mariadb_rpl_optionsv(MARIADB_RPL *rpl,
int mariadb_rpl_optionsv(MARIADB_RPL *rpl,
enum mariadb_rpl_option option,
...)
{
Expand Down Expand Up @@ -458,10 +460,11 @@ int STDCALL mariadb_rpl_optionsv(MARIADB_RPL *rpl,
goto end;
}
end:
va_end(ap);
return rc;
}

int STDCALL mariadb_rpl_get_optionsv(MARIADB_RPL *rpl,
int mariadb_rpl_get_optionsv(MARIADB_RPL *rpl,
enum mariadb_rpl_option option,
...)
{
Expand Down Expand Up @@ -501,8 +504,10 @@ int STDCALL mariadb_rpl_get_optionsv(MARIADB_RPL *rpl,
break;
}
default:
va_end(ap);
return 1;
break;
}
va_end(ap);
return 0;
}
19 changes: 15 additions & 4 deletions libmariadb/mariadb_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,8 @@ my_bool mthd_stmt_get_param_metadata(MYSQL_STMT *stmt)
{
MYSQL_DATA *result;

if (!(result= stmt->mysql->methods->db_read_rows(stmt->mysql, (MYSQL_FIELD *)0, 7)))
if (!(result= stmt->mysql->methods->db_read_rows(stmt->mysql, (MYSQL_FIELD *)0,
7 + ma_extended_type_info_rows(stmt->mysql))))
return(1);

free_rows(result);
Expand All @@ -1593,9 +1594,10 @@ my_bool mthd_stmt_get_result_metadata(MYSQL_STMT *stmt)
MYSQL_DATA *result;
MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root;

if (!(result= stmt->mysql->methods->db_read_rows(stmt->mysql, (MYSQL_FIELD *)0, 7)))
if (!(result= stmt->mysql->methods->db_read_rows(stmt->mysql, (MYSQL_FIELD *)0,
7 + ma_extended_type_info_rows(stmt->mysql))))
return(1);
if (!(stmt->fields= unpack_fields(result,fields_ma_alloc_root,
if (!(stmt->fields= unpack_fields(stmt->mysql, result, fields_ma_alloc_root,
stmt->field_count, 0)))
return(1);
return(0);
Expand Down Expand Up @@ -1836,6 +1838,11 @@ static int madb_alloc_stmt_fields(MYSQL_STMT *stmt)
stmt->fields[i].decimals= stmt->mysql->fields[i].decimals;
stmt->fields[i].charsetnr= stmt->mysql->fields[i].charsetnr;
stmt->fields[i].max_length= stmt->mysql->fields[i].max_length;
stmt->fields[i].extension=
stmt->mysql->fields[i].extension ?
ma_field_extension_deep_dup(fields_ma_alloc_root,
stmt->mysql->fields[i].extension) :
NULL;
}
if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND))))
{
Expand Down Expand Up @@ -1912,7 +1919,6 @@ int stmt_read_execute_response(MYSQL_STMT *stmt)
/* since all pointers will be incorrect if another statement will
be executed, so we need to allocate memory and copy the
information */
stmt->fields[i].extension= 0; /* not in use yet */
if (mysql->fields[i].db)
stmt->fields[i].db= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].db);
if (mysql->fields[i].table)
Expand All @@ -1927,6 +1933,11 @@ int stmt_read_execute_response(MYSQL_STMT *stmt)
stmt->fields[i].catalog= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].catalog);
if (mysql->fields[i].def)
stmt->fields[i].def= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].def);
stmt->fields[i].extension=
mysql->fields[i].extension ?
ma_field_extension_deep_dup(fields_ma_alloc_root,
mysql->fields[i].extension) :
NULL;
}
}

Expand Down
11 changes: 8 additions & 3 deletions libmariadb/win32_errmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,17 @@ void ma_format_win32_error(char* buf, size_t buflen, DWORD code, _Printf_format_
ENTRY(SEC_I_CONTEXT_EXPIRED, "The context has expired and can no longer be used"),
ENTRY(SEC_E_ALGORITHM_MISMATCH, "no cipher match"),
ENTRY(SEC_E_NO_CREDENTIALS, "no credentials"),
ENTRY(SEC_E_INVALID_TOKEN, "The token supplied to function is invalid")
ENTRY(SEC_E_INVALID_TOKEN, "The token supplied to function is invalid"),
ENTRY(SEC_E_UNSUPPORTED_FUNCTION,"The function requested is not supported")
};

struct map_entry* entry = NULL;
strncpy_s(cur,end-cur, ". ", _TRUNCATE);
cur += 2;

if (cur > buf && cur[-1] != ' ' && cur[-1] != '.')
{
strncpy_s(cur,end-cur, ". ", _TRUNCATE);
cur += 2;
}

for (size_t i = 0; i < sizeof(map) / sizeof(map[0]); i++)
{
Expand Down
33 changes: 19 additions & 14 deletions mariadb_config/mariadb_config.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

static char *mariadb_progname;

#define INCLUDE "-I@CMAKE_INSTALL_PREFIX@/@INSTALL_INCLUDEDIR@ -I@CMAKE_INSTALL_PREFIX@/@INSTALL_INCLUDEDIR@/mysql"
#define LIBS "-L@CMAKE_INSTALL_PREFIX@/@INSTALL_LIBDIR@/ -lmariadb"
#define INCLUDE "-I@CMAKE_SYSROOT@@CMAKE_INSTALL_PREFIX@/@INSTALL_INCLUDEDIR@ -I@CMAKE_SYSROOT@@CMAKE_INSTALL_PREFIX@/@INSTALL_INCLUDEDIR@/mysql"
#define LIBS "-L@CMAKE_SYSROOT@@CMAKE_INSTALL_PREFIX@/@INSTALL_LIBDIR@/ -lmariadb"
#define LIBS_SYS "@extra_dynamic_LDFLAGS@"
#define CFLAGS INCLUDE
#define VERSION "@MARIADB_CLIENT_VERSION@"
Expand All @@ -16,20 +16,25 @@ static char *mariadb_progname;
#define PORT "@MARIADB_PORT@"
#define TLS_LIBRARY_VERSION "@TLS_LIBRARY_VERSION@"

#if defined(SOLARIS) || defined(__sun)
#define OPT_STRING_TYPE (char *)
#else
#define OPT_STRING_TYPE
#endif
static struct option long_options[]=
{
{"cflags", no_argument, 0, 'a'},
{"help", no_argument, 0, 'b'},
{"include", no_argument, 0, 'c'},
{"libs", no_argument, 0, 'd'},
{"libs_r", no_argument, 0, 'e'},
{"libs_sys", no_argument, 0, 'l'},
{"version", no_argument, 0, 'f'},
{"cc_version", no_argument, 0, 'g'},
{"socket", no_argument, 0, 'h'},
{"port", no_argument, 0, 'i'},
{"plugindir", no_argument, 0, 'j'},
{"tlsinfo", no_argument, 0, 'k'},
{OPT_STRING_TYPE "cflags", no_argument, 0, 'a'},
{OPT_STRING_TYPE "help", no_argument, 0, 'b'},
{OPT_STRING_TYPE "include", no_argument, 0, 'c'},
{OPT_STRING_TYPE "libs", no_argument, 0, 'd'},
{OPT_STRING_TYPE "libs_r", no_argument, 0, 'e'},
{OPT_STRING_TYPE "libs_sys", no_argument, 0, 'l'},
{OPT_STRING_TYPE "version", no_argument, 0, 'f'},
{OPT_STRING_TYPE "cc_version", no_argument, 0, 'g'},
{OPT_STRING_TYPE "socket", no_argument, 0, 'h'},
{OPT_STRING_TYPE "port", no_argument, 0, 'i'},
{OPT_STRING_TYPE "plugindir", no_argument, 0, 'j'},
{OPT_STRING_TYPE "tlsinfo", no_argument, 0, 'k'},
{NULL, 0, 0, 0}
};

Expand Down
2 changes: 1 addition & 1 deletion plugins/auth/auth_gssapi_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static int gssapi_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)

/* register client plugin */
#ifndef PLUGIN_DYNAMIC
struct st_mysql_client_plugin_AUTHENTICATION auth_gssapi_client_plugin=
struct st_mysql_client_plugin_AUTHENTICATION auth_gssapi_client_client_plugin=
#else
struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ =
#endif
Expand Down
8 changes: 5 additions & 3 deletions plugins/auth/caching_sha2_pw.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,15 @@ static char *load_pub_key_file(const char *filename, int *pub_key_size)
if (fseek(fp, 0, SEEK_END))
goto end;

*pub_key_size= ftell(fp);
if ((*pub_key_size= ftell(fp)) < 0)
goto end;

rewind(fp);

if (!(buffer= malloc(*pub_key_size + 1)))
goto end;

if (!fread(buffer, *pub_key_size, 1, fp))
if (fread(buffer, *pub_key_size, 1, fp) != (size_t)*pub_key_size)
goto end;

error= 0;
Expand Down Expand Up @@ -312,7 +314,7 @@ static int auth_caching_sha2_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
{
#if defined(HAVE_GNUTLS)
mysql->methods->set_error(mysql, CR_AUTH_PLUGIN_ERR, "HY000",
"RSA Encrytion not supported - caching_sha2_password plugin was built with GnuTLS support");
"RSA Encryption not supported - caching_sha2_password plugin was built with GnuTLS support");
return CR_ERROR;
#else
/* read public key file (if specified) */
Expand Down
13 changes: 10 additions & 3 deletions plugins/auth/my_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ static int dummy_fallback_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql __attr
char last_error[MYSQL_ERRMSG_SIZE];
unsigned int i, last_errno= ((MCPVIO_EXT *)vio)->mysql->net.last_errno;
if (last_errno)
{
strncpy(last_error, ((MCPVIO_EXT *)vio)->mysql->net.last_error,
sizeof(last_error));
sizeof(last_error) - 1);
last_error[sizeof(last_error) - 1]= 0;
}

/* safety-wise we only do 10 round-trips */
for (i=0; i < 10; i++)
Expand All @@ -130,8 +133,12 @@ static int dummy_fallback_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql __attr
break;
}
if (last_errno)
strncpy(((MCPVIO_EXT *)vio)->mysql->net.last_error, last_error,
sizeof(((MCPVIO_EXT *)vio)->mysql->net.last_error));
{
MYSQL *mysql= ((MCPVIO_EXT *)vio)->mysql;
strncpy(mysql->net.last_error, last_error,
sizeof(mysql->net.last_error) - 1);
mysql->net.last_error[sizeof(mysql->net.last_error) - 1]= 0;
}
return CR_ERROR;
}

Expand Down
1 change: 0 additions & 1 deletion plugins/auth/old_password.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ static int auth_old_password(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
we use the old scramble.
*/
pkt= (uchar*)mysql->scramble_buff;
pkt_len= SCRAMBLE_LENGTH_323 + 1;
}
else
{
Expand Down
12 changes: 10 additions & 2 deletions plugins/auth/ref10/pow22523.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@
/* qhasm: z2 = z1^2^1 */
/* asm 1: fe_sq(>z2=fe#1,<z1=fe#11); for (i = 1;i < 1;++i) fe_sq(>z2=fe#1,>z2=fe#1); */
/* asm 2: fe_sq(>z2=t0,<z1=z); for (i = 1;i < 1;++i) fe_sq(>z2=t0,>z2=t0); */
fe_sq(t0,z); for (i = 1;i < 1;++i) fe_sq(t0,t0);
fe_sq(t0,z);

/* covscan CWE-561 dead code: variable i can't be < 1
for (i = 1;i < 1;++i) fe_sq(t0,t0);
*/

/* qhasm: z8 = z2^2^2 */
/* asm 1: fe_sq(>z8=fe#2,<z2=fe#1); for (i = 1;i < 2;++i) fe_sq(>z8=fe#2,>z8=fe#2); */
Expand All @@ -70,7 +74,11 @@ fe_mul(t0,t0,t1);
/* qhasm: z22 = z11^2^1 */
/* asm 1: fe_sq(>z22=fe#1,<z11=fe#1); for (i = 1;i < 1;++i) fe_sq(>z22=fe#1,>z22=fe#1); */
/* asm 2: fe_sq(>z22=t0,<z11=t0); for (i = 1;i < 1;++i) fe_sq(>z22=t0,>z22=t0); */
fe_sq(t0,t0); for (i = 1;i < 1;++i) fe_sq(t0,t0);
fe_sq(t0,t0);

/* covscan CWE-561 dead code: variable i can't be < 1
for (i = 1;i < 1;++i) fe_sq(t0,t0);
*/

/* qhasm: z_5_0 = z9*z22 */
/* asm 1: fe_mul(>z_5_0=fe#1,<z9=fe#2,<z22=fe#1); */
Expand Down
10 changes: 8 additions & 2 deletions plugins/auth/ref10/pow225521.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
/* qhasm: z2 = z1^2^1 */
/* asm 1: fe_sq(>z2=fe#1,<z1=fe#11); for (i = 1;i < 1;++i) fe_sq(>z2=fe#1,>z2=fe#1); */
/* asm 2: fe_sq(>z2=t0,<z1=z); for (i = 1;i < 1;++i) fe_sq(>z2=t0,>z2=t0); */
fe_sq(t0,z); for (i = 1;i < 1;++i) fe_sq(t0,t0);
fe_sq(t0,z);
/* covscan CWE-561 dead code: variable i can't be < 1
for (i = 1;i < 1;++i) fe_sq(t0,t0);
*/

/* qhasm: z8 = z2^2^2 */
/* asm 1: fe_sq(>z8=fe#2,<z2=fe#1); for (i = 1;i < 2;++i) fe_sq(>z8=fe#2,>z8=fe#2); */
Expand All @@ -70,7 +73,10 @@ fe_mul(t0,t0,t1);
/* qhasm: z22 = z11^2^1 */
/* asm 1: fe_sq(>z22=fe#3,<z11=fe#1); for (i = 1;i < 1;++i) fe_sq(>z22=fe#3,>z22=fe#3); */
/* asm 2: fe_sq(>z22=t2,<z11=t0); for (i = 1;i < 1;++i) fe_sq(>z22=t2,>z22=t2); */
fe_sq(t2,t0); for (i = 1;i < 1;++i) fe_sq(t2,t2);
fe_sq(t2,t0);
/* covscan CWE-561 dead code: variable i can't be < 1
for (i = 1;i < 1;++i) fe_sq(t2,t2);
*/

/* qhasm: z_5_0 = z9*z22 */
/* asm 1: fe_mul(>z_5_0=fe#2,<z9=fe#2,<z22=fe#3); */
Expand Down
15 changes: 10 additions & 5 deletions plugins/io/remote_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ typedef struct
CURLM *multi_handle= NULL;

#ifndef PLUGIN_DYNAMIC
MARIADB_REMOTEIO_PLUGIN remote_io_plugin=
MARIADB_REMOTEIO_PLUGIN remote_io_client_plugin=
#else
MARIADB_REMOTEIO_PLUGIN _mysql_client_plugin_declaration_ =
#endif
Expand Down Expand Up @@ -290,10 +290,15 @@ MA_FILE *ma_rio_open(const char *url,const char *operation)
}
rf->curl = curl_easy_init();

curl_easy_setopt(rf->curl, CURLOPT_URL, url);
curl_easy_setopt(rf->curl, CURLOPT_WRITEDATA, file);
curl_easy_setopt(rf->curl, CURLOPT_VERBOSE, 0L);
curl_easy_setopt(rf->curl, CURLOPT_WRITEFUNCTION, rio_write_callback);
if (curl_easy_setopt(rf->curl, CURLOPT_URL, url) ||
curl_easy_setopt(rf->curl, CURLOPT_WRITEDATA, file) ||
curl_easy_setopt(rf->curl, CURLOPT_VERBOSE, 0L) ||
curl_easy_setopt(rf->curl, CURLOPT_WRITEFUNCTION, rio_write_callback))
{
free(file);
free(rf);
return NULL;
}

curl_multi_add_handle(multi_handle, rf->curl);

Expand Down
14 changes: 9 additions & 5 deletions plugins/pvio/pvio_npipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ my_bool pvio_npipe_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type,
else if (timeout <=0)
timeout_ms= -1;
else
timeout_ms = timeout*100;
timeout_ms = timeout*1000;

pvio->timeout[type]= (timeout > 0) ? timeout * 1000 : -1;
pvio->timeout[type]= timeout_ms;
return 0;
}

Expand Down Expand Up @@ -217,7 +217,6 @@ my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, "HY000", 0, "");
return 1;
}
memset(cpipe, 0, sizeof(struct st_pvio_npipe));
pvio->data= (void *)cpipe;
cpipe->pipe= INVALID_HANDLE_VALUE;
pvio->mysql= cinfo->mysql;
Expand All @@ -237,7 +236,11 @@ my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
szPipeName[MAX_PATH - 1]= 0;
snprintf(szPipeName, MAX_PATH - 1, "\\\\%s\\pipe\\%s", cinfo->host, cinfo->unix_socket);

deadline = GetTickCount64() + pvio->timeout[PVIO_CONNECT_TIMEOUT];
if (pvio->timeout[PVIO_CONNECT_TIMEOUT] > 0)
deadline = GetTickCount64() + pvio->timeout[PVIO_CONNECT_TIMEOUT];
else
deadline = INFINITE;

while (1)
{
if ((cpipe->pipe = CreateFile(szPipeName,
Expand Down Expand Up @@ -346,7 +349,8 @@ my_bool pvio_npipe_is_alive(MARIADB_PVIO *pvio)
HANDLE handle;
if (!pvio || !pvio->data)
return FALSE;
handle= ((struct st_pvio_npipe *)pvio->data)->pipe;

handle= ((struct st_pvio_npipe *)pvio->data)->pipe;
/* Copy data from named pipe without removing it */
if (PeekNamedPipe(handle, NULL, 0, NULL, NULL, NULL))
return TRUE;
Expand Down
8 changes: 7 additions & 1 deletion plugins/pvio/pvio_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,13 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
else
#endif
{
strcpy(UNIXaddr.sun_path, cinfo->unix_socket);
size_t sun_path_size = sizeof(UNIXaddr.sun_path);
strncpy(UNIXaddr.sun_path, cinfo->unix_socket, sun_path_size - 1);
if (sun_path_size == strlen(UNIXaddr.sun_path) + 1 && UNIXaddr.sun_path[sun_path_size - 1] != '\0')
{
/* Making the string null-terminated */
UNIXaddr.sun_path[sun_path_size - 1] = '\0';
}
port_length= sizeof(UNIXaddr);
}
if (pvio_socket_connect_sync_or_async(pvio, (struct sockaddr *) &UNIXaddr, port_length))
Expand Down
12 changes: 1 addition & 11 deletions unittest/libmariadb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,11 @@ SET(MANUAL_TESTS "t_aurora" "t_conc173" "rpl_api")
# Get finger print from server certificate
IF(WITH_SSL)
IF(CERT_PATH)
IF(EXISTS ${CERT_PATH}/server-cert.sha1)
FILE(READ ${CERT_PATH}/server-cert.sha1 CERT_FINGER_PRINT)
STRING(REPLACE "\n" "" CERT_FINGER_PRINT "${CERT_FINGER_PRINT}")
ADD_DEFINITIONS(-DTEST_SSL_SHA1)
ENDIF()
IF(EXISTS ${CERT_PATH}/client-key-enc.pem)
ADD_DEFINITIONS(-DTEST_SSL_PASSPHRASE)
ENDIF()
SET(API_TESTS ${API_TESTS} "ssl")
IF(WIN32)
STRING(REPLACE "\\" "\\\\" CERT_PATH ${CERT_PATH})
ENDIF()
CONFIGURE_FILE(${CC_SOURCE_DIR}/unittest/libmariadb/ssl.c.in
${CC_BINARY_DIR}/unittest/libmariadb/ssl.c)
ADD_EXECUTABLE(ssl ${CC_BINARY_DIR}/unittest/libmariadb/ssl.c)
ADD_DEFINITIONS(-DCERT_PATH="${CERT_PATH}")
ENDIF()
ENDIF()

Expand Down
1 change: 0 additions & 1 deletion unittest/libmariadb/charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ static int bug30472_retrieve_charset_info(MYSQL *con,
row= mysql_fetch_row(rs);
FAIL_IF(!row, "Couldn't fetch row");
strcpy(character_set_client, row[1]);
diag("cs: %s", row[1]);
mysql_free_result(rs);

rc= mysql_query(con, "SHOW VARIABLES LIKE 'character_set_results'");
Expand Down
23 changes: 23 additions & 0 deletions unittest/libmariadb/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1426,8 +1426,31 @@ static int test_sslenforce(MYSQL *unused __attribute__((unused)))
}
#endif

static int test_conc457(MYSQL *mysql)
{
MYSQL_RES *result;

SKIP_MYSQL(mysql);

result= mysql_list_processes(mysql);

FAIL_IF(mysql_field_count(mysql) != 9, "expected 9 columns");
mysql_free_result(result);
return OK;
}

static int test_conc458(MYSQL *my __attribute__((unused)))
{
MYSQL *mysql= mysql_init(NULL);
FAIL_IF(mysql_get_timeout_value(mysql) != 0, "expected timeout 0");
mysql_close(mysql);
return OK;
}


struct my_tests_st my_tests[] = {
{"test_conc458", test_conc458, TEST_CONNECTION_NONE, 0, NULL, NULL},
{"test_conc457", test_conc457, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc384", test_conc384, TEST_CONNECTION_NONE, 0, NULL, NULL},
#ifndef _WIN32
{"test_mdev12965", test_mdev12965, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
Expand Down
14 changes: 14 additions & 0 deletions unittest/libmariadb/my_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
/* prevent warnings on Win64 by using STMT_LEN instead of strlen */
#define STMT_LEN(A) (unsigned long)strlen((A))

#define SKIP_TRAVIS()\
if (getenv("TRAVIS"))\
{\
diag("Skip test on Travis CI");\
return SKIP;\
}

#define SKIP_MYSQL(mysql)\
if (!mariadb_connection(mysql))\
{\
diag("Skip test for non MariaDB server");\
return OK;\
}

#define check_mysql_rc(rc, mysql) \
if (rc)\
{\
Expand Down
4 changes: 2 additions & 2 deletions unittest/libmariadb/ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,7 @@ static int test_bind_negative(MYSQL *mysql)
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
check_mysql_rc(rc, mysql);

rc= mysql_query(mysql, "create temporary table t1 (c1 int unsigned)");
rc= mysql_query(mysql, "create temporary table t1 (c1 int)");
check_mysql_rc(rc, mysql);

rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1), (-1)");
Expand Down Expand Up @@ -2543,7 +2543,7 @@ static int test_pure_coverage(MYSQL *mysql)
FAIL_IF(!rc, "Error expected");
mysql_stmt_close(stmt);

/* Query without params and result should allow to bind 0 arrays */
/* Query without params and result should allow one to bind 0 arrays */
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, SL("insert into test_pure(c2) values(10)"));
Expand Down
41 changes: 39 additions & 2 deletions unittest/libmariadb/ps_bugs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5121,7 +5121,9 @@ static int test_maxparam(MYSQL *mysql)
int val= 1;
size_t mem= strlen(query) + 1 + 4 * 65535 + 1;
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
MYSQL_BIND bind[65535];
MYSQL_BIND* bind;

bind = calloc(sizeof(MYSQL_BIND), 65535);

rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
check_mysql_rc(rc, mysql);
Expand All @@ -5136,7 +5138,6 @@ static int test_maxparam(MYSQL *mysql)
rc= mysql_stmt_prepare(stmt, SL(buffer));
check_stmt_rc(rc, stmt);

memset(bind, 0, sizeof(MYSQL_BIND) * 65535);
for (i=0; i < 65534; i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
Expand All @@ -5158,10 +5159,46 @@ static int test_maxparam(MYSQL *mysql)
FAIL_IF(mysql_stmt_errno(stmt) != ER_PS_MANY_PARAM, "Expected ER_PS_MANY_PARAM error");

mysql_stmt_close(stmt);
free(bind);
return OK;
}

static int test_mdev_21920(MYSQL *mysql)
{
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
MYSQL_BIND bind[1];
int rc;
char buffer[128];

rc= mysql_stmt_prepare(stmt, SL("SELECT ''"));
check_stmt_rc(rc, stmt);

rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);

buffer[0]= 1;

memset(bind, 0, sizeof(MYSQL_BIND));
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= buffer;
bind[0].buffer_length= 127;

rc= mysql_stmt_bind_result(stmt, bind);
check_stmt_rc(rc, stmt);

rc= mysql_stmt_fetch(stmt);
check_stmt_rc(rc, stmt);

FAIL_IF(buffer[0] != 0, "Expected empty string");


mysql_stmt_close(stmt);

return OK;
}

struct my_tests_st my_tests[] = {
{"test_mdev_21920", test_mdev_21920, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_maxparam", test_maxparam, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_conc424", test_conc424, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_conc344", test_conc344, TEST_CONNECTION_NEW, 0, NULL, NULL},
Expand Down
85 changes: 36 additions & 49 deletions unittest/libmariadb/ssl.c.in → unittest/libmariadb/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,22 @@ char sslkey[FNLEN];
char sslkey_enc[FNLEN];
char sslca[FNLEN];
char sslcrl[FNLEN];
char ssl_cert_finger_print[129]= {0};
char bad_cert_finger_print[]= "00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:01:23:45:67";

pthread_mutex_t LOCK_test;

void read_fingerprint()
{
FILE *f= fopen(CERT_PATH "/server-cert.sha1", "r");
if (f)
{
if (!fscanf(f, "%128s", ssl_cert_finger_print))
ssl_cert_finger_print[0]= 0;
fclose(f);
}
}

int check_skip_ssl()
{
const char *ssldir= NULL;
Expand All @@ -61,7 +74,7 @@ int check_skip_ssl()
}
if (!(ssldir= getenv("SECURE_LOAD_PATH")))
{
ssldir= "@CERT_PATH@";
ssldir= CERT_PATH;
if (!strlen(ssldir))
{
diag("certificate directory not found");
Expand Down Expand Up @@ -436,10 +449,6 @@ static int test_password_protected(MYSQL *unused __attribute__((unused)))
if (check_skip_ssl())
return SKIP;

#ifndef TEST_SSL_PASSPHRASE
return SKIP;
#endif

mysql= mysql_init(NULL);
FAIL_IF(!mysql, "Can't allocate memory");

Expand Down Expand Up @@ -616,6 +625,8 @@ static int verify_ssl_server_cert(MYSQL *unused __attribute__((unused)))
if (!hostname || !strcmp(hostname, "localhost"))
return SKIP;

SKIP_TRAVIS();

mysql= mysql_init(NULL);
FAIL_IF(!mysql, "Can't allocate memory");

Expand Down Expand Up @@ -784,8 +795,6 @@ static int test_conc_102(MYSQL *mysql)
return OK;
}

const char *ssl_cert_finger_print= "@CERT_FINGER_PRINT@";

static int test_ssl_fp(MYSQL *unused __attribute__((unused)))
{
MYSQL *my;
Expand All @@ -796,22 +805,16 @@ static int test_ssl_fp(MYSQL *unused __attribute__((unused)))
if (check_skip_ssl())
return SKIP;

#ifndef TEST_SSL_SHA1
diag("Fingerprint of server certificate not found");
return SKIP;
#endif

if (!ssl_cert_finger_print[0])
{
diag("No fingerprint available");
return SKIP;
}

my= mysql_init(NULL);
FAIL_IF(!my, "mysql_init() failed");

mysql_ssl_set(my,0, 0, sslca, 0, 0);

mysql_options(my, MARIADB_OPT_SSL_FP, bad_cert_finger_print);

FAIL_IF(mysql_real_connect(my, hostname, username, password, schema,
port, socketname, 0), mysql_error(my));

mysql_options(my, MARIADB_OPT_SSL_FP, ssl_cert_finger_print);

FAIL_IF(!mysql_real_connect(my, hostname, username, password, schema,
Expand Down Expand Up @@ -843,21 +846,12 @@ static int test_ssl_fp_list(MYSQL *unused __attribute__((unused)))
if (check_skip_ssl())
return SKIP;

#ifndef TEST_SSL_SHA1
diag("Fingerprint of server certificate not found");
return SKIP;
#endif
if (!ssl_cert_finger_print[0])
{
diag("No fingerprint available");
return SKIP;
}
my= mysql_init(NULL);
FAIL_IF(!my, "mysql_init() failed");

mysql_ssl_set(my,0, 0, sslca, 0, 0);

mysql_options(my, MARIADB_OPT_SSL_FP_LIST, "@CERT_PATH@/server-cert.sha1");
mysql_options(my, MARIADB_OPT_SSL_FP_LIST, CERT_PATH "/server-cert.sha1");

if(!mysql_real_connect(my, hostname, username, password, schema,
port, socketname, 0))
Expand Down Expand Up @@ -1200,16 +1194,6 @@ static int test_conc286(MYSQL *unused __attribute__((unused)))
if (check_skip_ssl())
return SKIP;

#ifndef TEST_SSL_SHA1
diag("Fingerprint of server certificate not found");
return SKIP;
#endif

if (!ssl_cert_finger_print[0])
{
diag("No fingerprint available");
return SKIP;
}
my= mysql_init(NULL);
FAIL_IF(!my, "mysql_init() failed");

Expand Down Expand Up @@ -1304,16 +1288,6 @@ static int test_mdev14101(MYSQL *my __attribute__((unused)))

static int test_conc386(MYSQL *mysql)
{
#ifdef WIN32
if (_access(sslcombined, 0) == -1)
#else
if (access(sslcombined, R_OK) != 0)
#endif
{
diag("combined cert/key file not found");
return SKIP;
}

mysql= mysql_init(NULL);
mysql_ssl_set(mysql,
sslcombined,
Expand All @@ -1325,7 +1299,6 @@ static int test_conc386(MYSQL *mysql)
port, socketname, 0), mysql_error(mysql));
FAIL_IF(check_cipher(mysql) != 0, "Invalid cipher");
mysql_close(mysql);
unlink(sslcombined);
return OK;
}

Expand All @@ -1347,6 +1320,19 @@ static int test_ssl_verify(MYSQL *my __attribute__((unused)))
diag("error expected: %s\n", mysql_error(mysql));
mysql_close(mysql);

/* verify, using system ca should pass */

/* Disable this for now, since for some unknown reason it fails on travis
setenv("SSL_CERT_DIR", CERT_PATH, 1);
mysql= mysql_init(NULL);
mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &enforce);
mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &verify);
FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema,
port, socketname, 0), mysql_error(mysql));
mysql_close(mysql);
unsetenv("SSL_CERT_DIR");
*/

/* verify against local ca, this should pass */
mysql= mysql_init(NULL);
mysql_ssl_set(mysql,0, 0, sslca, 0, 0);
Expand Down Expand Up @@ -1423,6 +1409,7 @@ int main(int argc, char **argv)
#endif

get_envvars();
read_fingerprint();

if (argc > 1)
get_options(argc, argv);
Expand Down
2 changes: 1 addition & 1 deletion zlib/uncompr.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int ZEXPORT uncompress (dest, destLen, source, sourceLen)
const Bytef *source;
uLong sourceLen;
{
z_stream stream;
z_stream stream= {0};
int err;

stream.next_in = (Bytef*)source;
Expand Down