mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
Bug 534105: Only files are allowed to be executed
When searching the PATH environment variable, only accept resources of type "file" and that are executable. Any directories on the PATH is silently ignored by shells and so should also CDT do. Change-Id: Ia7cfd1b0b61d59602994528f0fb2af7fee93d946 Signed-off-by: Torbjörn Svensson <azoff@svenskalinuxforeningen.se>
This commit is contained in:
parent
f0235bae94
commit
0ede7c7a60
7 changed files with 7 additions and 3 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -23,6 +23,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 1024
|
||||
|
@ -53,6 +54,7 @@ char * pfind(const char *name, char * const envp[])
|
|||
char *sp;
|
||||
char *path;
|
||||
char fullpath[PATH_MAX+1];
|
||||
struct stat sb;
|
||||
|
||||
/* Sanity check. */
|
||||
if (name == NULL) {
|
||||
|
@ -83,9 +85,11 @@ char * pfind(const char *name, char * const envp[])
|
|||
while (tok != NULL) {
|
||||
snprintf(fullpath, sizeof(fullpath) - 1, "%s/%s", tok, name);
|
||||
|
||||
if (access(fullpath, X_OK) == 0) {
|
||||
free(path);
|
||||
return strdup(fullpath);
|
||||
if (stat(fullpath, &sb) == 0 && S_ISREG(sb.st_mode)) { /* fullpath is a file */
|
||||
if (access(fullpath, X_OK) == 0) { /* fullpath is executable */
|
||||
free(path);
|
||||
return strdup(fullpath);
|
||||
}
|
||||
}
|
||||
|
||||
tok = strtok_r( NULL, ":", &sp );
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Add table
Reference in a new issue