Merge pull request #12637 from taosdata/fix/invalid_read
fix: avoid invalid read/write
This commit is contained in:
commit
1c7df11df1
|
@ -213,8 +213,9 @@ int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valL
|
|||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(pVal, pRaw->pData + dataPos, valLen);
|
||||
if (pVal != NULL) {
|
||||
memcpy(pVal, pRaw->pData + dataPos, valLen);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -473,17 +473,16 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTempR
|
|||
|
||||
int32_t sz = 0;
|
||||
char* ch = (char*)fstSliceData(s, &sz);
|
||||
// char* tmp = taosMemoryCalloc(1, sz + 1);
|
||||
// memcpy(tmp, ch, sz);
|
||||
char* tmp = taosMemoryCalloc(1, sz + 1);
|
||||
memcpy(tmp, ch, sz);
|
||||
|
||||
if (0 != strncmp(ch, p, skip)) {
|
||||
if (0 != strncmp(tmp, p, skip)) {
|
||||
swsResultDestroy(rt);
|
||||
// taosMemoryFree(tmp);
|
||||
taosMemoryFree(tmp);
|
||||
break;
|
||||
}
|
||||
|
||||
TExeCond cond = cmpFn(ch + skip, tem->colVal, INDEX_TYPE_GET_TYPE(tem->colType));
|
||||
|
||||
TExeCond cond = cmpFn(tmp + skip, tem->colVal, INDEX_TYPE_GET_TYPE(tem->colType));
|
||||
if (MATCH == cond) {
|
||||
tfileReaderLoadTableIds((TFileReader*)reader, rt->out.out, tr->total);
|
||||
} else if (CONTINUE == cond) {
|
||||
|
@ -491,7 +490,7 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTempR
|
|||
swsResultDestroy(rt);
|
||||
break;
|
||||
}
|
||||
// taosMemoryFree(tmp);
|
||||
taosMemoryFree(tmp);
|
||||
swsResultDestroy(rt);
|
||||
}
|
||||
streamWithStateDestroy(st);
|
||||
|
|
|
@ -578,3 +578,40 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache_FLOAT) {
|
|||
EXPECT_EQ(1000, taosArrayGetSize(res));
|
||||
}
|
||||
}
|
||||
TEST_F(JsonEnv, testWriteJsonTfileAndCache_DOUBLE) {
|
||||
{
|
||||
double val = 10.0;
|
||||
std::string colName("test1");
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
WriteData(index, colName, TSDB_DATA_TYPE_DOUBLE, &val, sizeof(val), i);
|
||||
}
|
||||
}
|
||||
{
|
||||
double val = 2.0;
|
||||
std::string colName("test1");
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
WriteData(index, colName, TSDB_DATA_TYPE_DOUBLE, &val, sizeof(val), i + 1000);
|
||||
}
|
||||
}
|
||||
{
|
||||
SArray* res = NULL;
|
||||
std::string colName("test1");
|
||||
double val = 1.9;
|
||||
Search(index, colName, TSDB_DATA_TYPE_DOUBLE, &val, sizeof(val), QUERY_GREATER_EQUAL, &res);
|
||||
EXPECT_EQ(2000, taosArrayGetSize(res));
|
||||
}
|
||||
{
|
||||
SArray* res = NULL;
|
||||
std::string colName("test1");
|
||||
double val = 2.1;
|
||||
Search(index, colName, TSDB_DATA_TYPE_DOUBLE, &val, sizeof(val), QUERY_GREATER_EQUAL, &res);
|
||||
EXPECT_EQ(1000, taosArrayGetSize(res));
|
||||
}
|
||||
{
|
||||
std::string colName("test1");
|
||||
SArray* res = NULL;
|
||||
double val = 2.1;
|
||||
Search(index, colName, TSDB_DATA_TYPE_DOUBLE, &val, sizeof(val), QUERY_GREATER_EQUAL, &res);
|
||||
EXPECT_EQ(1000, taosArrayGetSize(res));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,9 +145,9 @@ static void cliWalkCb(uv_handle_t* handle, void* arg);
|
|||
} while (0)
|
||||
|
||||
#define CONN_HOST_THREAD_INDEX(conn) (conn ? ((SCliConn*)conn)->hThrdIdx : -1)
|
||||
#define CONN_PERSIST_TIME(para) (para * 1000 * 10)
|
||||
#define CONN_GET_HOST_THREAD(conn) (conn ? ((SCliConn*)conn)->hostThrd : NULL)
|
||||
#define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrdObj*)(conn)->hostThrd)->pTransInst))->label)
|
||||
#define CONN_PERSIST_TIME(para) (para * 1000 * 10)
|
||||
#define CONN_GET_HOST_THREAD(conn) (conn ? ((SCliConn*)conn)->hostThrd : NULL)
|
||||
#define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrdObj*)(conn)->hostThrd)->pTransInst))->label)
|
||||
#define CONN_SHOULD_RELEASE(conn, head) \
|
||||
do { \
|
||||
if ((head)->release == 1 && (head->msgLen) == sizeof(*head)) { \
|
||||
|
@ -227,7 +227,7 @@ static void cliWalkCb(uv_handle_t* handle, void* arg);
|
|||
#define REQUEST_PERSIS_HANDLE(msg) ((msg)->info.persistHandle == 1)
|
||||
#define REQUEST_RELEASE_HANDLE(cmsg) ((cmsg)->type == Release)
|
||||
|
||||
#define EPSET_GET_INUSE_IP(epSet) ((epSet)->eps[(epSet)->inUse].fqdn)
|
||||
#define EPSET_GET_INUSE_IP(epSet) ((epSet)->eps[(epSet)->inUse].fqdn)
|
||||
#define EPSET_GET_INUSE_PORT(epSet) ((epSet)->eps[(epSet)->inUse].port)
|
||||
|
||||
static void* cliWorkThread(void* arg);
|
||||
|
@ -924,8 +924,7 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
|
|||
arg->param1 = pMsg;
|
||||
arg->param2 = pThrd;
|
||||
transDQSched(pThrd->delayQueue, doDelayTask, arg, TRANS_RETRY_INTERVAL);
|
||||
|
||||
cliDestroy((uv_handle_t*)pConn->stream);
|
||||
cliDestroyConn(pConn, true);
|
||||
return -1;
|
||||
}
|
||||
} else if (pCtx->retryCount < TRANS_RETRY_COUNT_LIMIT) {
|
||||
|
|
Loading…
Reference in New Issue