Skip to content

Commit

Permalink
shared/cgo: Don't use strlcpy
Browse files Browse the repository at this point in the history
Closes lxc#1336

Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Oct 25, 2024
1 parent 819de90 commit e0bec12
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions shared/cgo/process_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,6 @@ static inline int push_vargs(char ***list, char *entry)
return 0;
}

static inline size_t strlcpy(char *dest, const char *src, size_t size)
{
size_t ret = strlen(src);

if (size) {
size_t len = (ret >= size) ? size - 1 : ret;
memcpy(dest, src, len);
dest[len] = '\0';
}

return ret;
}

/*
* Sets the process title to the specified title. Note that this may fail if
* the kernel doesn't support PR_SET_MM_MAP (kernels <3.18).
Expand Down Expand Up @@ -231,8 +218,11 @@ static inline int setproctitle(char *title)

ret = prctl(PR_SET_MM, prctl_arg(PR_SET_MM_MAP), prctl_arg(&prctl_map),
prctl_arg(sizeof(prctl_map)), prctl_arg(0));
if (ret == 0)
(void)strlcpy((char *)arg_start, title, len);
if (ret == 0) {
char *dest = (char *)arg_start;
memcpy(dest, title, len);
dest[len] = '\0';
}

return ret;
}
Expand Down

0 comments on commit e0bec12

Please sign in to comment.