From afb319215d4fc8939ab1ad5055959bc066a5a87e Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 2 Jan 2015 23:07:40 +0100 Subject: [PATCH] unix: make uv_exepath(size=0) return UV_EINVAL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the behavior of a call to uv_exepath() with a size argument of zero consistent with the Windows implementation where it returns UV_EINVAL. PR-URL: https://github.com/libuv/libuv/pull/104 Reviewed-By: Saúl Ibarra Corretgé --- src/unix/aix.c | 2 +- src/unix/darwin.c | 2 +- src/unix/freebsd.c | 2 +- src/unix/linux-core.c | 2 +- src/unix/netbsd.c | 2 +- src/unix/openbsd.c | 2 +- src/unix/sunos.c | 2 +- test/test-get-currentexe.c | 4 ++++ 8 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/unix/aix.c b/src/unix/aix.c index 349c2b558..0c5d1f4b5 100644 --- a/src/unix/aix.c +++ b/src/unix/aix.c @@ -294,7 +294,7 @@ int uv_exepath(char* buffer, size_t* size) { int fd; char **argv; - if ((buffer == NULL) || (size == NULL)) + if (buffer == NULL || size == NULL || *size == 0) return -EINVAL; snprintf(pp, sizeof(pp), "/proc/%lu/psinfo", (unsigned long) getpid()); diff --git a/src/unix/darwin.c b/src/unix/darwin.c index c9a45edee..69117d61e 100644 --- a/src/unix/darwin.c +++ b/src/unix/darwin.c @@ -70,7 +70,7 @@ int uv_exepath(char* buffer, size_t* size) { char* path; char* fullpath; - if (buffer == NULL || size == NULL) + if (buffer == NULL || size == NULL || *size == 0) return -EINVAL; usize = *size; diff --git a/src/unix/freebsd.c b/src/unix/freebsd.c index d59e3773a..55492adc4 100644 --- a/src/unix/freebsd.c +++ b/src/unix/freebsd.c @@ -78,7 +78,7 @@ int uv_exepath(char* buffer, size_t* size) { int mib[4]; size_t cb; - if (buffer == NULL || size == NULL) + if (buffer == NULL || size == NULL || *size == 0) return -EINVAL; #ifdef __DragonFly__ diff --git a/src/unix/linux-core.c b/src/unix/linux-core.c index 4ff1a8485..3452dadb6 100644 --- a/src/unix/linux-core.c +++ b/src/unix/linux-core.c @@ -378,7 +378,7 @@ void uv_loadavg(double avg[3]) { int uv_exepath(char* buffer, size_t* size) { ssize_t n; - if (buffer == NULL || size == NULL) + if (buffer == NULL || size == NULL || *size == 0) return -EINVAL; n = readlink("/proc/self/exe", buffer, *size - 1); diff --git a/src/unix/netbsd.c b/src/unix/netbsd.c index 5f1182f8b..de99d135f 100644 --- a/src/unix/netbsd.c +++ b/src/unix/netbsd.c @@ -83,7 +83,7 @@ int uv_exepath(char* buffer, size_t* size) { size_t cb; pid_t mypid; - if (buffer == NULL || size == NULL) + if (buffer == NULL || size == NULL || *size == 0) return -EINVAL; mypid = getpid(); diff --git a/src/unix/openbsd.c b/src/unix/openbsd.c index cde8d4d0c..97144bf1b 100644 --- a/src/unix/openbsd.c +++ b/src/unix/openbsd.c @@ -85,7 +85,7 @@ int uv_exepath(char* buffer, size_t* size) { pid_t mypid; int err; - if (buffer == NULL || size == NULL) + if (buffer == NULL || size == NULL || *size == 0) return -EINVAL; mypid = getpid(); diff --git a/src/unix/sunos.c b/src/unix/sunos.c index d6fb7f495..04a8cb496 100644 --- a/src/unix/sunos.c +++ b/src/unix/sunos.c @@ -300,7 +300,7 @@ int uv_exepath(char* buffer, size_t* size) { ssize_t res; char buf[128]; - if (buffer == NULL || size == NULL) + if (buffer == NULL || size == NULL || *size == 0) return -EINVAL; snprintf(buf, sizeof(buf), "/proc/%lu/path/a.out", (unsigned long) getpid()); diff --git a/test/test-get-currentexe.c b/test/test-get-currentexe.c index be578db75..b23991723 100644 --- a/test/test-get-currentexe.c +++ b/test/test-get-currentexe.c @@ -61,5 +61,9 @@ TEST_IMPL(get_currentexe) { r = uv_exepath(buffer, NULL); ASSERT(r == UV_EINVAL); + size = 0; + r = uv_exepath(buffer, &size); + ASSERT(r == UV_EINVAL); + return 0; }