Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: avoid buffer overflow in proctitle.c
Browse files Browse the repository at this point in the history
Get/set process title with uv_strlcpy(), not strncpy(). The latter won't
zero-terminate the result if the destination buffer is too small.
  • Loading branch information
bnoordhuis committed Jul 13, 2012
1 parent dc97d44 commit a87abc7
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/unix/proctitle.c
Expand Up @@ -81,22 +81,12 @@ char** uv_setup_args(int argc, char** argv) {


uv_err_t uv_set_process_title(const char* title) {
/* No need to terminate, last char is always '\0'. */
if (process_title.len)
strncpy(process_title.str, title, process_title.len - 1);

uv_strlcpy(process_title.str, title, process_title.len);
return uv_ok_;
}


uv_err_t uv_get_process_title(char* buffer, size_t size) {
if (process_title.str) {
strncpy(buffer, process_title.str, size);
} else {
if (size > 0) {
buffer[0] = '\0';
}
}

uv_strlcpy(buffer, process_title.str ? process_title.str : "", size);
return uv_ok_;
}

0 comments on commit a87abc7

Please sign in to comment.