Skip to content

Commit

Permalink
use strncpy instead of memcpy when copying a string
Browse files Browse the repository at this point in the history
  • Loading branch information
HiGarfield committed Apr 29, 2024
1 parent 785803d commit 2013ec1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/process_iterator_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ static void pti2proc(struct proc_taskallinfo *ti, struct process *process)
if (ti->pbsd.pbi_name[0] != '\0')
{
process->max_cmd_len = MIN(sizeof(process->command), sizeof(ti->pbsd.pbi_name)) - 1;
memcpy(process->command, ti->pbsd.pbi_name, process->max_cmd_len + 1);
strncpy(process->command, ti->pbsd.pbi_name, process->max_cmd_len);
}
else
{
process->max_cmd_len = MIN(sizeof(process->command), sizeof(ti->pbsd.pbi_comm)) - 1;
memcpy(process->command, ti->pbsd.pbi_comm, process->max_cmd_len + 1);
strncpy(process->command, ti->pbsd.pbi_comm, process->max_cmd_len);
}
process->command[process->max_cmd_len] = '\0';
}

static int get_process_pti(pid_t pid, struct proc_taskallinfo *ti)
Expand Down

0 comments on commit 2013ec1

Please sign in to comment.