pgpool2.git / summary / log / commit / refs

commit    24b4fa2c0bb1f4f44a12516c2b70276529bdb7fa
Author:   Tatsuo Ishii <ishii at sraoss.co.jp>
Date:     Sun Jan 17 08:19:14 2010 +0000

    Fix bind_rewrite_timestamp when used with paramFormats being specified
    and more than two parameters exist. Patch contributed by Akio Ishida.
    See [pgpool-general-jp: 670] for more details.


pool_timestamp.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/pool_timestamp.c b/pool_timestamp.c index 1ffbe80e4..c68970aa4 100644 --- a/pool_timestamp.c +++ b/pool_timestamp.c @@ -666,7 +666,8 @@ bind_rewrite_timestamp(POOL_CONNECTION_POOL *backend, Portal *portal, const char *orig_msg, int *len) { int16 tmp2, - num_params; + num_params, + num_formats; int32 tmp4; int i, ts_len, @@ -686,7 +687,7 @@ bind_rewrite_timestamp(POOL_CONNECTION_POOL *backend, Portal *portal, ts_len = strlen(ts); *len += (strlen(ts) + sizeof(int32)) * portal->num_tsparams; - new_msg = copy_to = (char *) malloc(*len); + new_msg = copy_to = (char *) malloc(*len + portal->num_tsparams * sizeof(int16)); copy_from = orig_msg; /* portal_name */ @@ -702,11 +703,30 @@ bind_rewrite_timestamp(POOL_CONNECTION_POOL *backend, Portal *portal, /* format code */ memcpy(&tmp2, copy_from, sizeof(int16)); copy_len = sizeof(int16); - tmp2 = ntohs(tmp2); - copy_len += tmp2 * sizeof(int16); + tmp2 = num_formats = ntohs(tmp2); + + if (num_formats > 1) + { + /* enlarge message length */ + *len += portal->num_tsparams * sizeof(int16); + tmp2 += portal->num_tsparams; + } + tmp2 = htons(tmp2); + memcpy(copy_to, &tmp2, copy_len); + copy_to += copy_len; copy_from += copy_len; + + copy_len = num_formats * sizeof(int16); + memcpy(copy_to, copy_from, copy_len); copy_to += copy_len; copy_from += copy_len; + if (num_formats > 1) + { + /* set format codes to zero(text) */ + memset(copy_to, 0, portal->num_tsparams * 2); + copy_to += sizeof(int16) * portal->num_tsparams; + } + /* num params */ memcpy(&tmp2, copy_from, sizeof(int16)); copy_len = sizeof(int16); [parent: 5dd396d448ce]