mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-07-19 01:40:17 +00:00
tools: acrn-manager: remove usage of banned APIs
1, replace strlen with strnlen 2, Return value check for strncpy function Tracked-On: #1254 Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com> Acked-by: Yan, Like <like.yan@intel.com> Reviewed-by: Yonghua Huang <yonghua.huang@intel.com> Reviewed-by: Kaige Fu <kaige.fu@intel.com>
This commit is contained in:
parent
af760f8dce
commit
b12c7b741b
@ -92,6 +92,7 @@ static int check_name(const char *name)
|
|||||||
|
|
||||||
static const char *acrnctl_bin_path;
|
static const char *acrnctl_bin_path;
|
||||||
static int find_acrn_dm;
|
static int find_acrn_dm;
|
||||||
|
#define MAX_WORD 64
|
||||||
|
|
||||||
static int write_tmp_file(int fd, int n, char *word[])
|
static int write_tmp_file(int fd, int n, char *word[])
|
||||||
{
|
{
|
||||||
@ -101,7 +102,7 @@ static int write_tmp_file(int fd, int n, char *word[])
|
|||||||
if (!n)
|
if (!n)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
len = strlen(word[0]);
|
len = strnlen(word[0], MAX_WORD);
|
||||||
if (len >= strlen("acrn-dm")) {
|
if (len >= strlen("acrn-dm")) {
|
||||||
if (!strcmp(word[0] + len - strlen("acrn-dm"), "acrn-dm")) {
|
if (!strcmp(word[0] + len - strlen("acrn-dm"), "acrn-dm")) {
|
||||||
find_acrn_dm++;
|
find_acrn_dm++;
|
||||||
@ -111,7 +112,7 @@ static int write_tmp_file(int fd, int n, char *word[])
|
|||||||
printf("ERROR: acrnctl bin path is truncated\n");
|
printf("ERROR: acrnctl bin path is truncated\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = write(fd, buf, strlen(buf));
|
ret = write(fd, buf, strnlen(buf, sizeof(buf)));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
return -1;
|
||||||
i++;
|
i++;
|
||||||
@ -123,7 +124,7 @@ static int write_tmp_file(int fd, int n, char *word[])
|
|||||||
if (snprintf(buf, sizeof(buf), " %s", word[i]) >= sizeof(buf))
|
if (snprintf(buf, sizeof(buf), " %s", word[i]) >= sizeof(buf))
|
||||||
printf("WARN: buf is truncated\n");
|
printf("WARN: buf is truncated\n");
|
||||||
i++;
|
i++;
|
||||||
ret = write(fd, buf, strlen(buf));
|
ret = write(fd, buf, strnlen(buf, sizeof(buf)));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -134,7 +135,6 @@ static int write_tmp_file(int fd, int n, char *word[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_FILE_SIZE (4096 * 4)
|
#define MAX_FILE_SIZE (4096 * 4)
|
||||||
#define MAX_WORD 64
|
|
||||||
#define FILE_NAME_LENGTH 128
|
#define FILE_NAME_LENGTH 128
|
||||||
|
|
||||||
#define TMP_FILE_SUFFIX ".acrnctl"
|
#define TMP_FILE_SUFFIX ".acrnctl"
|
||||||
@ -155,7 +155,7 @@ static int acrnctl_do_add(int argc, char *argv[])
|
|||||||
char vmname[128];
|
char vmname[128];
|
||||||
size_t len = sizeof(cmd_out);
|
size_t len = sizeof(cmd_out);
|
||||||
|
|
||||||
if (strlen(argv[1]) >= FILE_NAME_LENGTH) {
|
if (strnlen(argv[1], FILE_NAME_LENGTH) == FILE_NAME_LENGTH) {
|
||||||
printf("file name too long: %s\n", argv[1]);
|
printf("file name too long: %s\n", argv[1]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -347,6 +347,10 @@ static void handle_timer_req(struct mngr_msg *msg, int client_fd, void *param)
|
|||||||
}
|
}
|
||||||
|
|
||||||
strncpy(arg.name, msg->data.acrnd_timer.name, sizeof(arg.name) - 1);
|
strncpy(arg.name, msg->data.acrnd_timer.name, sizeof(arg.name) - 1);
|
||||||
|
if (sizeof(arg.name) - 1 < strnlen(msg->data.acrnd_timer.name, VMNAME_LEN)) {
|
||||||
|
perror("timer name was truncated\n");
|
||||||
|
goto reply_ack;
|
||||||
|
}
|
||||||
|
|
||||||
if (acrnd_add_work(acrnd_vm_timer_func, &arg, msg->data.acrnd_timer.t)) {
|
if (acrnd_add_work(acrnd_vm_timer_func, &arg, msg->data.acrnd_timer.t)) {
|
||||||
pdebug();
|
pdebug();
|
||||||
|
Loading…
Reference in New Issue
Block a user