This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
[PATCH] Realpath gives a path when it probably should not.
- From: Ranjani Murthy <ranmur at gmail dot com>
- To: libc-alpha <libc-alpha at sources dot redhat dot com>
- Date: Mon, 25 Apr 2005 09:15:56 -0700
- Subject: [PATCH] Realpath gives a path when it probably should not.
- Reply-to: Ranjani Murthy <ranmur at gmail dot com>
Realpath gives a path to existing non directories. It gives a path
for pathnames like /tmp/file1.c/../../tmp/file2.c. Realpath should
return NULL and set errno to ENOTDIR in such a case. Attached is the
patch and a test case.
Ranjani
--- libc/stdlib/canonicalize.c.orig 2004-04-14 21:39:53 +0400
+++ libc/stdlib/canonicalize.c 2004-06-14 21:42:05 +0400
@@ -199,6 +199,11 @@ __realpath (const char *name, char *reso
if (dest > rpath + 1)
while ((--dest)[-1] != '/');
}
+ else if (!S_ISDIR (st.st_mode) && *end)
+ {
+ __set_errno (ENOTDIR);
+ goto error;
+ }
}
}
if (dest > rpath + 1 && dest[-1] == '/')
Test case to reproduce the problem.
Shell Script:
#!/bin/bash
touch /tmp/file1.c
touch /tmp/file2.c
Test File:
/* Test cases for realpath */
#include <stdlib.h>
#include <errno.h>
main()
{
char dest[50], *ret_value;
ret_value = realpath("/tmp/file1.c/../../tmp/file2.c ", dest);
printf("Path: /tmp/file1.c/../../tmp/file2.c, ");
printf("Dest: %s , Return Value: %s , Errno: %d\n", dest,
ret_value, errno);
}