--- old/src/os/posix/vm/os_posix.cpp 2017-03-14 12:10:20.382868000 +0100 +++ new/src/os/posix/vm/os_posix.cpp 2017-03-14 12:10:19.841840000 +0100 @@ -1107,6 +1107,12 @@ char* os::Posix::realpath(const char* filename, char* outbuf, size_t outbuflen) { + if (filename == NULL || outbuf == 0 || outbuflen < 1) { + assert(false, "os::Posix::realpath: invalid arguments."); + errno = EINVAL; + return NULL; + } + char* result = NULL; // This assumes platform realpath() is implemented according to POSIX.1-2008. @@ -1118,21 +1124,20 @@ strcpy(outbuf, p); result = outbuf; } else { - errno = EINVAL; + errno = ENAMETOOLONG; } ::free(p); // *not* os::free } else { // Fallback for platforms struggling with modern Posix standards (AIX 5.3, 6.1). If realpath // returns EINVAL, this may indicate that realpath is not POSIX.1-2008 compatible and - // that it complains about the NULL we did hand down as user buffer (unless filename - // was NULL, in which case it may have been complaining about that). + // that it complains about the NULL we did hand down as user buffer. // In this case, use the user provided buffer but at least check whether realpath caused // a memory overwriter. - if (errno == EINVAL && filename != NULL) { + if (errno == EINVAL) { + outbuf[outbuflen - 1] = '\0'; p = ::realpath(filename, outbuf); if (p != NULL) { - assert(p == outbuf, "Unexpected.."); - guarantee(strlen(p) < outbuflen, "realpath buffer overwriter detected."); + guarantee(outbuf[outbuflen - 1] == '\0', "realpath buffer overwriter detected."); result = p; } }