1*c54f35caSApple OSS Distributions#include <Foundation/Foundation.h> 2*c54f35caSApple OSS Distributions#include <darwintest.h> 3*c54f35caSApple OSS Distributions#include <darwintest_utils.h> 4*c54f35caSApple OSS Distributions#include <mach-o/dyld.h> 5*c54f35caSApple OSS Distributions#include <System/sys/codesign.h> 6*c54f35caSApple OSS Distributions#include <unistd.h> 7*c54f35caSApple OSS Distributions#include <stdlib.h> 8*c54f35caSApple OSS Distributions#include <signal.h> 9*c54f35caSApple OSS Distributions#include <sys/types.h> 10*c54f35caSApple OSS Distributions#include <sys/sysctl.h> 11*c54f35caSApple OSS Distributions 12*c54f35caSApple OSS Distributions 13*c54f35caSApple OSS DistributionsT_GLOBAL_META(T_META_RUN_CONCURRENTLY(true), 14*c54f35caSApple OSS Distributions T_META_ASROOT(true)); 15*c54f35caSApple OSS Distributions 16*c54f35caSApple OSS Distributionsstruct procargs { 17*c54f35caSApple OSS Distributions int argc; 18*c54f35caSApple OSS Distributions size_t preflightSize; 19*c54f35caSApple OSS Distributions NSString *executablePath; 20*c54f35caSApple OSS Distributions NSArray *components; 21*c54f35caSApple OSS Distributions NSString *legacyExecutablePath; 22*c54f35caSApple OSS Distributions void *rawBuffer; 23*c54f35caSApple OSS Distributions size_t rawBufferSize; 24*c54f35caSApple OSS Distributions}; 25*c54f35caSApple OSS Distributions 26*c54f35caSApple OSS Distributionsstatic void printHexDump(void* buffer, size_t size); 27*c54f35caSApple OSS Distributions 28*c54f35caSApple OSS Distributionstypedef struct procargs *procargs_t; 29*c54f35caSApple OSS Distributions 30*c54f35caSApple OSS Distributions#define TEST_ENVIRONMENT_VARIABLE "TESTENVVARIABLE" 31*c54f35caSApple OSS Distributions#define TEST_ENVIRONMENT_VARIABLE_VALUE "TESTENVVARIABLE_VALUE" 32*c54f35caSApple OSS Distributions 33*c54f35caSApple OSS Distributions 34*c54f35caSApple OSS Distributionsstatic size_t argmax; 35*c54f35caSApple OSS Distributions 36*c54f35caSApple OSS Distributionsstatic procargs_t getProcArgs(int type, pid_t pid, size_t allocSize) 37*c54f35caSApple OSS Distributions{ 38*c54f35caSApple OSS Distributions int sysctlArgs[3] = {CTL_KERN, type, pid}; 39*c54f35caSApple OSS Distributions int argc; 40*c54f35caSApple OSS Distributions NSMutableArray *components = [NSMutableArray array]; 41*c54f35caSApple OSS Distributions procargs_t args = (procargs_t) malloc(sizeof(struct procargs)); 42*c54f35caSApple OSS Distributions size_t currentLen = 0; 43*c54f35caSApple OSS Distributions bool legacyPathPresent = false; 44*c54f35caSApple OSS Distributions NSString *current = nil; 45*c54f35caSApple OSS Distributions NSString *legacyExecutablePath = nil; 46*c54f35caSApple OSS Distributions NSString *executablePath = nil; 47*c54f35caSApple OSS Distributions size_t bufferSize; 48*c54f35caSApple OSS Distributions size_t preflightSize = 0; 49*c54f35caSApple OSS Distributions const char *name = type == KERN_PROCARGS ? "KERN_PROCARGS" : "KERN_PROCARGS2"; 50*c54f35caSApple OSS Distributions const char *cursor; 51*c54f35caSApple OSS Distributions void *buffer; 52*c54f35caSApple OSS Distributions 53*c54f35caSApple OSS Distributions T_LOG("Get proc args for pid %d, allocSize %lu with %s", pid, allocSize, name); 54*c54f35caSApple OSS Distributions 55*c54f35caSApple OSS Distributions 56*c54f35caSApple OSS Distributions T_ASSERT_TRUE(type == KERN_PROCARGS || type == KERN_PROCARGS2, "type is valid"); 57*c54f35caSApple OSS Distributions 58*c54f35caSApple OSS Distributions /* Determine how much memory to allocate. If allocSize is 0 we will use the size 59*c54f35caSApple OSS Distributions * we get from the sysctl for our buffer. */ 60*c54f35caSApple OSS Distributions T_ASSERT_POSIX_SUCCESS(sysctl(sysctlArgs, 3, NULL, &preflightSize, NULL, 0), "sysctl %s", name); 61*c54f35caSApple OSS Distributions T_LOG("procargs data should be %lu bytes", preflightSize); 62*c54f35caSApple OSS Distributions 63*c54f35caSApple OSS Distributions if (allocSize == 0) { 64*c54f35caSApple OSS Distributions allocSize = preflightSize; 65*c54f35caSApple OSS Distributions } 66*c54f35caSApple OSS Distributions 67*c54f35caSApple OSS Distributions buffer = malloc(allocSize); 68*c54f35caSApple OSS Distributions T_QUIET; T_ASSERT_NOTNULL(buffer, "malloc buffer of size %lu", allocSize); 69*c54f35caSApple OSS Distributions bufferSize = allocSize; 70*c54f35caSApple OSS Distributions 71*c54f35caSApple OSS Distributions T_ASSERT_POSIX_SUCCESS(sysctl(sysctlArgs, 3, buffer, &bufferSize, NULL, 0), "sysctl %s", name); 72*c54f35caSApple OSS Distributions T_ASSERT_LE(bufferSize, allocSize, "returned buffer size should be less than allocated size"); 73*c54f35caSApple OSS Distributions T_LOG("sysctl wrote %lu bytes", bufferSize); 74*c54f35caSApple OSS Distributions if (allocSize >= bufferSize) { 75*c54f35caSApple OSS Distributions /* Allocated buffer is larger than what kernel wrote, so it should match preflightSize */ 76*c54f35caSApple OSS Distributions T_ASSERT_EQ(bufferSize, preflightSize, "buffer size should be the same as preflight size"); 77*c54f35caSApple OSS Distributions } 78*c54f35caSApple OSS Distributions 79*c54f35caSApple OSS Distributions printHexDump(buffer, bufferSize); 80*c54f35caSApple OSS Distributions 81*c54f35caSApple OSS Distributions if (type == KERN_PROCARGS2) { 82*c54f35caSApple OSS Distributions argc = *(int *)buffer; 83*c54f35caSApple OSS Distributions cursor = (const char *)buffer + sizeof(int); 84*c54f35caSApple OSS Distributions } else { 85*c54f35caSApple OSS Distributions /* Without KERN_PROCARGS2, we can't tell where argv ends and environ begins. 86*c54f35caSApple OSS Distributions * Set argc to -1 to indicate this */ 87*c54f35caSApple OSS Distributions argc = -1; 88*c54f35caSApple OSS Distributions cursor = buffer; 89*c54f35caSApple OSS Distributions } 90*c54f35caSApple OSS Distributions 91*c54f35caSApple OSS Distributions while ((uintptr_t)cursor < (uintptr_t)buffer + bufferSize) { 92*c54f35caSApple OSS Distributions /* Ensure alignment and check if the uint16_t at cursor is the magic value */ 93*c54f35caSApple OSS Distributions if (!((uintptr_t)cursor & (sizeof(uint16_t) - 1)) && 94*c54f35caSApple OSS Distributions (uintptr_t)buffer + bufferSize - (uintptr_t)cursor > sizeof(uint16_t)) { 95*c54f35caSApple OSS Distributions /* Silence -Wcast-align by casting to const void * */ 96*c54f35caSApple OSS Distributions uint16_t value = *(const uint16_t *)(const void *)cursor; 97*c54f35caSApple OSS Distributions if (value == 0xBFFF) { 98*c54f35caSApple OSS Distributions /* Magic value that specifies the end of the argument/environ section */ 99*c54f35caSApple OSS Distributions cursor += sizeof(uint16_t) + sizeof(uint32_t); 100*c54f35caSApple OSS Distributions legacyPathPresent = true; 101*c54f35caSApple OSS Distributions break; 102*c54f35caSApple OSS Distributions } 103*c54f35caSApple OSS Distributions } 104*c54f35caSApple OSS Distributions currentLen = strnlen(cursor, bufferSize - ((uintptr_t)cursor - (uintptr_t)buffer)); 105*c54f35caSApple OSS Distributions current = [[NSString alloc] initWithBytes:cursor length:currentLen encoding:NSUTF8StringEncoding]; 106*c54f35caSApple OSS Distributions T_QUIET; T_ASSERT_NOTNULL(current, "allocated string"); 107*c54f35caSApple OSS Distributions cursor += currentLen + 1; 108*c54f35caSApple OSS Distributions 109*c54f35caSApple OSS Distributions if (executablePath == nil) { 110*c54f35caSApple OSS Distributions executablePath = current; 111*c54f35caSApple OSS Distributions [executablePath retain]; 112*c54f35caSApple OSS Distributions while (*cursor == 0) { 113*c54f35caSApple OSS Distributions cursor++; 114*c54f35caSApple OSS Distributions } 115*c54f35caSApple OSS Distributions } else { 116*c54f35caSApple OSS Distributions [components addObject:current]; 117*c54f35caSApple OSS Distributions } 118*c54f35caSApple OSS Distributions [current release]; 119*c54f35caSApple OSS Distributions } 120*c54f35caSApple OSS Distributions if (legacyPathPresent) { 121*c54f35caSApple OSS Distributions T_ASSERT_EQ(type, KERN_PROCARGS, "Legacy executable path should only be present for KERN_PROCARGS"); 122*c54f35caSApple OSS Distributions currentLen = strnlen(cursor, bufferSize - ((uintptr_t)cursor - (uintptr_t)buffer)); 123*c54f35caSApple OSS Distributions current = [[NSString alloc] initWithBytes:cursor length:currentLen encoding:NSUTF8StringEncoding]; 124*c54f35caSApple OSS Distributions T_QUIET; T_ASSERT_NOTNULL(current, "allocated string"); 125*c54f35caSApple OSS Distributions legacyExecutablePath = current; 126*c54f35caSApple OSS Distributions } 127*c54f35caSApple OSS Distributions args->argc = argc; 128*c54f35caSApple OSS Distributions args->executablePath = executablePath; 129*c54f35caSApple OSS Distributions args->components = components; 130*c54f35caSApple OSS Distributions args->legacyExecutablePath = legacyExecutablePath; 131*c54f35caSApple OSS Distributions args->preflightSize = preflightSize; 132*c54f35caSApple OSS Distributions args->rawBuffer = buffer; 133*c54f35caSApple OSS Distributions args->rawBufferSize = bufferSize; 134*c54f35caSApple OSS Distributions return args; 135*c54f35caSApple OSS Distributions} 136*c54f35caSApple OSS Distributions 137*c54f35caSApple OSS Distributionsstatic void printProcArgs(procargs_t procargs) { 138*c54f35caSApple OSS Distributions if (procargs->argc == -1) { 139*c54f35caSApple OSS Distributions T_LOG("No argument count"); 140*c54f35caSApple OSS Distributions } else { 141*c54f35caSApple OSS Distributions T_LOG("Argc is %d", procargs->argc); 142*c54f35caSApple OSS Distributions } 143*c54f35caSApple OSS Distributions T_LOG("Executable path: %s (length %lu)", [procargs->executablePath UTF8String], [procargs->executablePath length]); 144*c54f35caSApple OSS Distributions for (size_t i = 0; i < [procargs->components count]; i++) { 145*c54f35caSApple OSS Distributions NSString *component = [procargs->components objectAtIndex:i]; 146*c54f35caSApple OSS Distributions const char *str = [component UTF8String]; 147*c54f35caSApple OSS Distributions size_t len = [component length]; 148*c54f35caSApple OSS Distributions if (procargs->argc != -1) { 149*c54f35caSApple OSS Distributions T_LOG("%s %zu: %s (length %lu)", i >= (size_t)procargs->argc ? "Env var" : "Argument", i, str, len); 150*c54f35caSApple OSS Distributions } else { 151*c54f35caSApple OSS Distributions T_LOG("Component %zu: %s (length %lu)", i, str, len); 152*c54f35caSApple OSS Distributions } 153*c54f35caSApple OSS Distributions } 154*c54f35caSApple OSS Distributions if (procargs->legacyExecutablePath) { 155*c54f35caSApple OSS Distributions T_LOG("Contains legacy executable path: %s (length %lu)", [procargs->legacyExecutablePath UTF8String], [procargs->legacyExecutablePath length]); 156*c54f35caSApple OSS Distributions } 157*c54f35caSApple OSS Distributions printHexDump(procargs->rawBuffer, procargs->rawBufferSize); 158*c54f35caSApple OSS Distributions} 159*c54f35caSApple OSS Distributions 160*c54f35caSApple OSS Distributionsstatic void printHexDump(void* buffer, size_t size) { 161*c54f35caSApple OSS Distributions #define ROW_LENGTH 24 162*c54f35caSApple OSS Distributions T_LOG("Buffer %p, size %zu", buffer, size); 163*c54f35caSApple OSS Distributions for (size_t row = 0; row < size; row += ROW_LENGTH) { 164*c54f35caSApple OSS Distributions NSMutableString *line = [[NSMutableString alloc] initWithCapacity:0]; 165*c54f35caSApple OSS Distributions NSMutableString *text = [[NSMutableString alloc] initWithCapacity:0]; 166*c54f35caSApple OSS Distributions [line appendFormat:@" %04zx ", row]; 167*c54f35caSApple OSS Distributions for (size_t col = row; col < row + ROW_LENGTH; col++) { 168*c54f35caSApple OSS Distributions if (col < size) { 169*c54f35caSApple OSS Distributions char c = ((char *)buffer)[col]; 170*c54f35caSApple OSS Distributions [line appendFormat:@"%02x ", c]; 171*c54f35caSApple OSS Distributions if (isprint(c)) { 172*c54f35caSApple OSS Distributions [text appendFormat:@"%c", c]; 173*c54f35caSApple OSS Distributions } else { 174*c54f35caSApple OSS Distributions [text appendString:@"."]; 175*c54f35caSApple OSS Distributions } 176*c54f35caSApple OSS Distributions } else { 177*c54f35caSApple OSS Distributions [line appendString:@" "]; 178*c54f35caSApple OSS Distributions } 179*c54f35caSApple OSS Distributions } 180*c54f35caSApple OSS Distributions [line appendFormat:@" %@", text]; 181*c54f35caSApple OSS Distributions T_LOG("%s", [line UTF8String]); 182*c54f35caSApple OSS Distributions [text release]; 183*c54f35caSApple OSS Distributions [line release]; 184*c54f35caSApple OSS Distributions } 185*c54f35caSApple OSS Distributions} 186*c54f35caSApple OSS Distributions 187*c54f35caSApple OSS Distributionsstatic void deallocProcArgs(procargs_t procargs) 188*c54f35caSApple OSS Distributions{ 189*c54f35caSApple OSS Distributions [procargs->components release]; 190*c54f35caSApple OSS Distributions [procargs->executablePath release]; 191*c54f35caSApple OSS Distributions [procargs->legacyExecutablePath release]; 192*c54f35caSApple OSS Distributions free(procargs->rawBuffer); 193*c54f35caSApple OSS Distributions free(procargs); 194*c54f35caSApple OSS Distributions} 195*c54f35caSApple OSS Distributions 196*c54f35caSApple OSS DistributionsT_HELPER_DECL(child_helper, "Child process helper") 197*c54f35caSApple OSS Distributions{ 198*c54f35caSApple OSS Distributions while (true) { 199*c54f35caSApple OSS Distributions wait(NULL); 200*c54f35caSApple OSS Distributions } 201*c54f35caSApple OSS Distributions} 202*c54f35caSApple OSS Distributions 203*c54f35caSApple OSS Distributionsstatic pid_t 204*c54f35caSApple OSS Distributionslaunch_child_process(NSArray *args, bool cs_restrict) 205*c54f35caSApple OSS Distributions{ 206*c54f35caSApple OSS Distributions pid_t pid; 207*c54f35caSApple OSS Distributions char path[PATH_MAX]; 208*c54f35caSApple OSS Distributions uint32_t path_size = sizeof(path); 209*c54f35caSApple OSS Distributions uint32_t csopsStatus = 0; 210*c54f35caSApple OSS Distributions const char** dt_args; 211*c54f35caSApple OSS Distributions size_t dt_args_count; 212*c54f35caSApple OSS Distributions 213*c54f35caSApple OSS Distributions T_ASSERT_POSIX_SUCCESS(_NSGetExecutablePath(path, &path_size), "get executable path"); 214*c54f35caSApple OSS Distributions 215*c54f35caSApple OSS Distributions /* We need to add 4 arguments to the beginning and NULL at the end */ 216*c54f35caSApple OSS Distributions dt_args_count = [args count] + 5; 217*c54f35caSApple OSS Distributions dt_args = malloc(sizeof(char *) * dt_args_count); 218*c54f35caSApple OSS Distributions dt_args[0] = path; 219*c54f35caSApple OSS Distributions dt_args[1] = "-n"; 220*c54f35caSApple OSS Distributions dt_args[2] = "child_helper"; 221*c54f35caSApple OSS Distributions dt_args[3] = "--"; 222*c54f35caSApple OSS Distributions for (size_t i = 0; i < [args count]; i++) { 223*c54f35caSApple OSS Distributions NSString *arg = [args objectAtIndex:i]; 224*c54f35caSApple OSS Distributions dt_args[i + 4] = [arg UTF8String]; 225*c54f35caSApple OSS Distributions } 226*c54f35caSApple OSS Distributions dt_args[[args count] + 4] = NULL; 227*c54f35caSApple OSS Distributions 228*c54f35caSApple OSS Distributions T_LOG("Launching %s", path); 229*c54f35caSApple OSS Distributions T_LOG("Arguments: "); 230*c54f35caSApple OSS Distributions for (size_t i = 0; i < dt_args_count; i++) { 231*c54f35caSApple OSS Distributions T_LOG(" %s", dt_args[i] ? dt_args[i] : "(null)"); 232*c54f35caSApple OSS Distributions } 233*c54f35caSApple OSS Distributions T_ASSERT_POSIX_SUCCESS(dt_launch_tool(&pid, (char **)dt_args, false, NULL, NULL), "launched helper"); 234*c54f35caSApple OSS Distributions free(dt_args); 235*c54f35caSApple OSS Distributions 236*c54f35caSApple OSS Distributions if (cs_restrict) { 237*c54f35caSApple OSS Distributions csopsStatus |= CS_RESTRICT; 238*c54f35caSApple OSS Distributions T_ASSERT_POSIX_SUCCESS(csops(pid, CS_OPS_SET_STATUS, &csopsStatus, sizeof(csopsStatus)), "set CS_RESTRICT"); 239*c54f35caSApple OSS Distributions } 240*c54f35caSApple OSS Distributions return pid; 241*c54f35caSApple OSS Distributions} 242*c54f35caSApple OSS Distributions 243*c54f35caSApple OSS DistributionsT_DECL(test_sysctl_kern_procargs_25397314, "Test kern.procargs and kern.procargs2 sysctls") 244*c54f35caSApple OSS Distributions{ 245*c54f35caSApple OSS Distributions procargs_t procargs; 246*c54f35caSApple OSS Distributions size_t argsize = sizeof(argmax); 247*c54f35caSApple OSS Distributions NSString *testArgument1 = @"test argument 1"; 248*c54f35caSApple OSS Distributions bool containsTestArgument1 = false; 249*c54f35caSApple OSS Distributions NSString *testArgument2 = @"test argument 2"; 250*c54f35caSApple OSS Distributions bool containsTestArgument2 = false; 251*c54f35caSApple OSS Distributions NSString *testEnvironmentVariable = @TEST_ENVIRONMENT_VARIABLE; 252*c54f35caSApple OSS Distributions bool containsTestEnvironmentVariable = false; 253*c54f35caSApple OSS Distributions bool containsPathEnvironmentVariable = false; 254*c54f35caSApple OSS Distributions int development = 0; 255*c54f35caSApple OSS Distributions size_t development_size = sizeof(development); 256*c54f35caSApple OSS Distributions uint32_t csopsStatus = 0; 257*c54f35caSApple OSS Distributions 258*c54f35caSApple OSS Distributions 259*c54f35caSApple OSS Distributions T_ASSERT_POSIX_SUCCESS(sysctlbyname("kern.development", &development, &development_size, NULL, 0), "sysctl kern.development"); 260*c54f35caSApple OSS Distributions 261*c54f35caSApple OSS Distributions T_ASSERT_POSIX_SUCCESS(sysctlbyname("kern.argmax", &argmax, &argsize, NULL, 0), "sysctl kern.argmax"); 262*c54f35caSApple OSS Distributions procargs = getProcArgs(KERN_PROCARGS2, getpid(), argmax); 263*c54f35caSApple OSS Distributions T_ASSERT_NOTNULL(procargs->executablePath, "executable path should be non-null"); 264*c54f35caSApple OSS Distributions T_ASSERT_GT([procargs->executablePath length], 0, "executable path should not be empty"); 265*c54f35caSApple OSS Distributions printProcArgs(procargs); 266*c54f35caSApple OSS Distributions deallocProcArgs(procargs); 267*c54f35caSApple OSS Distributions 268*c54f35caSApple OSS Distributions procargs = getProcArgs(KERN_PROCARGS2, getpid(), 0); 269*c54f35caSApple OSS Distributions T_ASSERT_NOTNULL(procargs->executablePath, "executable path should be non-null"); 270*c54f35caSApple OSS Distributions T_ASSERT_GT([procargs->executablePath length], 0, "executable path should not be empty"); 271*c54f35caSApple OSS Distributions printProcArgs(procargs); 272*c54f35caSApple OSS Distributions deallocProcArgs(procargs); 273*c54f35caSApple OSS Distributions 274*c54f35caSApple OSS Distributions setenv(TEST_ENVIRONMENT_VARIABLE, TEST_ENVIRONMENT_VARIABLE_VALUE, true); 275*c54f35caSApple OSS Distributions 276*c54f35caSApple OSS Distributions pid_t child = launch_child_process(@[testArgument1, testArgument2], false); 277*c54f35caSApple OSS Distributions procargs = getProcArgs(KERN_PROCARGS2, child, argmax); 278*c54f35caSApple OSS Distributions T_ASSERT_NOTNULL(procargs->executablePath, "executable path should be non-null"); 279*c54f35caSApple OSS Distributions T_ASSERT_GT([procargs->executablePath length], 0, "executable path should not be empty"); 280*c54f35caSApple OSS Distributions printProcArgs(procargs); 281*c54f35caSApple OSS Distributions 282*c54f35caSApple OSS Distributions for (NSString *component in procargs->components) { 283*c54f35caSApple OSS Distributions if ([component isEqualToString:testArgument1]) { 284*c54f35caSApple OSS Distributions containsTestArgument1 = true; 285*c54f35caSApple OSS Distributions } 286*c54f35caSApple OSS Distributions if ([component isEqualToString:testArgument2]) { 287*c54f35caSApple OSS Distributions containsTestArgument2 = true; 288*c54f35caSApple OSS Distributions } 289*c54f35caSApple OSS Distributions if ([component containsString:testEnvironmentVariable]) { 290*c54f35caSApple OSS Distributions containsTestEnvironmentVariable = true; 291*c54f35caSApple OSS Distributions } 292*c54f35caSApple OSS Distributions } 293*c54f35caSApple OSS Distributions deallocProcArgs(procargs); 294*c54f35caSApple OSS Distributions kill(child, SIGKILL); 295*c54f35caSApple OSS Distributions T_ASSERT_TRUE(containsTestArgument1, "Found test argument 1"); 296*c54f35caSApple OSS Distributions T_ASSERT_TRUE(containsTestArgument2, "Found test argument 2"); 297*c54f35caSApple OSS Distributions T_ASSERT_TRUE(containsTestEnvironmentVariable, "Found test environment variable"); 298*c54f35caSApple OSS Distributions 299*c54f35caSApple OSS Distributions if (development) { 300*c54f35caSApple OSS Distributions T_LOG("Skipping test on DEVELOPMENT || DEBUG kernel"); 301*c54f35caSApple OSS Distributions } else { 302*c54f35caSApple OSS Distributions containsTestArgument1 = false; 303*c54f35caSApple OSS Distributions containsTestArgument2 = false; 304*c54f35caSApple OSS Distributions containsTestEnvironmentVariable = false; 305*c54f35caSApple OSS Distributions 306*c54f35caSApple OSS Distributions child = launch_child_process(@[testArgument1, testArgument2], true); 307*c54f35caSApple OSS Distributions procargs = getProcArgs(KERN_PROCARGS2, child, argmax); 308*c54f35caSApple OSS Distributions T_ASSERT_NOTNULL(procargs->executablePath, "executable path should be non-null"); 309*c54f35caSApple OSS Distributions T_ASSERT_GT([procargs->executablePath length], 0, "executable path should not be empty"); 310*c54f35caSApple OSS Distributions printProcArgs(procargs); 311*c54f35caSApple OSS Distributions for (NSString *component in procargs->components) { 312*c54f35caSApple OSS Distributions if ([component isEqualToString:testArgument1]) { 313*c54f35caSApple OSS Distributions containsTestArgument1 = true; 314*c54f35caSApple OSS Distributions } 315*c54f35caSApple OSS Distributions if ([component isEqualToString:testArgument2]) { 316*c54f35caSApple OSS Distributions containsTestArgument2 = true; 317*c54f35caSApple OSS Distributions } 318*c54f35caSApple OSS Distributions if ([component containsString:testEnvironmentVariable]) { 319*c54f35caSApple OSS Distributions containsTestEnvironmentVariable = true; 320*c54f35caSApple OSS Distributions } 321*c54f35caSApple OSS Distributions } 322*c54f35caSApple OSS Distributions deallocProcArgs(procargs); 323*c54f35caSApple OSS Distributions kill(child, SIGKILL); 324*c54f35caSApple OSS Distributions T_ASSERT_TRUE(containsTestArgument1, "Found test argument 1"); 325*c54f35caSApple OSS Distributions T_ASSERT_TRUE(containsTestArgument2, "Found test argument 2"); 326*c54f35caSApple OSS Distributions T_ASSERT_FALSE(containsTestEnvironmentVariable, "No test environment variable"); 327*c54f35caSApple OSS Distributions 328*c54f35caSApple OSS Distributions 329*c54f35caSApple OSS Distributions csopsStatus |= CS_RESTRICT; 330*c54f35caSApple OSS Distributions T_ASSERT_POSIX_SUCCESS(csops(getpid(), CS_OPS_SET_STATUS, &csopsStatus, sizeof(csopsStatus)), "set CS_RESTRICT on self"); 331*c54f35caSApple OSS Distributions procargs = getProcArgs(KERN_PROCARGS2, getpid(), argmax); 332*c54f35caSApple OSS Distributions T_ASSERT_NOTNULL(procargs->executablePath, "executable path should be non-null"); 333*c54f35caSApple OSS Distributions T_ASSERT_GT([procargs->executablePath length], 0, "executable path should not be empty"); 334*c54f35caSApple OSS Distributions printProcArgs(procargs); 335*c54f35caSApple OSS Distributions for (NSString *component in procargs->components) { 336*c54f35caSApple OSS Distributions if ([component containsString:@"PATH"]) { 337*c54f35caSApple OSS Distributions containsPathEnvironmentVariable = true; 338*c54f35caSApple OSS Distributions } 339*c54f35caSApple OSS Distributions } 340*c54f35caSApple OSS Distributions deallocProcArgs(procargs); 341*c54f35caSApple OSS Distributions T_ASSERT_TRUE(containsPathEnvironmentVariable, "Found $PATH environment variable"); 342*c54f35caSApple OSS Distributions } 343*c54f35caSApple OSS Distributions} 344