From 7b9aff6ee6ccec70ef232619cd1bd099cadf115d Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Fri, 16 Jul 2021 20:30:15 +0800 Subject: [PATCH] [TD-5333]: taosdemo normal table binary overflow. (#6889) --- src/kit/taosdemo/taosdemo.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index b751446892..9e8526bfe4 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -4983,12 +4983,20 @@ static int64_t generateData(char *recBuf, char **data_type, bool b = rand_bool() & 1; pstr += sprintf(pstr, ",%s", b ? "true" : "false"); } else if (strcasecmp(data_type[i % columnCount], "BINARY") == 0) { - char *s = malloc(lenOfBinary); + char *s = malloc(lenOfBinary + 1); + if (s == NULL) { + errorPrint("%s() LN%d, memory allocation %d bytes failed\n", + __func__, __LINE__, lenOfBinary + 1); + } rand_string(s, lenOfBinary); pstr += sprintf(pstr, ",\"%s\"", s); free(s); } else if (strcasecmp(data_type[i % columnCount], "NCHAR") == 0) { - char *s = malloc(lenOfBinary); + char *s = malloc(lenOfBinary + 1); + if (s == NULL) { + errorPrint("%s() LN%d, memory allocation %d bytes failed\n", + __func__, __LINE__, lenOfBinary + 1); + } rand_string(s, lenOfBinary); pstr += sprintf(pstr, ",\"%s\"", s); free(s); -- GitLab