From f968c0403796b8e58035dba5dc4855687bbe112e Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 16 Sep 2016 12:19:44 +0200 Subject: [PATCH] a couple of PS bugs in ps_fetch_bin 1. Do not remove the last character from the blob (indeed, why C/C would corrupt the retrieved value?) 2. Always append a teminating '\0' if fetching into a string, also when nothing was fetched (blob length = 0) this fixes various test failures in --ps-protocol in the server --- libmariadb/ma_stmt_codec.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/libmariadb/ma_stmt_codec.c b/libmariadb/ma_stmt_codec.c index 4edfd9ac..eef37b8c 100644 --- a/libmariadb/ma_stmt_codec.c +++ b/libmariadb/ma_stmt_codec.c @@ -936,18 +936,12 @@ void ps_fetch_bin(MYSQL_BIND *r_param, { copylen= end - current_pos; if (r_param->buffer_length) - { memcpy(r_param->buffer, current_pos, MIN(copylen, r_param->buffer_length)); - if (copylen < r_param->buffer_length && - r_param->buffer_type == MYSQL_TYPE_STRING) - ((char *)r_param->buffer)[copylen]= 0; - } } + if (copylen < r_param->buffer_length && + r_param->buffer_type == MYSQL_TYPE_STRING) + ((char *)r_param->buffer)[copylen]= 0; *r_param->error= copylen > r_param->buffer_length; - /* don't count trailing zero if we fetch into string */ - if (r_param->buffer_type == MYSQL_TYPE_STRING && - !*r_param->error) - field_length--; (*row)+= field_length; } else