Fix binlogrouter build failures with GCC 8

GCC 8 appears to have improved the snprintf truncation detection which
revealed problems in the binlogrouter.
This commit is contained in:
Markus Mäkelä 2018-04-17 21:55:47 +03:00
parent 3a1c2119fb
commit ad15f4d4be
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
3 changed files with 8 additions and 10 deletions

View File

@ -78,11 +78,11 @@ bool binlog_next_file_exists(const char* binlogdir, const char* binlog)
{
char buf[BLRM_BINLOG_NAME_STR_LEN + 1];
char filename[PATH_MAX + 1];
char next_file[BLRM_BINLOG_NAME_STR_LEN + 1];
char next_file[BLRM_BINLOG_NAME_STR_LEN + 1 + 20];
int offset = sptr - binlog;
memcpy(buf, binlog, offset);
buf[offset] = '\0';
sprintf(next_file, BINLOG_NAMEFMT, buf, filenum);
snprintf(next_file, sizeof(next_file), BINLOG_NAMEFMT, buf, filenum);
snprintf(filename, PATH_MAX, "%s/%s", binlogdir, next_file);
filename[PATH_MAX] = '\0';

View File

@ -240,7 +240,7 @@ typedef struct start_encryption_event
int
blr_file_init(ROUTER_INSTANCE *router)
{
char path[PATH_MAX + 1] = "";
char path[PATH_MAX + 1 - BINLOG_FILE_EXTRA_INFO - BINLOG_FNAMELEN - 2] = "";
char filename[PATH_MAX + 1] = "";
int file_found, n = 1;
int root_len, i;
@ -262,9 +262,7 @@ blr_file_init(ROUTER_INSTANCE *router)
return 0;
}
strcpy(path, datadir);
strcat(path, "/");
strcat(path, router->service->name);
snprintf(path, sizeof(path), "%s/%s", datadir, router->service->name);
if (access(path, R_OK) == -1)
{

View File

@ -7045,9 +7045,9 @@ static bool blr_slave_gtid_request(ROUTER_INSTANCE *router,
SQLITE_OPEN_READONLY,
NULL) != SQLITE_OK)
{
char errmsg[BINLOG_ERROR_MSG_LEN + 1];
char errmsg[BINLOG_ERROR_MSG_LEN + sizeof(dbpath) + 1];
snprintf(errmsg,
BINLOG_ERROR_MSG_LEN,
sizeof(errmsg),
"Slave %lu: failed to open GTID maps db '%s': %s",
(unsigned long)slave->serverid,
dbpath,
@ -8178,7 +8178,7 @@ static bool blr_handle_admin_stmt(ROUTER_INSTANCE *router,
else
{
int rc;
char error_string[BINLOG_ERROR_MSG_LEN + 1] = "";
char error_string[BINLOG_ERROR_MSG_LEN + 1 + BINLOG_ERROR_MSG_LEN + 1] = "";
MASTER_SERVER_CFG *current_master = NULL;
current_master = (MASTER_SERVER_CFG *)MXS_CALLOC(1, sizeof(MASTER_SERVER_CFG));
@ -8226,7 +8226,7 @@ static bool blr_handle_admin_stmt(ROUTER_INSTANCE *router,
spinlock_release(&router->lock);
snprintf(error_string, BINLOG_ERROR_MSG_LEN,
snprintf(error_string, sizeof(error_string),
"Error writing into %s/master.ini: %s",
router->binlogdir,
error);