From 0960fb0ecdc4c5162130dc22e38ab0e32dfe565f Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Tue, 10 Feb 2009 12:08:34 +0000 Subject: [PATCH] fix realpath NULL buffer self-allocation --- include/stdlib.h | 2 +- libc/stdlib/realpath.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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; -- 2.39.5