Skip to content

Commit

Permalink
programs/cp: Fix pointer cast warning
Browse files Browse the repository at this point in the history
execve() expects the args to be in writable memory, so copy them using
strdup(3).
  • Loading branch information
neverpanic committed Nov 18, 2024
1 parent a1b2727 commit ee3423d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/programs/cp/cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/errno.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
const char *cp_path = "/bin/cp";
const char *clone_arg = "-c";
const char **new_argv = malloc(sizeof(char *) * (argc+2));
if (new_argv) {
char *cp_path = strdup("/bin/cp");
char *clone_arg = strdup("-c");
char **new_argv = malloc(sizeof(char *) * (argc+2));
if (cp_path && clone_arg && new_argv) {
new_argv[0] = cp_path;
new_argv[1] = clone_arg;
for (int i = 1; i <= argc; i++) {
Expand Down

0 comments on commit ee3423d

Please sign in to comment.