Fixed to Coverity defects and a fix to tee filter not compiling with SS_DEBUG flag.

This commit is contained in:
Markus Makela
2015-03-07 06:00:01 +02:00
parent dc1829fc8a
commit ea039dd01a
12 changed files with 50 additions and 39 deletions

View File

@ -73,8 +73,8 @@ resultset_free(RESULTSET *resultset)
{ {
RESULT_COLUMN *col; RESULT_COLUMN *col;
if (resultset) if (resultset != NULL)
return; {
col = resultset->column; col = resultset->column;
while (col) while (col)
{ {
@ -85,6 +85,7 @@ RESULT_COLUMN *col;
col = next; col = next;
} }
free(resultset); free(resultset);
}
} }
/** /**

View File

@ -42,6 +42,7 @@ static bool success = false;
int hup(DCB* dcb) int hup(DCB* dcb)
{ {
success = true; success = true;
return 1;
} }
/** /**
@ -108,7 +109,8 @@ hkinit();
skygw_log_sync_all(); skygw_log_sync_all();
ss_info_dassert(0 != result, "Stop should succeed"); ss_info_dassert(0 != result, "Stop should succeed");
dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER); if((dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER)) == NULL)
return 1;
ss_info_dassert(dcb != NULL, "DCB allocation failed"); ss_info_dassert(dcb != NULL, "DCB allocation failed");
session = session_alloc(service,dcb); session = session_alloc(service,dcb);

View File

@ -34,9 +34,9 @@ add_library(namedserverfilter SHARED namedserverfilter.c)
target_link_libraries(namedserverfilter log_manager utils) target_link_libraries(namedserverfilter log_manager utils)
install(TARGETS namedserverfilter DESTINATION modules) install(TARGETS namedserverfilter DESTINATION modules)
add_library(lagfilter SHARED lagfilter.c) add_library(slavelag SHARED slavelag.c)
target_link_libraries(lagfilter log_manager utils query_classifier) target_link_libraries(slavelag log_manager utils query_classifier)
install(TARGETS lagfilter DESTINATION modules) install(TARGETS slavelag DESTINATION modules)
add_subdirectory(hint) add_subdirectory(hint)

View File

@ -1558,6 +1558,7 @@ bool check_match_any(FW_INSTANCE* my_instance, FW_SESSION* my_session, GWBUF *qu
} }
qlen = gw_mysql_get_byte3(memptr); qlen = gw_mysql_get_byte3(memptr);
qlen = qlen < 0xffffff ? qlen : 0xffffff;
fullquery = malloc((qlen) * sizeof(char)); fullquery = malloc((qlen) * sizeof(char));
memcpy(fullquery,memptr + 5,qlen - 1); memcpy(fullquery,memptr + 5,qlen - 1);
memset(fullquery + qlen - 1,0,1); memset(fullquery + qlen - 1,0,1);
@ -1612,6 +1613,7 @@ bool check_match_all(FW_INSTANCE* my_instance, FW_SESSION* my_session, GWBUF *qu
} }
qlen = gw_mysql_get_byte3(memptr); qlen = gw_mysql_get_byte3(memptr);
qlen = qlen < 0xffffff ? qlen : 0xffffff;
fullquery = malloc((qlen) * sizeof(char)); fullquery = malloc((qlen) * sizeof(char));
memcpy(fullquery,memptr + 5,qlen - 1); memcpy(fullquery,memptr + 5,qlen - 1);
memset(fullquery + qlen - 1,0,1); memset(fullquery + qlen - 1,0,1);

View File

@ -32,7 +32,7 @@ extern size_t log_ses_count[];
extern __thread log_info_t tls_log_info; extern __thread log_info_t tls_log_info;
/** /**
* @file lagfilter.c - a very simple filter designed to send queries to the * @file slavelag.c - a very simple filter designed to send queries to the
* master server after data modification has occurred. This is done to prevent * master server after data modification has occurred. This is done to prevent
* replication lag affecting the outcome of a select query. * replication lag affecting the outcome of a select query.
* *
@ -43,7 +43,10 @@ extern __thread log_info_t tls_log_info;
* *
* count=<number of queries> Queries to route to master after data modification. * count=<number of queries> Queries to route to master after data modification.
* time=<time period> Seconds to wait before queries are routed to slaves. * time=<time period> Seconds to wait before queries are routed to slaves.
* match=<regex> Regex for matching
* ignore=<regex> Regex for ignoring
* *
* The filter also has two options: @c case, which makes the regex case-sensitive, and @c ignorecase, which does the opposite.
* Date Who Description * Date Who Description
* 03/03/2015 Markus Mäkelä Written for demonstrative purposes * 03/03/2015 Markus Mäkelä Written for demonstrative purposes
* @endverbatim * @endverbatim
@ -333,8 +336,8 @@ time_t now = time(NULL);
if(query_classifier_get_operation(queue) & (QUERY_OP_DELETE|QUERY_OP_INSERT|QUERY_OP_UPDATE)) if(query_classifier_get_operation(queue) & (QUERY_OP_DELETE|QUERY_OP_INSERT|QUERY_OP_UPDATE))
{ {
sql = modutil_get_SQL(queue); if((sql = modutil_get_SQL(queue)) != NULL)
{
if(my_instance->nomatch == NULL||(my_instance->nomatch && regexec(&my_instance->nore,sql,0,NULL,0) != 0)) if(my_instance->nomatch == NULL||(my_instance->nomatch && regexec(&my_instance->nore,sql,0,NULL,0) != 0))
{ {
if(my_instance->match == NULL|| if(my_instance->match == NULL||
@ -345,9 +348,9 @@ time_t now = time(NULL);
my_instance->stats.n_modified++; my_instance->stats.n_modified++;
} }
} }
free(sql); free(sql);
} }
}
else if(my_session->hints_left > 0) else if(my_session->hints_left > 0)
{ {
queue->hint = hint_create_route(queue->hint, queue->hint = hint_create_route(queue->hint,

View File

@ -1170,13 +1170,7 @@ clientReply (FILTER* instance, void *session, GWBUF *reply)
if(my_session->waiting[PARENT]) if(my_session->waiting[PARENT])
{ {
route = true; route = true;
#ifdef SS_DEBUG
ss_dassert(my_session->replies[PARENT] < 2 ||
modutil_count_signal_packets(my_session->tee_replybuf,
my_session->use_ok,
my_session->eof[PARENT]) == 0);
skygw_log_write_flush(LOGFILE_DEBUG,"tee.c:[%d] Routing partial response set.",my_session->d_id);
#endif
} }
else if(my_session->eof[PARENT] >= min_eof && else if(my_session->eof[PARENT] >= min_eof &&
my_session->eof[CHILD] >= min_eof) my_session->eof[CHILD] >= min_eof)

View File

@ -82,7 +82,7 @@ struct dirent *dp;
strcpy(path, "/usr/local/skysql/MaxScale"); strcpy(path, "/usr/local/skysql/MaxScale");
if ((ptr = getenv("MAXSCALE_HOME")) != NULL) if ((ptr = getenv("MAXSCALE_HOME")) != NULL)
{ {
strcpy(path, ptr); strncpy(path, ptr,PATH_MAX);
} }
strcat(path, "/"); strcat(path, "/");
strcat(path, router->service->name); strcat(path, router->service->name);
@ -196,7 +196,7 @@ unsigned char magic[] = BINLOG_MAGIC;
fsync(fd); fsync(fd);
close(router->binlog_fd); close(router->binlog_fd);
spinlock_acquire(&router->binlog_lock); spinlock_acquire(&router->binlog_lock);
strcpy(router->binlog_name, file); strncpy(router->binlog_name, file,BINLOG_FNAMELEN+1);
router->binlog_position = 4; /* Initial position after the magic number */ router->binlog_position = 4; /* Initial position after the magic number */
spinlock_release(&router->binlog_lock); spinlock_release(&router->binlog_lock);
router->binlog_fd = fd; router->binlog_fd = fd;
@ -230,7 +230,7 @@ int fd;
fsync(fd); fsync(fd);
close(router->binlog_fd); close(router->binlog_fd);
spinlock_acquire(&router->binlog_lock); spinlock_acquire(&router->binlog_lock);
strcpy(router->binlog_name, file); strncpy(router->binlog_name, file,BINLOG_FNAMELEN+1);
router->binlog_position = lseek(fd, 0L, SEEK_END); router->binlog_position = lseek(fd, 0L, SEEK_END);
spinlock_release(&router->binlog_lock); spinlock_release(&router->binlog_lock);
router->binlog_fd = fd; router->binlog_fd = fd;
@ -310,7 +310,7 @@ BLFILE *file;
spinlock_release(&router->fileslock); spinlock_release(&router->fileslock);
return NULL; return NULL;
} }
strcpy(file->binlogname, binlog); strncpy(file->binlogname, binlog,BINLOG_FNAMELEN+1);
file->refcnt = 1; file->refcnt = 1;
file->cache = 0; file->cache = 0;
spinlock_init(&file->lock); spinlock_init(&file->lock);

