فهرست منبع

libc/stdlib: canonicalize_file_name() memory leak

Uclibc's canonicalize_file_name() is allocating temprary buffer of 4kB
(PATH_MAX), and passing it to realpath() as second argument. Function is
not checking if realpath() fails and memory is lost.
Wojciech Nizinski 10 سال پیش
والد
کامیت
5178df3e15
1فایلهای تغییر یافته به همراه1 افزوده شده و 20 حذف شده
  1. 1 20
      libc/stdlib/canonicalize.c

+ 1 - 20
libc/stdlib/canonicalize.c

@@ -9,30 +9,11 @@
  */
 
 #include <stdlib.h>
-#include <limits.h>
 
 #ifdef __USE_GNU
 
-#ifndef PATH_MAX
-# ifdef _POSIX_VERSION
-#  define PATH_MAX _POSIX_PATH_MAX
-# else
-#  ifdef MAXPATHLEN
-#   define PATH_MAX MAXPATHLEN
-#  else
-#   define PATH_MAX 1024
-#  endif
-# endif
-#endif
-
 char * canonicalize_file_name (const char *name)
 {
-	char *buf = (char *) malloc(PATH_MAX);
-
-	if(unlikely(buf == NULL))
-		return NULL;
-
-	*buf='\0';
-	return realpath (name, buf);
+	return realpath (name, NULL);
 }
 #endif