pgpool2.git / summary / log / commit / refs
commit 1130920fbcfc1a904efe2391ea998ff3c7d16e16
Author: Muhammad Usama <m.usama@gmail.com>
Date: Tue Jul 15 12:30:33 2014 +0000
Fix coverity issue:1111387 Explicit null dereferenced
Fix coverity issue:1111388 Explicit null dereferenced
Fix coverity issue:1111411 Missing break in switch
Fix coverity issue:1111412 Missing break in switch
Fix coverity issue:1111450 Resource leak
Fix coverity issue:1111451 Resource leak
Fix coverity issue:1111472 Dereference before null check
Fix coverity issue:1111473 Dereference before null check
Fix coverity issue:1111474 Dereference before null check
Fix coverity issue:1111475 Wrong sizeof argument
Fix coverity issue:1111495 Use after free
Fix coverity issue:1111496 Use after free
Fix coverity issue:1222989 Bad bit shift operation
Fix coverity issue:1222990 Bad bit shift operation
Fix coverity issue:1222994 Explicit null dereferenced
Fix coverity issue:1222995 Printf format string issue
The commit also contains a tiny fix for compiler warning of missing prototype
for ExceptionalCondition() function.
src/include/pool_type.h | 6 +++++-
src/parallel_query/pool_rewrite_outfuncs.c | 10 +++++-----
src/parser/outfuncs.c | 1 +
src/parser/pool_string.c | 12 +++---------
src/protocol/pool_connection_pool.c | 2 +-
src/protocol/pool_process_query.c | 6 +++---
src/protocol/pool_proto2.c | 21 ++++++++++++++++-----
src/protocol/pool_proto_modules.c | 6 ++++--
src/rewrite/pool_timestamp.c | 12 ++++--------
src/utils/error/elog.c | 5 ++---
src/utils/pool_relcache.c | 6 ++++--
11 files changed, 48 insertions(+), 39 deletions(-)
diff --git a/src/include/pool_type.h b/src/include/pool_type.h
index 1159d2b8a..f0691bb01 100644
--- a/src/include/pool_type.h
+++ b/src/include/pool_type.h
@@ -6,7 +6,7 @@
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
- * Copyright (c) 2003-2011 PgPool Global Development Group
+ * Copyright (c) 2003-2014 PgPool Global Development Group
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
@@ -88,6 +88,10 @@ typedef struct {
} BackendStatusRecord;
extern int assert_enabled;
+extern void ExceptionalCondition(const char *conditionName,
+ const char *errorType,
+ const char *fileName, int lineNumber) __attribute__((noreturn));
+
#define MAXIMUM_ALIGNOF 8
#define TYPEALIGN(ALIGNVAL,LEN) \
diff --git a/src/parallel_query/pool_rewrite_outfuncs.c b/src/parallel_query/pool_rewrite_outfuncs.c
index 231a10e14..9d9376388 100644
--- a/src/parallel_query/pool_rewrite_outfuncs.c
+++ b/src/parallel_query/pool_rewrite_outfuncs.c
@@ -3934,12 +3934,10 @@ FuncChangebyAggregate(AnalyzeSelect *analyze, FuncCall *fnode)
free_string(sortfunc);
return i;
} else {
- if(having)
- free_string(having);
+ free_string(having);
}
}
- if(sortfunc)
- free_string(sortfunc);
+ free_string(sortfunc);
}
return -1;
}
@@ -8322,6 +8320,7 @@ _rewriteCommentStmt(Node *BaseSelect, RewriteQuery *message, ConInfoTodblink *db
snprintf(buf, 16, "%ld", v->val.ival);
delay_string_append_char(message, str, buf);
}
+ break;
case OBJECT_CAST:
delay_string_append_char(message, str, "CAST (");
@@ -8387,6 +8386,7 @@ _rewriteCommentStmt(Node *BaseSelect, RewriteQuery *message, ConInfoTodblink *db
static void
_rewriteRangeSubselect(Node *BaseSelect, RewriteQuery *message, ConInfoTodblink *dblink, String *str, RangeSubselect *node)
{
+ Assert(node && node->alias);
int last = message->current_select;
Alias *alias = node->alias;
char *table_name = alias->aliasname;
@@ -8412,7 +8412,7 @@ _rewriteRangeSubselect(Node *BaseSelect, RewriteQuery *message, ConInfoTodblink
AnalyzeSelect *analyze;
analyze=message->analyze[sub_no];
- if(node->alias && node->alias->colnames)
+ if(node->alias->colnames)
{
ListCell *lc;
int num = list_length(node->alias->colnames);
diff --git a/src/parser/outfuncs.c b/src/parser/outfuncs.c
index 58abe2c42..ed6a26985 100644
--- a/src/parser/outfuncs.c
+++ b/src/parser/outfuncs.c
@@ -4811,6 +4811,7 @@ _outCommentStmt(String *str, CommentStmt *node)
snprintf(buf, 16, "%ld", v->val.ival);
string_append_char(str, buf);
}
+ break;
case OBJECT_CAST:
string_append_char(str, "CAST (");
diff --git a/src/parser/pool_string.c b/src/parser/pool_string.c
index 114eb3af0..427f12c7d 100644
--- a/src/parser/pool_string.c
+++ b/src/parser/pool_string.c
@@ -32,22 +32,16 @@ String *init_string(char *str)
String *string = palloc(sizeof(String));
int size;
+ string->len = (str != NULL)? strlen(str): 0;
- size = (strlen(str) + 1) / STRING_SIZE + 1;
+ size = (string->len + 1) / STRING_SIZE + 1;
string->size = size;
string->data = palloc(STRING_SIZE * size);
memset(string->data, 0, STRING_SIZE * size);
- if (str == NULL)
- {
- string->len = 0;
- }
- else
- {
- string->len = strlen(str);
+ if (str != NULL)
memcpy(string->data, str, string->len);
- }
return string;
}
diff --git a/src/protocol/pool_connection_pool.c b/src/protocol/pool_connection_pool.c
index 62a350365..347b0816e 100644
--- a/src/protocol/pool_connection_pool.c
+++ b/src/protocol/pool_connection_pool.c
@@ -165,7 +165,7 @@ POOL_CONNECTION_POOL *pool_get_cp(char *user, char *database, int protoMajor, in
pfree(CONNECTION_SLOT(connection_pool, j));
}
info = connection_pool->info;
- memset(connection_pool, 0, sizeof(POOL_CONNECTION_POOL_SLOT));
+ memset(connection_pool, 0, sizeof(POOL_CONNECTION_POOL));
connection_pool->info = info;
memset(connection_pool->info, 0, sizeof(ConnectionInfo) * MAX_NUM_BACKENDS);
POOL_SETMASK(&oldmask);
diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c
index a095d3724..7520f50ff 100644
--- a/src/protocol/pool_process_query.c
+++ b/src/protocol/pool_process_query.c
@@ -385,7 +385,7 @@ POOL_STATUS pool_process_query(POOL_CONNECTION *frontend,
/* used only in pool_parallel_exec */
#define BITS (8 * sizeof(long int))
-static void set_fd(unsigned long fd ,unsigned long *setp)
+static void set_fd(int fd ,unsigned long *setp)
{
unsigned long tmp = fd / FD_SETSIZE;
unsigned long rem = fd % FD_SETSIZE;
@@ -393,7 +393,7 @@ static void set_fd(unsigned long fd ,unsigned long *setp)
}
/* used only in pool_parallel_exec */
-static int isset_fd(unsigned long fd, unsigned long *setp)
+static int isset_fd(int fd, unsigned long *setp)
{
unsigned long tmp = fd / FD_SETSIZE;
unsigned long rem = fd % FD_SETSIZE;
@@ -4391,7 +4391,7 @@ int pool_extract_error_message(bool read_kind, POOL_CONNECTION *backend, int maj
pfree(str_buf);
ereport(ERROR,
(errmsg("unable to extract error message"),
- errdetail("invalid message kind \"%C\"",kind)));
+ errdetail("invalid message kind \"%c\"",kind)));
}
}
diff --git a/src/protocol/pool_proto2.c b/src/protocol/pool_proto2.c
index e69ac936f..beea7dc7f 100644
--- a/src/protocol/pool_proto2.c
+++ b/src/protocol/pool_proto2.c
@@ -374,7 +374,7 @@ POOL_STATUS EmptyQueryResponse(POOL_CONNECTION *frontend,
POOL_STATUS ErrorResponse(POOL_CONNECTION *frontend,
POOL_CONNECTION_POOL *backend)
{
- char *string = NULL;
+ char *string = "";
int len = 0;
int i;
POOL_STATUS ret = POOL_CONTINUE;
@@ -389,7 +389,6 @@ POOL_STATUS ErrorResponse(POOL_CONNECTION *frontend,
return POOL_END;
}
}
-
/* forward to the frontend */
pool_write(frontend, "E", 1);
pool_write_and_flush(frontend, string, len);
@@ -419,7 +418,7 @@ POOL_STATUS FunctionResultResponse(POOL_CONNECTION *frontend,
{
char dummy;
int len;
- char *result = 0;
+ char *result = NULL;
int i;
pool_write(frontend, "V", 1);
@@ -460,7 +459,13 @@ POOL_STATUS FunctionResultResponse(POOL_CONNECTION *frontend,
errdetail("reading from backend node %d failed",i)));
}
}
- pool_write(frontend, result, len);
+ if(result)
+ pool_write(frontend, result, len);
+ else
+ ereport(FATAL,
+ (return_code(2),
+ errmsg("unable to process function result response"),
+ errdetail("reading from backend node failed")));
}
for (i=0;i<NUM_BACKENDS;i++)
@@ -499,7 +504,13 @@ POOL_STATUS NoticeResponse(POOL_CONNECTION *frontend,
/* forward to the frontend */
pool_write(frontend, "N", 1);
- return pool_write_and_flush(frontend, string, len);
+ if (string == NULL)
+ ereport(FATAL,
+ (return_code(2),
+ errmsg("unable to process Notice response"),
+ errdetail("reading from backend node failed")));
+ else
+ return pool_write_and_flush(frontend, string, len);
}
POOL_STATUS NotificationResponse(POOL_CONNECTION *frontend,
diff --git a/src/protocol/pool_proto_modules.c b/src/protocol/pool_proto_modules.c
index b272c425a..935a92321 100644
--- a/src/protocol/pool_proto_modules.c
+++ b/src/protocol/pool_proto_modules.c
@@ -1098,7 +1098,7 @@ POOL_STATUS Bind(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend,
{
char *pstmt_name;
char *portal_name;
- char *rewrite_msg;
+ char *rewrite_msg = NULL;
POOL_SENT_MESSAGE *parse_msg;
POOL_SENT_MESSAGE *bind_msg;
POOL_SESSION_CONTEXT *session_context;
@@ -1195,7 +1195,9 @@ POOL_STATUS Bind(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend,
pool_extended_send_and_wait(query_context, "B", len, contents, 1, MASTER_NODE_ID);
pool_extended_send_and_wait(query_context, "B", len, contents, -1, MASTER_NODE_ID);
-
+
+ if(rewrite_msg)
+ pfree(rewrite_msg);
return POOL_CONTINUE;
}
diff --git a/src/rewrite/pool_timestamp.c b/src/rewrite/pool_timestamp.c
index aa99fc8c8..cf2ef33a7 100644
--- a/src/rewrite/pool_timestamp.c
+++ b/src/rewrite/pool_timestamp.c
@@ -30,7 +30,6 @@
#include "pool_config.h"
#include "parser/parsenodes.h"
#include "parser/parser.h"
-//#include "parser/pool_memory.h"
#include "utils/palloc.h"
typedef struct {
@@ -112,12 +111,9 @@ static void *
ts_unregister_func(void *data)
{
TSRel *rel = (TSRel *) data;
-
- if (rel == NULL)
- return NULL;
-
- free(rel);
- return rel;
+ if (rel)
+ free(rel);
+ return (void *)0;
}
@@ -778,7 +774,7 @@ bind_rewrite_timestamp(POOL_CONNECTION_POOL *backend,
*len += (ts_len + sizeof(int32)) * message->num_tsparams;
/* allocate extra memory for parameter formats */
num_org_params = message->query_context->num_original_params;
- new_msg = copy_to = (char *) malloc(*len + sizeof(int16) * (message->num_tsparams + num_org_params));
+ new_msg = copy_to = (char *) palloc(*len + sizeof(int16) * (message->num_tsparams + num_org_params));
copy_from = orig_msg;
/* portal_name */
diff --git a/src/utils/error/elog.c b/src/utils/error/elog.c
index 956a7ef63..c83f6b5be 100644
--- a/src/utils/error/elog.c
+++ b/src/utils/error/elog.c
@@ -1345,9 +1345,8 @@ pg_re_throw(void)
}
/* Doesn't return ... */
- fprintf(stderr,"pg_re_throw tried to return %s %d\n",
- __FILE__, __LINE__);
-}
+ ExceptionalCondition("pg_re_throw tried to return", "FailedAssertion",
+ __FILE__, __LINE__);}
/*
diff --git a/src/utils/pool_relcache.c b/src/utils/pool_relcache.c
index 925a73c90..a9f8b2484 100644
--- a/src/utils/pool_relcache.c
+++ b/src/utils/pool_relcache.c
@@ -116,6 +116,7 @@ void *pool_search_relcache(POOL_RELCACHE *relcache, POOL_CONNECTION_POOL *backen
if (local_session_id < 0)
{
pool_error("pool_search_relcache: pool_get_local_session_id failed");
+ free(rel);
return NULL;
}
@@ -279,6 +280,7 @@ void *string_register_func(POOL_SELECT_RESULT *res)
void *string_unregister_func(void *data)
{
- free(data);
- return data;
+ if(data)
+ free(data);
+ return (void *)0;
}
[parent: a714980071bf]