diff options
| author | Po Lu | 2023-05-05 12:10:14 +0800 |
|---|---|---|
| committer | Po Lu | 2023-05-05 12:10:14 +0800 |
| commit | 2ba6c5035c904426d564eac47381480158cbbb9e (patch) | |
| tree | b576d09ca7ae39e22e52c4004a8b02f0e833c3d7 /exec/exec.c | |
| parent | d5414f1797467b00ca4f75faf39c774b150fc509 (diff) | |
| download | emacs-2ba6c5035c904426d564eac47381480158cbbb9e.tar.gz emacs-2ba6c5035c904426d564eac47381480158cbbb9e.zip | |
Update Android port
* doc/emacs/android.texi (Android Environment): Document lossage
with SIGSTOP.
* exec/exec.c (exec_0): Check X_OK on file being opened. Also
handle /proc/self/exe.
Diffstat (limited to 'exec/exec.c')
| -rw-r--r-- | exec/exec.c | 76 |
1 files changed, 46 insertions, 30 deletions
diff --git a/exec/exec.c b/exec/exec.c index 17051428658..a15386b51bb 100644 --- a/exec/exec.c +++ b/exec/exec.c | |||
| @@ -961,52 +961,68 @@ exec_0 (char *name, struct exec_tracee *tracee, | |||
| 961 | ssize_t link_size; | 961 | ssize_t link_size; |
| 962 | size_t remaining; | 962 | size_t remaining; |
| 963 | 963 | ||
| 964 | /* If name is not absolute, then make it relative to TRACEE's | 964 | /* If the process is trying to run /proc/self/exe, make it run |
| 965 | cwd. Use stpcpy, as sprintf is not reentrant. */ | 965 | itself instead. */ |
| 966 | 966 | ||
| 967 | if (name[0] && name[0] != '/') | 967 | if (!strcmp (name, "/proc/self/exe") && tracee->exec_file) |
| 968 | { | 968 | { |
| 969 | /* Clear `buffer'. */ | 969 | strncpy (name, tracee->exec_file, PATH_MAX - 1); |
| 970 | memset (buffer, 0, sizeof buffer); | 970 | name[PATH_MAX] = '\0'; |
| 971 | memset (buffer1, 0, sizeof buffer); | 971 | } |
| 972 | else | ||
| 973 | { | ||
| 974 | /* If name is not absolute, then make it relative to TRACEE's | ||
| 975 | cwd. Use stpcpy, as sprintf is not reentrant. */ | ||
| 972 | 976 | ||
| 973 | /* Copy over /proc, the PID, and /cwd/. */ | 977 | if (name[0] && name[0] != '/') |
| 974 | rewrite = stpcpy (buffer, "/proc/"); | 978 | { |
| 975 | rewrite = format_pid (rewrite, tracee->pid); | 979 | /* Clear `buffer'. */ |
| 976 | stpcpy (rewrite, "/cwd"); | 980 | memset (buffer, 0, sizeof buffer); |
| 981 | memset (buffer1, 0, sizeof buffer); | ||
| 977 | 982 | ||
| 978 | /* Resolve this symbolic link. */ | 983 | /* Copy over /proc, the PID, and /cwd/. */ |
| 984 | rewrite = stpcpy (buffer, "/proc/"); | ||
| 985 | rewrite = format_pid (rewrite, tracee->pid); | ||
| 986 | stpcpy (rewrite, "/cwd"); | ||
| 979 | 987 | ||
| 980 | link_size = readlink (buffer, buffer1, | 988 | /* Resolve this symbolic link. */ |
| 981 | PATH_MAX + 1); | ||
| 982 | 989 | ||
| 983 | if (link_size < 0) | 990 | link_size = readlink (buffer, buffer1, |
| 984 | return NULL; | 991 | PATH_MAX + 1); |
| 985 | 992 | ||
| 986 | /* Check that the name is a reasonable size. */ | 993 | if (link_size < 0) |
| 994 | return NULL; | ||
| 987 | 995 | ||
| 988 | if (link_size > PATH_MAX) | 996 | /* Check that the name is a reasonable size. */ |
| 989 | { | 997 | |
| 990 | /* The name is too long. */ | 998 | if (link_size > PATH_MAX) |
| 991 | errno = ENAMETOOLONG; | 999 | { |
| 992 | return NULL; | 1000 | /* The name is too long. */ |
| 993 | } | 1001 | errno = ENAMETOOLONG; |
| 1002 | return NULL; | ||
| 1003 | } | ||
| 994 | 1004 | ||
| 995 | /* Add a directory separator if necessary. */ | 1005 | /* Add a directory separator if necessary. */ |
| 996 | 1006 | ||
| 997 | if (!link_size || buffer1[link_size - 1] != '/') | 1007 | if (!link_size || buffer1[link_size - 1] != '/') |
| 998 | buffer1[link_size] = '/', link_size++; | 1008 | buffer1[link_size] = '/', link_size++; |
| 999 | 1009 | ||
| 1000 | rewrite = buffer1 + link_size; | 1010 | rewrite = buffer1 + link_size; |
| 1001 | remaining = buffer1 + sizeof buffer1 - rewrite - 1; | 1011 | remaining = buffer1 + sizeof buffer1 - rewrite - 1; |
| 1002 | rewrite = stpncpy (rewrite, name, remaining); | 1012 | rewrite = stpncpy (rewrite, name, remaining); |
| 1003 | 1013 | ||
| 1004 | /* Replace name with buffer1. */ | 1014 | /* Replace name with buffer1. */ |
| 1005 | #ifndef REENTRANT | 1015 | #ifndef REENTRANT |
| 1006 | strcpy (name, buffer1); | 1016 | strcpy (name, buffer1); |
| 1007 | #endif /* REENTRANT */ | 1017 | #endif /* REENTRANT */ |
| 1018 | } | ||
| 1008 | } | 1019 | } |
| 1009 | 1020 | ||
| 1021 | /* Check that the file is accessible and executable. */ | ||
| 1022 | |||
| 1023 | if (access (name, X_OK)) | ||
| 1024 | return NULL; | ||
| 1025 | |||
| 1010 | fd = open (name, O_RDONLY); | 1026 | fd = open (name, O_RDONLY); |
| 1011 | if (fd < 0) | 1027 | if (fd < 0) |
| 1012 | return NULL; | 1028 | return NULL; |