From e504719e17f92bd789da9098bfd65065d223cc64 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 21 Feb 2012 13:26:42 +0100 Subject: [PATCH] linux: fix signedness issue in uv_exepath() readlink() returns -1 on error. The <= 0 check failed to catch that because the return value was implicitly cast to size_t, which is unsigned. --- src/unix/linux.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/unix/linux.c b/src/unix/linux.c index 8986eef9..f6e09fc6 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -171,13 +171,17 @@ void uv_loadavg(double avg[3]) { int uv_exepath(char* buffer, size_t* size) { + ssize_t n; + if (!buffer || !size) { return -1; } - *size = readlink("/proc/self/exe", buffer, *size - 1); - if (*size <= 0) return -1; - buffer[*size] = '\0'; + n = readlink("/proc/self/exe", buffer, *size - 1); + if (n <= 0) return -1; + buffer[n] = '\0'; + *size = n; + return 0; }