Avoid using the "access" function for security reasons as per its documentation. Also, check to ensure it is a file (and not something else) when we are looking for a file
Fixes trac:1272 This commit was SVN r19373. The following Trac tickets were found above: Ticket 1272 --> https://svn.open-mpi.org/trac/ompi/ticket/1272
Этот коммит содержится в:
родитель
43f8bcfe54
Коммит
04fe1e1875
@ -25,6 +25,9 @@
|
|||||||
#ifdef HAVE_SHLWAPI_H
|
#ifdef HAVE_SHLWAPI_H
|
||||||
#include <shlwapi.h>
|
#include <shlwapi.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_SYS_STAT_H
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "opal/util/path.h"
|
#include "opal/util/path.h"
|
||||||
#include "opal/util/os_path.h"
|
#include "opal/util/os_path.h"
|
||||||
@ -174,6 +177,7 @@ char *opal_path_findv(char *fname, int mode, char **envv, char *wrkdir)
|
|||||||
char *opal_path_access(char *fname, char *path, int mode)
|
char *opal_path_access(char *fname, char *path, int mode)
|
||||||
{
|
{
|
||||||
char *fullpath = NULL;
|
char *fullpath = NULL;
|
||||||
|
struct stat buf;
|
||||||
|
|
||||||
/* Allocate space for the full pathname. */
|
/* Allocate space for the full pathname. */
|
||||||
if (NULL == path) {
|
if (NULL == path) {
|
||||||
@ -184,14 +188,50 @@ char *opal_path_access(char *fname, char *path, int mode)
|
|||||||
if (NULL == fullpath)
|
if (NULL == fullpath)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Get status on the full path name to check for existance. Then
|
/* first check to see - is this a file or a directory? We
|
||||||
check the permissions. */
|
* only want files
|
||||||
|
*/
|
||||||
if (access(fullpath, mode)) {
|
if (0 != stat(fullpath, &buf)) {
|
||||||
|
/* couldn't stat the path - obviously, this also meets the
|
||||||
|
* existence check, if that was requested
|
||||||
|
*/
|
||||||
free(fullpath);
|
free(fullpath);
|
||||||
fullpath = NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(S_IFREG & buf.st_mode) &&
|
||||||
|
!(S_IFLNK & buf.st_mode)) {
|
||||||
|
/* this isn't a regular file or a symbolic link, so
|
||||||
|
* ignore it
|
||||||
|
*/
|
||||||
|
free(fullpath);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check the permissions */
|
||||||
|
if ((X_OK & mode) && !(S_IXUSR & buf.st_mode)) {
|
||||||
|
/* if they asked us to check executable permission,
|
||||||
|
* and that isn't set, then return NULL
|
||||||
|
*/
|
||||||
|
free(fullpath);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if ((R_OK & mode) && !(S_IRUSR & buf.st_mode)) {
|
||||||
|
/* if they asked us to check read permission,
|
||||||
|
* and that isn't set, then return NULL
|
||||||
|
*/
|
||||||
|
free(fullpath);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if ((W_OK & mode) && !(S_IWUSR & buf.st_mode)) {
|
||||||
|
/* if they asked us to check write permission,
|
||||||
|
* and that isn't set, then return NULL
|
||||||
|
*/
|
||||||
|
free(fullpath);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* must have met all criteria! */
|
||||||
return fullpath;
|
return fullpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user