pgpool2.git / summary / log / commit / refs

commit    7bef7650c1679687ca64bbd41470fc55ff9372da
Author:   Muhammad Usama <m.usama@gmail.com>
Date:     Thu Jul 17 14:07:55 2014 +0000

    Fix coverity issue:1111380 Logically dead code
    Fix coverity issue:1111382 Logically dead code
    Fix coverity issue:1111402 Explicit null dereferenced
    Fix coverity issue:1111405 Explicit null dereferenced
    Fix coverity issue:1111407 Dereference after null check
    Fix coverity issue:1111408 Explicit null dereferenced
    Fix coverity issue:1111409 Dereference after null check
    Fix coverity issue:1111383 Logically dead code
    Fix coverity issue:1111492 Structurally dead code
    Fix coverity issue:1111417 Nesting level does not match indentation
    Fix coverity issue:1111379 Logically dead code
    Fix coverity issue:1111406 Explicit null dereferenced
    Fix coverity issue:1111396 Explicit null dereferenced
    Fix coverity issue:1111397 Explicit null dereferenced


src/libs/pcp/pcp.c | 35 +++++++------- src/parallel_query/pool_rewrite_outfuncs.c | 75 ++++++++++++++++++------------ src/parser/outfuncs.c | 2 - src/pcp_con/pcp_child.c | 4 +- src/system_db/pool_system.c | 5 +- src/utils/pool_relcache.c | 14 +----- 6 files changed, 66 insertions(+), 69 deletions(-) diff --git a/src/libs/pcp/pcp.c b/src/libs/pcp/pcp.c index b4d8b4203..db6e513c4 100644 --- a/src/libs/pcp/pcp.c +++ b/src/libs/pcp/pcp.c @@ -625,11 +625,6 @@ pcp_process_info(int pid, int *array_size) return NULL; rsize = ntohl(rsize); buf = (char *)palloc(rsize); - if (buf == NULL) - { - errorcode = NOMEMERR; - return NULL; - } if (pcp_read(pc, buf, rsize - sizeof(int))) { pfree(buf); @@ -657,26 +652,20 @@ pcp_process_info(int pid, int *array_size) *array_size = ci_size; process_info = (ProcessInfo *)palloc(sizeof(ProcessInfo) * ci_size); - if (process_info == NULL) - { - pfree(buf); - errorcode = NOMEMERR; - return NULL; - } - conn_info = (ConnectionInfo *)palloc(sizeof(ConnectionInfo) * ci_size); - if (conn_info == NULL) - { - pfree(buf); - pfree(process_info); - errorcode = NOMEMERR; - return NULL; - } continue; } else if (strcmp(buf, "ProcessInfo") == 0) { + if(process_info == NULL) + { + if (debug) fprintf(stderr, "DEBUG: invalid data.\"%s\"\n", buf); + pfree(buf); + errorcode = UNKNOWNERR; + return NULL; + } + process_info[offset].connection_info = &conn_info[offset]; index = (char *) memchr(buf, '\0', rsize) + 1; @@ -1300,6 +1289,14 @@ pcp_pool_status(int *array_size) } else if (strcmp(buf, "ProcessConfig") == 0) { + if(status == NULL) + { + if (debug) fprintf(stderr, "DEBUG: invalid data.\"%s\"\n", buf); + pfree(buf); + errorcode = UNKNOWNERR; + return NULL; + } + index = (char *) memchr(buf, '\0', rsize) + 1; if (index != NULL) strlcpy(status[offset].name, index, POOLCONFIG_MAXNAMELEN+1); diff --git a/src/parallel_query/pool_rewrite_outfuncs.c b/src/parallel_query/pool_rewrite_outfuncs.c index 9d9376388..5fed42861 100644 --- a/src/parallel_query/pool_rewrite_outfuncs.c +++ b/src/parallel_query/pool_rewrite_outfuncs.c @@ -339,6 +339,9 @@ _checkVirtualColumn(ColumnRef *col,RewriteQuery *message) } } + if(!colname) + return check_col; + if(analyze->partstate[SELECT_FROMCLAUSE] == 'S') { if (message->table_relname) @@ -2662,25 +2665,27 @@ static void writeRangeHeader(RewriteQuery *message,ConInfoTodblink *dblink, Stri v_colnum = virtual->col_num; delay_string_append_char(message, str, "SELECT "); - - for(i = 0; i < v_colnum; i++) + if(table) { - if(!strcmp(virtual->table_list[i],table) && virtual->valid[i] != -1) + for(i = 0; i < v_colnum; i++) { - - if(first == 0) + if(!strcmp(virtual->table_list[i],table) && virtual->valid[i] != -1) { - delay_string_append_char(message, str, virtual->table_list[i]); - delay_string_append_char(message, str, "."); - delay_string_append_char(message, str, virtual->col_list[i]); - first = 1; - } - else - { - delay_string_append_char(message, str, ", "); - delay_string_append_char(message, str, virtual->table_list[i]); - delay_string_append_char(message, str, "."); - delay_string_append_char(message, str, virtual->col_list[i]); + + if(first == 0) + { + delay_string_append_char(message, str, virtual->table_list[i]); + delay_string_append_char(message, str, "."); + delay_string_append_char(message, str, virtual->col_list[i]); + first = 1; + } + else + { + delay_string_append_char(message, str, ", "); + delay_string_append_char(message, str, virtual->table_list[i]); + delay_string_append_char(message, str, "."); + delay_string_append_char(message, str, virtual->col_list[i]); + } } } } @@ -2722,6 +2727,11 @@ static void writeRangeFooter(RewriteQuery *message,ConInfoTodblink *dblink, Stri if(!table) { message->r_code = SELECT_RELATION_ERROR; + /* + * since we are unable to get the table name so nothing much we can + * do so bailout + */ + return; } delay_string_append_char(message, str, table); @@ -4166,10 +4176,11 @@ _rewriteFuncCall(Node *BaseSelect, RewriteQuery *message, ConInfoTodblink *dblin } } - if(strcmp(funcname,"user") == 0 || + if(funcname && + (strcmp(funcname,"user") == 0 || strcmp(funcname,"current_user") == 0 || strcmp(funcname,"session_user") == 0 || - strcmp(funcname,"current_role") == 0) + strcmp(funcname,"current_role") == 0)) return ; delay_string_append_char(message, str, "("); @@ -4379,18 +4390,24 @@ _rewriteTypeName(Node *BaseSelect, RewriteQuery *message, ConInfoTodblink *dblin dot = 1; else delay_string_append_char(message, str, "."); - if(node->typemod < 0) + + if(node->typemod < 0) + { + if(message->rewritelock != -1) { - if(message->rewritelock != -1) - { - delay_string_append_char(message, str, "\"\""); - delay_string_append_char(message, str, typename); - delay_string_append_char(message, str, "\"\""); - } else { - delay_string_append_char(message, str, typename); - } - } else + delay_string_append_char(message, str, "\"\""); delay_string_append_char(message, str, typename); + delay_string_append_char(message, str, "\"\""); + } + else + { + delay_string_append_char(message, str, typename); + } + } + else + { + delay_string_append_char(message, str, typename); + } } } @@ -6900,8 +6917,6 @@ _rewriteCreateTrigStmt(Node *BaseSelect, RewriteQuery *message, ConInfoTodblink if (node->events & TRIGGER_TYPE_INSERT) { - if (has_events) - delay_string_append_char(message, str, "OR "); delay_string_append_char(message, str, "INSERT "); has_events = true; } diff --git a/src/parser/outfuncs.c b/src/parser/outfuncs.c index ed6a26985..de220b41c 100644 --- a/src/parser/outfuncs.c +++ b/src/parser/outfuncs.c @@ -3278,8 +3278,6 @@ _outCreateTrigStmt(String *str, CreateTrigStmt *node) if (node->events & TRIGGER_TYPE_INSERT) { - if (has_events) - string_append_char(str, "OR "); string_append_char(str, "INSERT "); has_events = true; } diff --git a/src/pcp_con/pcp_child.c b/src/pcp_con/pcp_child.c index 31c36e739..bc6e62a1c 100644 --- a/src/pcp_con/pcp_child.c +++ b/src/pcp_con/pcp_child.c @@ -535,13 +535,13 @@ user_authenticate(char *buf, char *passwd_file, char *salt, int salt_len) /* strcpy() should be OK, but use strncpy() to be extra careful */ strncpy(packet_username, buf, MAX_USER_PASSWD_LEN); - index = (char *) memchr(buf, '\0', MAX_USER_PASSWD_LEN) + 1; + index = (char *) memchr(buf, '\0', MAX_USER_PASSWD_LEN); if (index == NULL) { pool_debug("pcp_child: error while reading authentication packet"); return 0; } - strncpy(packet_password, index, MAX_USER_PASSWD_LEN); + strncpy(packet_password, ++index, MAX_USER_PASSWD_LEN); fp = fopen(passwd_file, "r"); if (fp == NULL) diff --git a/src/system_db/pool_system.c b/src/system_db/pool_system.c index a46a395d6..a23462e1a 100644 --- a/src/system_db/pool_system.c +++ b/src/system_db/pool_system.c @@ -205,7 +205,7 @@ int pool_memset_system_db_info (SystemDBInfo *info) else { info->dist_def_num = PQntuples(result); - if (info->dist_def_num != 0) + if (PQntuples(result) > 0) { dist_info = palloc(sizeof(DistDefInfo) * info->dist_def_num); } @@ -292,12 +292,11 @@ int pool_memset_system_db_info (SystemDBInfo *info) else { info->repli_def_num = PQntuples(result); - if (info->repli_def_num != 0) + if (PQntuples(result) > 0) { repli_info = palloc(sizeof(RepliDefInfo) * info->repli_def_num); } - info->repli_def_slot = repli_info; for (i = 0; i < PQntuples(result); ++i) diff --git a/src/utils/pool_relcache.c b/src/utils/pool_relcache.c index a9f8b2484..ae96edd9d 100644 --- a/src/utils/pool_relcache.c +++ b/src/utils/pool_relcache.c @@ -263,19 +263,7 @@ void *int_unregister_func(void *data) void *string_register_func(POOL_SELECT_RESULT *res) { - char *ret = NULL; - int i; - - if (res->numrows == 0) - return NULL; - - for (i = 0; i < res->numrows; i++) - { - ret = strdup(res->data[i]); - break; - } - - return (void *)ret; + return (res->numrows > 0) ? strdup(res->data[0]): NULL; } void *string_unregister_func(void *data) [parent: 1130920fbcfc]