This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Realpath gives a path when it probably should not.


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);
	
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]