From b49d6f7c30420d843a84c7afbe6c3498fbc3ac57 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 18 Jul 2012 00:22:06 +0200 Subject: [PATCH] unix: fix uv_set_process_title() Use strncpy() to set the process title, it pads the remainder with nul bytes. Avoids garbage output on systems where `ps aux` prints the entire proctitle buffer, not just the characters up to the first '\0'. Fixes joyent/node#3726. --- src/unix/proctitle.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/unix/proctitle.c b/src/unix/proctitle.c index 29099710..9057074a 100644 --- a/src/unix/proctitle.c +++ b/src/unix/proctitle.c @@ -81,7 +81,14 @@ char** uv_setup_args(int argc, char** argv) { uv_err_t uv_set_process_title(const char* title) { - uv_strlcpy(process_title.str, title, process_title.len); + /* proctitle doesn't need to be zero terminated, last char is always '\0'. + * Use strncpy(), it pads the remainder with nul bytes. Avoids garbage output + * on systems where `ps aux` prints the entire proctitle buffer, not just the + * characters up to the first '\0'. + */ + if (process_title.len > 0) + strncpy(process_title.str, title, process_title.len - 1); + return uv_ok_; }