View File

@ -1228,8 +1228,8 @@ MYSQL_session *auth_info;
if ((auth_info = calloc(1, sizeof(MYSQL_session))) == NULL) if ((auth_info = calloc(1, sizeof(MYSQL_session))) == NULL)
return NULL; return NULL;
strcpy(auth_info->user, username); strncpy(auth_info->user, username,MYSQL_USER_MAXLEN+1);
strcpy(auth_info->db, database); strncpy(auth_info->db, database,MYSQL_DATABASE_MAXLEN+1);
gw_sha1_str((const uint8_t *)password, strlen(password), auth_info->client_sha1); gw_sha1_str((const uint8_t *)password, strlen(password), auth_info->client_sha1);
return auth_info; return auth_info;

View File

@ -385,7 +385,9 @@ char *sql;
if (modutil_MySQL_Query(queue, &sql, &len, &residual)) if (modutil_MySQL_Query(queue, &sql, &len, &residual))
{ {
sql = strndup(sql, len); sql = strndup(sql, len);
return maxinfo_execute_query(instance, session, sql); int rc = maxinfo_execute_query(instance, session, sql);
free(sql);
return rc;
} }
else else
{ {

View File

@ -85,6 +85,7 @@ int len;
return; return;
sprintf(msg, "%s in query '%s'", desc, sql); sprintf(msg, "%s in query '%s'", desc, sql);
maxinfo_send_error(dcb, 1149, msg); maxinfo_send_error(dcb, 1149, msg);
free(msg);
} }
/** /**
@ -112,7 +113,7 @@ int len;
data[4] = 0xff; // Error indicator data[4] = 0xff; // Error indicator
data[5] = errcode & 0xff; // Error Code data[5] = errcode & 0xff; // Error Code
data[6] = (errcode >> 8) & 0xff; // Error Code data[6] = (errcode >> 8) & 0xff; // Error Code
strncpy((char *)&data[7], "#42000", 6); memcpy(&data[7], "#42000", 6);
strncpy((char *)&data[13], msg, strlen(msg)); // Error Message memcpy(&data[13], msg, strlen(msg)); // Error Message
dcb->func.write(dcb, pkt); dcb->func.write(dcb, pkt);
} }

View File

@ -735,7 +735,7 @@ exec_select(DCB *dcb, MAXINFO_TREE *tree)
static int static int
maxinfo_pattern_match(char *pattern, char *str) maxinfo_pattern_match(char *pattern, char *str)
{ {
int anchor, len, trailing; int anchor = 0, len, trailing;
char *fixed; char *fixed;
extern char *strcasestr(); extern char *strcasestr();

View File

@ -100,6 +100,7 @@ MAXINFO_TREE *col, *table;
} }
} }
// Malformed show // Malformed show
free(text);
free_tree(tree); free_tree(tree);
*parse_error = PARSE_MALFORMED_SHOW; *parse_error = PARSE_MALFORMED_SHOW;
return NULL; return NULL;
@ -151,6 +152,8 @@ MAXINFO_TREE *tree = NULL;
case LT_FROM: case LT_FROM:
return make_tree_node(MAXOP_COLUMNS, text, NULL, return make_tree_node(MAXOP_COLUMNS, text, NULL,
NULL); NULL);
default:
free(text);
} }
break; break;
case LT_STAR: case LT_STAR:
@ -159,6 +162,8 @@ MAXINFO_TREE *tree = NULL;
if (lookahead != LT_FROM) if (lookahead != LT_FROM)
return make_tree_node(MAXOP_ALL_COLUMNS, NULL, NULL, return make_tree_node(MAXOP_ALL_COLUMNS, NULL, NULL,
NULL); NULL);
default:
free(text2);
} }
return NULL; return NULL;
} }
@ -180,6 +185,7 @@ MAXINFO_TREE *tree = NULL;
*ptr = fetch_token(*ptr, &token, &text); *ptr = fetch_token(*ptr, &token, &text);
if (token == LT_STRING) if (token == LT_STRING)
return make_tree_node(MAXOP_TABLE, text, NULL, NULL); return make_tree_node(MAXOP_TABLE, text, NULL, NULL);
free(text);
return NULL; return NULL;
} }