Skip to content

Commit

Permalink
Merge pull request #1337 from stgraber/main
Browse files Browse the repository at this point in the history
shared/cgo: Don't use strlcpy
  • Loading branch information
hallyn authored Oct 25, 2024
2 parents 819de90 + d040099 commit 103b0ff
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 - 1);
dest[len-1] = '\0';
}

return ret;
}
Expand Down

0 comments on commit 103b0ff

Please sign in to comment.