diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 978fc5b8ececc29e4cef8566da39437cc723b060..e7861201d3de7613e107de6bf062a1d13cd6a585 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -218,9 +218,9 @@ void *rpcOpen(const SRpcInit *pInit) { pRpc->localPort = pInit->localPort; pRpc->afp = pInit->afp; pRpc->sessions = pInit->sessions+1; - if (pInit->user) strcpy(pRpc->user, pInit->user); - if (pInit->secret) strcpy(pRpc->secret, pInit->secret); - if (pInit->ckey) strcpy(pRpc->ckey, pInit->ckey); + if (pInit->user) tstrncpy(pRpc->user, pInit->user, sizeof(pRpc->user)); + if (pInit->secret) memcpy(pRpc->secret, pInit->secret, sizeof(pRpc->secret)); + if (pInit->ckey) tstrncpy(pRpc->ckey, pInit->ckey, sizeof(pRpc->ckey)); pRpc->spi = pInit->spi; pRpc->cfp = pInit->cfp; pRpc->afp = pInit->afp; @@ -434,7 +434,8 @@ void rpcSendResponse(const SRpcMsg *pRsp) { } void rpcSendRedirectRsp(void *thandle, const SRpcIpSet *pIpSet) { - SRpcMsg rpcMsg; + SRpcMsg rpcMsg; + memset(&rpcMsg, 0, sizeof(rpcMsg)); rpcMsg.contLen = sizeof(SRpcIpSet); rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen); diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index defd277db1fe31a1732363326a399f217a2ed3cf..5dd5e4015e6b01339da7756c863ace9fb9ec00d8 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -253,12 +253,14 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void * if (pthread_mutex_init(&(pThreadObj->mutex), NULL) < 0) { tError("%s failed to init TCP client mutex(%s)", label, strerror(errno)); + free(pThreadObj); return NULL; } pThreadObj->pollFd = epoll_create(10); // size does not matter if (pThreadObj->pollFd < 0) { tError("%s failed to create TCP client epoll", label); + free(pThreadObj); return NULL; } @@ -269,6 +271,8 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void * int code = pthread_create(&(pThreadObj->thread), &thattr, taosProcessTcpData, (void *)(pThreadObj)); pthread_attr_destroy(&thattr); if (code != 0) { + close(pThreadObj->pollFd); + free(pThreadObj); tError("%s failed to create TCP read data thread(%s)", label, strerror(errno)); return NULL; } diff --git a/src/rpc/test/rclient.c b/src/rpc/test/rclient.c index ea1ebb5974691f9bd6a1244e6ad06de464d2b307..857b39dd82de949ae5ac6a98c48907cc578c1e93 100644 --- a/src/rpc/test/rclient.c +++ b/src/rpc/test/rclient.c @@ -14,6 +14,7 @@ */ #include "os.h" +#include "tutil.h" #include "tglobal.h" #include "rpcLog.h" #include "trpc.h" @@ -105,7 +106,7 @@ int main(int argc, char *argv[]) { if (strcmp(argv[i], "-p")==0 && i < argc-1) { ipSet.port[0] = atoi(argv[++i]); } else if (strcmp(argv[i], "-i") ==0 && i < argc-1) { - strcpy(ipSet.fqdn[0], argv[++i]); + tstrncpy(ipSet.fqdn[0], argv[++i], sizeof(ipSet.fqdn)); } else if (strcmp(argv[i], "-t")==0 && i < argc-1) { rpcInit.numOfThreads = atoi(argv[++i]); } else if (strcmp(argv[i], "-m")==0 && i < argc-1) { diff --git a/src/rpc/test/rsclient.c b/src/rpc/test/rsclient.c index 3b19d7a9ea5561e3641fbbbf2deae99c5794df87..6f367bc19ba6fc718a75a47a83b07e4a7a2f9547 100644 --- a/src/rpc/test/rsclient.c +++ b/src/rpc/test/rsclient.c @@ -15,6 +15,7 @@ #include "os.h" +#include "tutil.h" #include "tglobal.h" #include "rpcLog.h" #include "trpc.h" @@ -106,7 +107,7 @@ int main(int argc, char *argv[]) { if (strcmp(argv[i], "-p")==0 && i < argc-1) { ipSet.port[0] = atoi(argv[++i]); } else if (strcmp(argv[i], "-i") ==0 && i < argc-1) { - strcpy(ipSet.fqdn[0], argv[++i]); + tstrncpy(ipSet.fqdn[0], argv[++i], sizeof(ipSet.fqdn)); } else if (strcmp(argv[i], "-t")==0 && i < argc-1) { rpcInit.numOfThreads = atoi(argv[++i]); } else if (strcmp(argv[i], "-m")==0 && i < argc-1) { diff --git a/src/rpc/test/rserver.c b/src/rpc/test/rserver.c index 4ce6a0a8cf6bd4a920187f3483e54acf70dc7f09..71e7c62b9eabe371fa95306906fbf43bcbaab4ff 100644 --- a/src/rpc/test/rserver.c +++ b/src/rpc/test/rserver.c @@ -69,6 +69,7 @@ void processShellMsg() { taosGetQitem(qall, &type, (void **)&pRpcMsg); rpcFreeCont(pRpcMsg->pCont); + memset(&rpcMsg, 0, sizeof(rpcMsg)); rpcMsg.pCont = rpcMallocCont(msgSize); rpcMsg.contLen = msgSize; rpcMsg.handle = pRpcMsg->handle; diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index 984df2387957fdcc4f7255a85dbfc70b2f8ca250..1960dc2a2a33a2b775f0a2449407a792cdf4b64e 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -42,6 +42,11 @@ extern "C" { } \ } +#define tstrncpy(dst, src, size) do { \ + strncpy((dst), (src), (size)); \ + (dst)[(size) - 1] = 0; \ +} while (0); + #define tclose(x) taosCloseSocket(x) // Pointer p drift right by b bytes diff --git a/src/wal/test/waltest.c b/src/wal/test/waltest.c index cf9bf9542eb2ce71d8d0b4319bfe68faa0152429..073dbf72af02437dc494fdf18ceeebaa24777dca 100644 --- a/src/wal/test/waltest.c +++ b/src/wal/test/waltest.c @@ -15,6 +15,7 @@ //#define _DEFAULT_SOURCE #include "os.h" +#include "tutil.h" #include "tglobal.h" #include "tlog.h" #include "twal.h" @@ -45,7 +46,7 @@ int main(int argc, char *argv[]) { for (int i=1; i