sunos: preemptively fix uv_exepath(size=1)

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é <saghul@gmail.com>
This commit is contained in:
Ben Noordhuis 2015-01-03 10:07:03 +01:00
parent 555a9647a0
commit 1b0ac59179

View File

@ -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;