Bernhard Reutner-Fischer wrote:
Hi all,

I'd like to do a maintenance 0.9.30.3 release soon (in a week or so).

If you have patches/fixes that should be backported from master then
please say so now (or push non-controversial fixes right to the branch).

Hi Bernhard,

It would be great if the "realpath-SUSv4-compliant" commit in master could be added also to 0_9_30 branch for upcoming 0.9.30.3 release.

Without that patch some QT applications build against uclibc give a segmentation fault at runtime (see [1]).

Some of the toolchain-maker packages i have tested (crosstool-NG, buildroot) are using 0.9.30 as default and the resulting toolchains have the problem i said building qt libs/apps.

The cherry-pick from master does *not* apply cleanly, so i have already adapt it to apply to current 0_9_30 branch (attached).

Please consider applying it for next 0.9.30.3.

[1] http://bugreports.qt.nokia.com/browse/QTBUG-8365

--
Regards,

Javier Viguera
Software Engineer

Digi International Spain, S.A.
http://www.digi.com
>From 2fd66611455c67dca5c5ffaa39c7ad0f3d1a68d4 Mon Sep 17 00:00:00 2001
From: Bernhard Reutner-Fischer <[email protected]>
Date: Sat, 14 Nov 2009 15:57:47 +0100
Subject: [PATCH] realpath: SUSv4 compliant

Signed-off-by: Mike Frysinger <[email protected]>
Signed-off-by: Bernhard Reutner-Fischer <[email protected]>
---
 include/stdlib.h       |   15 ++++++---------
 libc/stdlib/realpath.c |   22 ++++++++--------------
 2 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/include/stdlib.h b/include/stdlib.h
index cb42583..53640ed 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -630,17 +630,14 @@ extern char *canonicalize_file_name (__const char *__name)
      __THROW __nonnull ((1)) __wur;
 #endif
 
-#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
-/* Return the canonical absolute name of file NAME.  The last file name
-   component need not exist, and may be a symlink to a nonexistent file.
-   If RESOLVED is null, the result is malloc'd; otherwise, if the canonical
-   name is PATH_MAX chars or more, returns null with `errno' set to
-   ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, returns the
-   name in RESOLVED.  */
+/* Return the canonical absolute name of file NAME.  If RESOLVED is
+   null, the result is malloc'd; otherwise, if the canonical name is
+   PATH_MAX chars or more, returns null with `errno' set to
+   ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
+   returns the 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));
-#endif
+		       char *__restrict __resolved) __THROW __wur;
 
 
 /* Shorthand for type of comparison functions.  */
diff --git a/libc/stdlib/realpath.c b/libc/stdlib/realpath.c
index e9eabdf..f21a35b 100644
--- a/libc/stdlib/realpath.c
+++ b/libc/stdlib/realpath.c
@@ -41,19 +41,10 @@ libc_hidden_proto(getcwd)
 
 #define MAX_READLINKS 32
 
-#ifdef __STDC__
 char *realpath(const char *path, char got_path[])
-#else
-char *realpath(path, got_path)
-const char *path;
-char got_path[];
-#endif
 {
 	char copy_path[PATH_MAX];
-	/* use user supplied buffer directly - reduces stack usage */
-	/* char got_path[PATH_MAX]; */
-	char *max_path;
-	char *new_path;
+	char *max_path, *new_path, *allocated_path;
 	size_t path_len;
 	int readlinks = 0;
 #ifdef S_IFLNK
@@ -77,12 +68,13 @@ char got_path[];
 	/* 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;
+	allocated_path = got_path ? NULL : (got_path = malloc(PATH_MAX));
 	max_path = got_path + PATH_MAX - 2; /* points to last non-NUL char */
 	new_path = got_path;
 	if (*path != '/') {
 		/* If it's a relative pathname use getcwd for starters. */
 		if (!getcwd(new_path, PATH_MAX - 1))
-			return NULL;
+			goto err;
 		new_path += strlen(new_path);
 		if (new_path[-1] != '/')
 			*new_path++ = '/';
@@ -119,6 +111,8 @@ char got_path[];
 		while (*path != '\0' && *path != '/') {
 			if (new_path > max_path) {
 				__set_errno(ENAMETOOLONG);
+ err:
+				free(allocated_path);
 				return NULL;
 			}
 			*new_path++ = *path++;
@@ -127,7 +121,7 @@ char got_path[];
 		/* Protect against infinite loops. */
 		if (readlinks++ > MAX_READLINKS) {
 			__set_errno(ELOOP);
-			return NULL;
+			goto err;
 		}
 		path_len = strlen(path);
 		/* See if last (so far) pathname component is a symlink. */
@@ -138,13 +132,13 @@ char got_path[];
 			if (link_len < 0) {
 				/* EINVAL means the file exists but isn't a symlink. */
 				if (errno != EINVAL) {
-					return NULL;
+					goto err;
 				}
 			} else {
 				/* Safe sex check. */
 				if (path_len + link_len >= PATH_MAX - 2) {
 					__set_errno(ENAMETOOLONG);
-					return NULL;
+					goto err;
 				}
 				/* Note: readlink doesn't add the null byte. */
 				/* copy_path[link_len] = '\0'; - we don't need it too */
-- 
1.7.0

_______________________________________________
uClibc mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/uclibc

Reply via email to