From d17a8e45f5b677f55a152c23b25c4ab256ef1679 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 3 Jan 2015 09:58:43 +0100 Subject: [PATCH] openbsd: fix uv_exepath(smallbuf) UV_EINVAL error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Write as much of the path as possible to the output buffer. Before this commit, passing in a buffer that was too small to hold the result failed with a UV_EINVAL error. PR-URL: https://github.com/libuv/libuv/pull/104 Reviewed-By: Saúl Ibarra Corretgé --- src/unix/openbsd.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/unix/openbsd.c b/src/unix/openbsd.c index 97144bf1..3e7ae848 100644 --- a/src/unix/openbsd.c +++ b/src/unix/openbsd.c @@ -108,17 +108,19 @@ int uv_exepath(char* buffer, size_t* size) { } argsbuf_size *= 2U; } + if (argsbuf[0] == NULL) { err = -EINVAL; /* FIXME(bnoordhuis) More appropriate error. */ goto out; } + + *size -= 1; exepath_size = strlen(argsbuf[0]); - if (exepath_size >= *size) { - err = -EINVAL; - goto out; - } - memcpy(buffer, argsbuf[0], exepath_size + 1U); - *size = exepath_size; + if (*size > exepath_size) + *size = exepath_size; + + memcpy(buffer, argsbuf[0], *size); + buffer[*size] = '\0'; err = 0; out: