PERFORCE change 177354 for review

Jonathan Anderson jona at FreeBSD.org
Mon Apr 26 14:43:29 UTC 2010


http://p4web.freebsd.org/@@177354?ac=10

Change 177354 by jona at jona-belle-freebsd8 on 2010/04/26 14:42:36

	Allow objects to be loaded by FD number instead of name

Affected files ...

.. //depot/projects/trustedbsd/capabilities/src/libexec/rtld-elf/rtld.c#43 edit

Differences ...

==== //depot/projects/trustedbsd/capabilities/src/libexec/rtld-elf/rtld.c#43 (text+ko) ====

@@ -1703,17 +1703,22 @@
 	    return obj;
 
 #ifdef IN_RTLD_CAP
-    if (strchr(name, '/') != NULL) {
-	_rtld_error("Absolute paths to shared objects not supported \"%s\"", name);
-	return NULL;
-    }
+    path = xstrdup(name);
 
     /* is the name actually a file descriptor? */
-    long long long_fd = strtonum(name, 0, 10000, NULL);
-    fd = (int) long_fd;
-    if (fstat(fd, &sb) == -1) {
-    	/* if not, search the library path */
-	path = xstrdup(name);
+    long long long_fd = strtonum(path, 0, __INT_MAX, NULL);
+    if ((long_fd >= 0) && (fstat((int) long_fd, &sb) == 0))
+	fd = (int) long_fd;
+
+    /* if not, search the library path */
+    else {
+	dbg("preload by name: %s", name);
+	if (strchr(name, '/') != NULL) {
+	    _rtld_error("Absolute paths (e.g. \"%s\") not supported", path);
+	    free(path);
+	    return NULL;
+	}
+
 	if ((fd = find_library_fd(path)) < 0) {
 	    _rtld_error("Unable to find \"%s\" in LD_LIBRARY_DIRS", path);
 	    free(path);
@@ -1791,7 +1796,7 @@
     if (dangerous_ld_env) {
 	if (fstatfs(fd, &fs) != 0) {
 	    _rtld_error("Cannot fstatfs \"%s\"", path);
-		return NULL;
+	    return NULL;
 	}
 	if (fs.f_flags & MNT_NOEXEC) {
 	    _rtld_error("Cannot execute objects on %s\n", fs.f_mntonname);


More information about the p4-projects mailing list