Remove use of lstat

lstat is not available on some platforms (e.g. Ubuntu 16.04). In this
particular case stat is sufficient.

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
Dave Rodgman 2022-07-20 16:08:00 +01:00
parent c95cb6d6e5
commit fa40b02da3

View file

@ -1656,38 +1656,24 @@ cleanup:
ret = MBEDTLS_ERR_X509_BUFFER_TOO_SMALL; ret = MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
goto cleanup; goto cleanup;
} }
else else if( stat( entry_name, &sb ) == -1 )
{ {
/* Determine if the file entry could be a link. Using lstat(2) if( errno == ENOENT )
* is safer than just stat(2), otherwise a broken link will
* give us a false positive. */
if( lstat( entry_name, &sb ) == -1 )
{ {
/* Broken symbolic link - ignore this entry.
stat(2) will return this error for either (a) a dangling
symlink or (b) a missing file.
Given that we have just obtained the filename from readdir,
assume that it does exist and therefore treat this as a
dangling symlink. */
continue;
}
else
{
/* Some other file error; report the error. */
ret = MBEDTLS_ERR_X509_FILE_IO_ERROR; ret = MBEDTLS_ERR_X509_FILE_IO_ERROR;
goto cleanup; goto cleanup;
} }
/* If the file is a symbolic link, we need to validate the real
* information using stat(2). */
if( S_ISLNK( sb.st_mode ) )
{
/* If stat(2) fails it could be a broken link or a generic
* error. If the link is broken, ignore it, otherwise
* just set a MBEDTLS_ERR_X509_FILE_IO_ERROR. */
if( stat( entry_name, &sb ) == -1 )
{
if( errno == ENOENT )
{
/* Broken link - ignore this entry */
continue;
}
else
{
ret = MBEDTLS_ERR_X509_FILE_IO_ERROR;
goto cleanup;
}
}
}
} }
if( !S_ISREG( sb.st_mode ) ) if( !S_ISREG( sb.st_mode ) )