From 1b0ac59179371e864231d94232bb55967eeefee2 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 3 Jan 2015 10:07:03 +0100 Subject: [PATCH] sunos: preemptively fix uv_exepath(size=1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I'm not 100% sure whether the behavior of readlink() with size=0 is well-defined on Solaris; it can return either 0 or fail with EINVAL. POSIX is not explicit about the mandated behavior. This commit adds a little caution and makes it skip the readlink() call when size=1 and simply writes the terminating zero byte. PR-URL: https://github.com/libuv/libuv/pull/104 Reviewed-By: Saúl Ibarra Corretgé --- src/unix/sunos.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/unix/sunos.c b/src/unix/sunos.c index 04a8cb49..ca183a62 100644 --- a/src/unix/sunos.c +++ b/src/unix/sunos.c @@ -304,7 +304,11 @@ int uv_exepath(char* buffer, size_t* size) { return -EINVAL; snprintf(buf, sizeof(buf), "/proc/%lu/path/a.out", (unsigned long) getpid()); - res = readlink(buf, buffer, *size - 1); + + res = *size - 1; + if (res > 0) + res = readlink(buf, buffer, res); + if (res == -1) return -errno;