From: Vincent Hanquez Date: Tue, 10 Feb 2009 12:08:34 +0000 (+0000) Subject: fix realpath NULL buffer self-allocation X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=xenclient%2Fuclibc.git fix realpath NULL buffer self-allocation --- diff --git a/include/stdlib.h b/include/stdlib.h index b87dfd9..9b112d8 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -637,7 +637,7 @@ extern char *canonicalize_file_name (__const char *__name) name in RESOLVED. */ /* we choose to handle __resolved==NULL as crash :) */ extern char *realpath (__const char *__restrict __name, - char *__restrict __resolved) __THROW __wur __nonnull((2)); + char *__restrict __resolved) __THROW __wur; #endif diff --git a/libc/stdlib/realpath.c b/libc/stdlib/realpath.c index e9eabdf..fe8fdd6 100644 --- a/libc/stdlib/realpath.c +++ b/libc/stdlib/realpath.c @@ -74,6 +74,15 @@ char got_path[]; __set_errno(ENAMETOOLONG); return NULL; } + + if (!got_path) { + got_path = malloc(PATH_MAX); + if (!got_path) { + __set_errno(ENOMEM); + return NULL; + } + } + /* Copy so that path is at the end of copy_path[] */ strcpy(copy_path + (PATH_MAX-1) - path_len, path); path = copy_path + (PATH_MAX-1) - path_len;