[106710] trunk/base/src/darwintracelib1.0/darwintrace.c
cal at macports.org
cal at macports.org
Wed Jun 5 18:13:07 PDT 2013
Revision: 106710
https://trac.macports.org/changeset/106710
Author: cal at macports.org
Date: 2013-06-05 18:13:07 -0700 (Wed, 05 Jun 2013)
Log Message:
-----------
darwintrace: deal with non-canonical paths
This fixes one of the last problems with darwintrace I've noticed:
/opt/local/bin/as tries to execute /opt/local/bin/../libexec/as/x86_64/as,
which previously failed, because the non-canonical path wasn't recognized as
being provided by a port in the dependency list.
Modified Paths:
--------------
trunk/base/src/darwintracelib1.0/darwintrace.c
Modified: trunk/base/src/darwintracelib1.0/darwintrace.c
===================================================================
--- trunk/base/src/darwintracelib1.0/darwintrace.c 2013-06-06 00:58:29 UTC (rev 106709)
+++ trunk/base/src/darwintracelib1.0/darwintrace.c 2013-06-06 01:13:07 UTC (rev 106710)
@@ -595,9 +595,11 @@
* return 1 if path (once normalized) is in sandbox or redirected, 0 otherwise.
*/
__attribute__((always_inline))
-inline int __darwintrace_is_in_sandbox(const char* path, char * newpath) {
+static inline int __darwintrace_is_in_sandbox(const char* path, char * newpath) {
char *t, *p, *_;
+ char *strpos, *normpos;
char lpath[MAXPATHLEN];
+ char normalizedpath[MAXPATHLEN];
__darwintrace_setup();
@@ -614,13 +616,49 @@
strcat(lpath, "/");
strcat(lpath, path);
}
-
p = lpath;
+ normalizedpath[0] = '\0';
+ strpos = p + 1;
+ normpos = normalizedpath;
+ for (;;) {
+ char *curpos = strsep(&strpos, "/");
+ if (curpos == NULL) {
+ /* reached the end of the path */
+ break;
+ } else if (*curpos == '\0') {
+ /* empty entry, ignore */
+ continue;
+ } else if (strcmp(curpos, ".") == 0) {
+ /* no-op directory, ignore */
+ continue;
+ } else if (strcmp(curpos, "..") == 0) {
+ /* walk up one directory */
+ char *lastSep = strrchr(normalizedpath, '/');
+ if (lastSep == NULL) {
+ /* path is completely empty */
+ normpos = normalizedpath;
+ *normpos = '\0';
+ continue;
+ }
+ /* remove last component by overwriting the slash with \0, update normpos */
+ *lastSep = '\0';
+ normpos = lastSep;
+ }
+ /* default case: standard path, copy */
+ strcat(normpos, "/");
+ normpos++;
+ strcat(normpos, curpos);
+ debug_printf("path %s, processing entry %s, normalized %s\n", path, curpos, normalizedpath);
+ }
+ if (*normalizedpath == '\0') {
+ strcat(normalizedpath, "/");
+ }
+
for (t = filemap; *t;) {
char state;
- if (__darwintrace_strbeginswith(p, t)) {
+ if (__darwintrace_strbeginswith(normalizedpath, t)) {
/* move t to the integer describing how to handle this match */
t += strlen(t) + 1;
switch (*t) {
@@ -638,11 +676,11 @@
if (_[-1] != '/') {
*_ = '/';
}
- strcpy(_, p);
+ strcpy(_, normalizedpath);
return 1;
case 2:
/* ask the socket whether this file is OK */
- return ask_for_dependency(p);
+ return ask_for_dependency(normalizedpath);
default:
fprintf(stderr, "darwintrace: error: unexpected byte in file map: `%x'\n", *t);
abort();
@@ -675,7 +713,7 @@
t++;
}
- __darwintrace_log_op("sandbox_violation", path, 0);
+ __darwintrace_log_op("sandbox_violation", normalizedpath, 0);
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20130605/94185664/attachment.html>
More information about the macports-changes
mailing list