fix: replace unsafe str fun and check return value

This commit is contained in:
Alex Duan 2024-10-28 16:12:18 +08:00
parent 90642f4dc2
commit 036b7ebefa
2 changed files with 105 additions and 94 deletions

View File

@ -1331,11 +1331,15 @@ void printScreen(TAOS* con, SShellCmd* cmd, SWords* match) {
if (word->end && str[strLen - 1] != ';') { if (word->end && str[strLen - 1] != ';') {
// append end ';' // append end ';'
char *p = taosMemoryMalloc(strLen + 8); char* p = taosMemoryCalloc(strLen + 8, 1);
strcpy(p, str); if (p) {
strcat(p, ";"); tstrncpy(p, str, strLen);
tstrncpy(p + strLen, ";", 1);
shellInsertStr(cmd, (char*)p, strLen + 1); shellInsertStr(cmd, (char*)p, strLen + 1);
taosMemoryFree(p); taosMemoryFree(p);
} else {
shellInsertStr(cmd, (char*)str, strLen);
}
} else { } else {
// insert new // insert new
shellInsertStr(cmd, (char*)str, strLen); shellInsertStr(cmd, (char*)str, strLen);

View File

@ -17,7 +17,6 @@
#include <iostream> #include <iostream>
#include "shellAuto.h" #include "shellAuto.h"
TEST(fieldOptionsArea, autoTabTest) { TEST(fieldOptionsArea, autoTabTest) {
printf("hellow world SHELL tab test\n"); printf("hellow world SHELL tab test\n");
@ -35,8 +34,10 @@ TEST(fieldOptionsArea, autoTabTest) {
"create table st( ts timestamp, age int, name binary(16)) tags( area int, addr", "create table st( ts timestamp, age int, name binary(16)) tags( area int, addr",
"create table st (ts timestamp , age int, name binary(16) , area int,", "create table st (ts timestamp , age int, name binary(16) , area int,",
"create table st (ts timestamp , age int, name binary(16) ) tags ( area int ,addr varbinary", "create table st (ts timestamp , age int, name binary(16) ) tags ( area int ,addr varbinary",
"create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level 'high' , no i", "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level "
"create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode 'simple8b' level 'high', no in", "'high' , no i",
"create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode "
"'simple8b' level 'high', no in",
}; };
// str true // str true
@ -54,7 +55,8 @@ TEST(fieldOptionsArea, autoTabTest) {
"create table st (ts timestamp , age int, name binary(16), area int,addr varbinary(32) ", "create table st (ts timestamp , age int, name binary(16), area int,addr varbinary(32) ",
"create table st (ts timestamp , age int, name binary(16), area int , addr varbinary(32) compress 'zlib' ", "create table st (ts timestamp , age int, name binary(16), area int , addr varbinary(32) compress 'zlib' ",
"create table st (ts timestamp , age int, name binary(16), area int , addr varbinary(32) level 'high' ", "create table st (ts timestamp , age int, name binary(16), area int , addr varbinary(32) level 'high' ",
"create table st (ts timestamp , age int, name binary(16) , area int , addr varbinary(32) encode 'simple8b' level 'high' ", "create table st (ts timestamp , age int, name binary(16) , area int , addr varbinary(32) encode 'simple8b' "
"level 'high' ",
}; };
// s0 is false // s0 is false
@ -87,8 +89,10 @@ TEST(isCreateFieldsArea, autoTabTest) {
"create table st( ts timestamp, age int, name binary(16)) tags( area int, addr int)", "create table st( ts timestamp, age int, name binary(16)) tags( area int, addr int)",
"create table st (ts timestamp , age int, name binary(16) ) tags ( area int,addr varbinary(32) )", "create table st (ts timestamp , age int, name binary(16) ) tags ( area int,addr varbinary(32) )",
"create table st (ts timestamp , age int, name binary(16) ) tags ( area int ,addr varbinary(14))", "create table st (ts timestamp , age int, name binary(16) ) tags ( area int ,addr varbinary(14))",
"create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level 'high' )", "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level "
"create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode 'simple8b' level 'high' ) ", "'high' )",
"create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode "
"'simple8b' level 'high' ) ",
}; };
// str true // str true
@ -104,9 +108,12 @@ TEST(isCreateFieldsArea, autoTabTest) {
"create table st(ts timestamp, age int, name binary(16)) tags(area int,addr varbinary(32) ", "create table st(ts timestamp, age int, name binary(16)) tags(area int,addr varbinary(32) ",
"create table st( ts timestamp, age int, name binary(16)) tags(area int,addr varbinary(32) ", "create table st( ts timestamp, age int, name binary(16)) tags(area int,addr varbinary(32) ",
"create table st (ts timestamp , age int, name binary(16) ) tags ( area int, addr varbinary(32) ", "create table st (ts timestamp , age int, name binary(16) ) tags ( area int, addr varbinary(32) ",
"create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) compress 'zlib' ", "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) compress "
"create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level 'high' ", "'zlib' ",
"create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode 'simple8b' level 'high' ", "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level "
"'high' ",
"create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode "
"'simple8b' level 'high' ",
}; };
// s0 is false // s0 is false