Merge pull request #15929 from taosdata/fix/ZhiqiangWang/TD-15311-fix-copy-appname-overflow
os: fix copy appname overflow
This commit is contained in:
commit
a34d0590e6
|
@ -16,6 +16,7 @@
|
||||||
#define ALLOW_FORBID_FUNC
|
#define ALLOW_FORBID_FUNC
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include "tdef.h"
|
||||||
#include "pthread.h"
|
#include "pthread.h"
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
@ -57,7 +58,7 @@ int32_t taosGetAppName(char* name, int32_t* len) {
|
||||||
end = filepath;
|
end = filepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(name, end);
|
tstrncpy(name, end, TSDB_APP_NAME_LEN);
|
||||||
|
|
||||||
if (len != NULL) {
|
if (len != NULL) {
|
||||||
*len = (int32_t)strlen(end);
|
*len = (int32_t)strlen(end);
|
||||||
|
@ -625,7 +626,7 @@ int32_t taosGetAppName(char *name, int32_t *len) {
|
||||||
buf[PATH_MAX] = '\0';
|
buf[PATH_MAX] = '\0';
|
||||||
size_t n = strlen(buf);
|
size_t n = strlen(buf);
|
||||||
if (len) *len = n;
|
if (len) *len = n;
|
||||||
if (name) strcpy(name, buf);
|
if (name) tstrncpy(name, buf, TSDB_APP_NAME_LEN);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -668,7 +669,7 @@ int32_t taosGetAppName(char* name, int32_t* len) {
|
||||||
|
|
||||||
++end;
|
++end;
|
||||||
|
|
||||||
strcpy(name, end);
|
tstrncpy(name, end, TSDB_APP_NAME_LEN);
|
||||||
|
|
||||||
if (len != NULL) {
|
if (len != NULL) {
|
||||||
*len = strlen(name);
|
*len = strlen(name);
|
||||||
|
|
Loading…
Reference in New Issue