]> git.saurik.com Git - apple/libc.git/blobdiff - gen/FreeBSD/sysctl.c
Libc-1439.100.3.tar.gz
[apple/libc.git] / gen / FreeBSD / sysctl.c
index 66d82d04c7150e2c52cf5451bef93586da533de9..3cbe7488a3d8cb85c69c79392b01beb5508fade0 100644 (file)
@@ -43,18 +43,49 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/sysctl.c,v 1.6 2007/01/09 00:27:55 imp Exp
 #include <unistd.h>
 #include <string.h>
 
 #include <unistd.h>
 #include <string.h>
 
-extern int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
-    void *newp, size_t newlen);
+#include "sysctl_internal.h"
+
 
 int
 
 int
-sysctl(name, namelen, oldp, oldlenp, newp, newlen)
-       int *name;
-       u_int namelen;
-       void *oldp, *newp;
-       size_t *oldlenp, newlen;
+sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
+__attribute__((disable_tail_calls))
 {
 {
-       if (name[0] != CTL_USER)
-               return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen));
+       if (name[0] != CTL_USER) {
+               if (namelen == 2 && name[0] == CTL_KERN && name[1] == KERN_EXEC) {
+                       /*
+                        * 7723306: intercept kern.exec and fake a return of
+                        * a dummy string ("/" in this case)
+                        */
+                       if (newp != NULL) {
+                               errno = EPERM;
+                               return -1;
+                       }
+                       if (oldp == NULL) {
+                               if (oldlenp != NULL) *oldlenp = 2;
+                               return 0;
+                       }
+                       if (oldlenp == NULL) {
+                               errno = EFAULT;
+                               return -1;
+                       }
+                       if (*oldlenp < 2) {
+                               errno = ENOMEM;
+                               return -1;
+                       }
+                       memmove(oldp, "/", 2);
+                       *oldlenp = 2;
+                       return 0;
+               }
+
+
+               int error = __sysctl(name, namelen, oldp, oldlenp, newp, newlen);
+               if (error < 0) {
+                       return error;
+               }
+
+
+               return error;
+       }
 
        if (newp != NULL) {
                errno = EPERM;
 
        if (newp != NULL) {
                errno = EPERM;