Fix canonicalize_file_name_at(3) not handling file paths correctly.
This commit is contained in:
parent
6b8e389b47
commit
2161a0e0e3
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
|
||||||
|
|
||||||
This file is part of the Sortix C Library.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ extern "C" char* canonicalize_file_name_at(int dirfd, const char* path)
|
||||||
// The ideal case is if it's a directory (case 1). We follow symbolic
|
// The ideal case is if it's a directory (case 1). We follow symbolic
|
||||||
// links to directories as that's also okay (case 3).
|
// links to directories as that's also okay (case 3).
|
||||||
int fd = openat(dirfd, path, O_RDONLY | O_DIRECTORY);
|
int fd = openat(dirfd, path, O_RDONLY | O_DIRECTORY);
|
||||||
if ( fd )
|
if ( 0 <= fd )
|
||||||
{
|
{
|
||||||
char* ret = canonicalize_file_name_at(fd, NULL);
|
char* ret = canonicalize_file_name_at(fd, NULL);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -151,7 +151,8 @@ extern "C" char* canonicalize_file_name_at(int dirfd, const char* path)
|
||||||
|
|
||||||
if ( path )
|
if ( path )
|
||||||
{
|
{
|
||||||
if ( !(ret = (char*) malloc(sizeof(char) * (1 + strlen(path) + 1))) )
|
retlen = 1 + strlen(path);
|
||||||
|
if ( !(ret = (char*) malloc(sizeof(char) * (retlen + 1))) )
|
||||||
return NULL;
|
return NULL;
|
||||||
stpcpy(stpcpy(ret, "/"), path);
|
stpcpy(stpcpy(ret, "/"), path);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue