Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
linux: fix signedness issue in uv_exepath()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bnoordhuis committed Feb 21, 2012
1 parent 75ab1ba commit e504719
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/unix/linux.c
Expand Up @@ -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;
}

Expand Down

0 comments on commit e504719

Please sign in to comment.