未验证 提交 da1959a1 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #2277 from taosdata/feature/query

[td-541] add string length overflow check.
...@@ -297,7 +297,7 @@ void *deleteTable(); ...@@ -297,7 +297,7 @@ void *deleteTable();
void *asyncWrite(void *sarg); void *asyncWrite(void *sarg);
void generateData(char *res, char **data_type, int num_of_cols, int64_t timestamp, int len_of_binary); int generateData(char *res, char **data_type, int num_of_cols, int64_t timestamp, int len_of_binary);
void rand_string(char *str, int size); void rand_string(char *str, int size);
...@@ -846,14 +846,19 @@ void *syncWrite(void *sarg) { ...@@ -846,14 +846,19 @@ void *syncWrite(void *sarg) {
int k; int k;
for (k = 0; k < winfo->nrecords_per_request;) { for (k = 0; k < winfo->nrecords_per_request;) {
int rand_num = rand() % 100; int rand_num = rand() % 100;
if (winfo->data_of_order ==1 && rand_num < winfo->data_of_rate) int len = -1;
{ if (winfo->data_of_order ==1 && rand_num < winfo->data_of_rate) {
long d = tmp_time - rand() % 1000000 + rand_num; long d = tmp_time - rand() % 1000000 + rand_num;
generateData(data, data_type, ncols_per_record, d, len_of_binary); len = generateData(data, data_type, ncols_per_record, d, len_of_binary);
} else } else {
{ len = generateData(data, data_type, ncols_per_record, tmp_time += 1000, len_of_binary);
generateData(data, data_type, ncols_per_record, tmp_time += 1000, len_of_binary);
} }
//assert(len + pstr - buffer < BUFFER_SIZE);
if (len + pstr - buffer >= BUFFER_SIZE) { // too long
break;
}
pstr += sprintf(pstr, " %s", data); pstr += sprintf(pstr, " %s", data);
inserted++; inserted++;
k++; k++;
...@@ -968,7 +973,7 @@ double getCurrentTime() { ...@@ -968,7 +973,7 @@ double getCurrentTime() {
return tv.tv_sec + tv.tv_usec / 1E6; return tv.tv_sec + tv.tv_usec / 1E6;
} }
void generateData(char *res, char **data_type, int num_of_cols, int64_t timestamp, int len_of_binary) { int32_t generateData(char *res, char **data_type, int num_of_cols, int64_t timestamp, int len_of_binary) {
memset(res, 0, MAX_DATA_SIZE); memset(res, 0, MAX_DATA_SIZE);
char *pstr = res; char *pstr = res;
pstr += sprintf(pstr, "(%" PRId64, timestamp); pstr += sprintf(pstr, "(%" PRId64, timestamp);
...@@ -1002,9 +1007,16 @@ void generateData(char *res, char **data_type, int num_of_cols, int64_t timestam ...@@ -1002,9 +1007,16 @@ void generateData(char *res, char **data_type, int num_of_cols, int64_t timestam
rand_string(s, len_of_binary); rand_string(s, len_of_binary);
pstr += sprintf(pstr, ", \"%s\"", s); pstr += sprintf(pstr, ", \"%s\"", s);
} }
if (pstr - res > MAX_DATA_SIZE) {
perror("column length too long, abort");
exit(-1);
}
} }
pstr += sprintf(pstr, ")"); pstr += sprintf(pstr, ")");
return pstr - res;
} }
static const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJK1234567890"; static const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJK1234567890";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册