X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/cf7d32b81c573a0536dc4da4157f9c26f8d0bed3..15129b1c8dbb3650c63b70adb1cad9af601c6c17:/tools/tests/xnu_quick_test/tests.c diff --git a/tools/tests/xnu_quick_test/tests.c b/tools/tests/xnu_quick_test/tests.c index 19d6af77f..11aec361a 100644 --- a/tools/tests/xnu_quick_test/tests.c +++ b/tools/tests/xnu_quick_test/tests.c @@ -3,25 +3,28 @@ * xnu_quick_test * * Created by Jerry Cottingham on 3/25/05. - * Copyright 2005 Apple Computer Inc. All rights reserved. + * Copyright 2008 Apple Inc. All rights reserved. * */ #include "tests.h" -#include /* for kqueue tests */ #include /* for message queue tests */ #include /* for message queue tests */ #include /* for get / settid */ #include /* for determining hw */ +#include /* for kas_info() */ #include /* for determination of Mac OS X version (tiger, leopard, etc.) */ #include /* for OSSwap32() */ +#include extern char g_target_path[ PATH_MAX ]; extern int g_skip_setuid_tests; -extern int g_is_under_rosetta; +extern int g_is_single_user; + + +void print_acct_debug_strings( char * my_ac_comm ); - #if TEST_SYSTEM_CALLS /* system calls to do */ "reboot", /* 55 = reboot */ @@ -68,13 +71,14 @@ int syscall_test( void * the_argp ) { int my_err; int my_fd = -1; - char * my_pathp; + char * my_pathp; + kern_return_t my_kr; - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } *my_pathp = 0x00; strcpy( my_pathp, &g_target_path[0] ); @@ -107,7 +111,7 @@ test_passed_exit: close( my_fd ); if ( my_pathp != NULL ) { remove( my_pathp ); - free( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); } @@ -179,26 +183,27 @@ int fork_wait4_exit_test( void * the_argp ) */ int read_write_test( void * the_argp ) { - int my_fd = -1; - int my_err; + int my_fd = -1; + int my_err; char * my_pathp = NULL; char * my_bufp = NULL; ssize_t my_result; off_t my_current_offset; - struct iovec my_iovs[2]; + struct iovec my_iovs[2]; struct stat my_sb; + kern_return_t my_kr; - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } - my_bufp = (char *) malloc( MY_BUFFER_SIZE ); - if ( my_bufp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_bufp, MY_BUFFER_SIZE, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); @@ -225,10 +230,10 @@ int read_write_test( void * the_argp ) } if ( my_result != 0 ) { if ( sizeof( ssize_t ) > sizeof( int ) ) { - printf( "read call failed - should have read 0 bytes on empty file - read %lld \n", my_result ); + printf( "read call failed - should have read 0 bytes on empty file - read %ld \n", (long int) my_result ); } else { - printf( "read call failed - should have read 0 bytes on empty file - read %d \n", my_result ); + printf( "read call failed - should have read 0 bytes on empty file - read %d \n", (int) my_result ); } goto test_failed_exit; } @@ -238,10 +243,10 @@ int read_write_test( void * the_argp ) my_err = errno; if ( my_result != -1 ) { if ( sizeof( ssize_t ) > sizeof( int ) ) { - printf( "write should have failed for read only fd - %lld \n", my_result ); + printf( "write should have failed for read only fd - %ld \n", (long int) my_result ); } else { - printf( "write should have failed for read only fd - %d \n", my_result ); + printf( "write should have failed for read only fd - %d \n", (int) my_result ); } goto test_failed_exit; } @@ -292,7 +297,7 @@ int read_write_test( void * the_argp ) goto test_failed_exit; } if ( my_result != 32 ) { - printf( "readv failed to get all the data - asked for %d got back %d\n", MY_BUFFER_SIZE, my_result ); + printf( "readv failed to get all the data - asked for %d got back %d\n", MY_BUFFER_SIZE, (int) my_result ); goto test_failed_exit; } if ( *my_bufp != 'j' || *(my_bufp + (MY_BUFFER_SIZE - 1)) != 'j' ) { @@ -330,7 +335,7 @@ int read_write_test( void * the_argp ) goto test_failed_exit; } if ( my_result != 16 ) { - printf( "writev failed to get all the data - asked for %d got back %d\n", MY_BUFFER_SIZE, my_result ); + printf( "writev failed to get all the data - asked for %d got back %d\n", MY_BUFFER_SIZE, (int) my_result ); goto test_failed_exit; } @@ -348,7 +353,7 @@ int read_write_test( void * the_argp ) goto test_failed_exit; } if ( my_result != 16 ) { - printf( "readv failed to get all the data - asked for %d got back %d\n", MY_BUFFER_SIZE, my_result ); + printf( "readv failed to get all the data - asked for %d got back %d\n", MY_BUFFER_SIZE, (int) my_result ); goto test_failed_exit; } if ( *my_bufp != 'z' || *(my_bufp + (MY_BUFFER_SIZE - 1)) != 'z' ) { @@ -429,11 +434,11 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } if ( my_bufp != NULL ) - free( my_bufp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_bufp, MY_BUFFER_SIZE); return( my_err ); } @@ -443,19 +448,20 @@ test_passed_exit: */ int open_close_test( void * the_argp ) { - int my_err; - int my_fd = -1; + int my_err; + int my_fd = -1; char * my_pathp = NULL; ssize_t my_result; long my_pconf_result; struct stat my_sb; char my_buffer[32]; + kern_return_t my_kr; - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); @@ -484,7 +490,7 @@ int open_close_test( void * the_argp ) // printf( "_PC_PATH_MAX %ld \n", my_pconf_result ); /* results look OK? */ if ( my_pconf_result < PATH_MAX ) { - printf( "pathconf - _PC_PATH_MAX - looks like wrong resutls \n" ); + printf( "pathconf - _PC_PATH_MAX - looks like wrong results \n" ); goto test_failed_exit; } @@ -496,7 +502,7 @@ int open_close_test( void * the_argp ) // printf( "_PC_NAME_MAX %ld \n", my_pconf_result ); /* results look OK? */ if ( my_pconf_result < 6 ) { - printf( "fpathconf - _PC_NAME_MAX - looks like wrong resutls \n" ); + printf( "fpathconf - _PC_NAME_MAX - looks like wrong results \n" ); goto test_failed_exit; } @@ -505,10 +511,10 @@ int open_close_test( void * the_argp ) my_err = errno; if ( my_result != 3 ) { if ( sizeof( ssize_t ) > sizeof( int ) ) { - printf( "write failed. should have written 3 bytes actually wrote - %lld \n", my_result ); + printf( "write failed. should have written 3 bytes actually wrote - %ld \n", (long int) my_result ); } else { - printf( "write failed. should have written 3 bytes actually wrote - %ld \n", my_result ); + printf( "write failed. should have written 3 bytes actually wrote - %d \n", (int) my_result ); } goto test_failed_exit; } @@ -549,10 +555,10 @@ int open_close_test( void * the_argp ) my_err = errno; if ( my_result != 3 ) { if ( sizeof( ssize_t ) > sizeof( int ) ) { - printf( "write failed. should have written 3 bytes actually wrote - %lld \n", my_result ); + printf( "write failed. should have written 3 bytes actually wrote - %ld \n", (long int) my_result ); } else { - printf( "write failed. should have written 3 bytes actually wrote - %ld \n", my_result ); + printf( "write failed. should have written 3 bytes actually wrote - %d \n", (int) my_result ); } goto test_failed_exit; } @@ -563,10 +569,10 @@ int open_close_test( void * the_argp ) my_err = errno; if ( my_result != 3 ) { if ( sizeof( ssize_t ) > sizeof( int ) ) { - printf( "write failed. should have written 3 bytes actually wrote - %lld \n", my_result ); + printf( "write failed. should have written 3 bytes actually wrote - %ld \n", (long int) my_result ); } else { - printf( "write failed. should have written 3 bytes actually wrote - %ld \n", my_result ); + printf( "write failed. should have written 3 bytes actually wrote - %d \n", (int) my_result ); } goto test_failed_exit; } @@ -609,8 +615,8 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); } @@ -621,24 +627,26 @@ test_passed_exit: */ int link_stat_unlink_test( void * the_argp ) { - int my_err; - int my_fd = -1; + int my_err; + int my_fd = -1; char * my_pathp = NULL; char * my_path2p = NULL; nlink_t my_link_count; ssize_t my_result; struct stat my_sb; + kern_return_t my_kr; - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } - my_path2p = (char *) malloc( PATH_MAX ); - if ( my_path2p == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_path2p, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } *my_pathp = 0x00; *my_path2p = 0x00; @@ -681,10 +689,10 @@ int link_stat_unlink_test( void * the_argp ) my_err = errno; if ( my_result != 3 ) { if ( sizeof( ssize_t ) > sizeof( int ) ) { - printf( "write failed. should have written 3 bytes actually wrote - %lld \n", my_result ); + printf( "write failed. should have written 3 bytes actually wrote - %ld \n", (long int) my_result ); } else { - printf( "write failed. should have written 3 bytes actually wrote - %ld \n", my_result ); + printf( "write failed. should have written 3 bytes actually wrote - %d \n", (int) my_result ); } goto test_failed_exit; } @@ -742,12 +750,12 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } if ( my_path2p != NULL ) { remove( my_path2p ); - free( my_path2p ); + vm_deallocate(mach_task_self(), (vm_address_t)my_path2p, PATH_MAX); } return( my_err ); } @@ -758,20 +766,22 @@ test_passed_exit: */ int chdir_fchdir_test( void * the_argp ) { - int my_err; - int my_fd = -1; + int my_err; + int my_fd = -1; char * my_pathp = NULL; char * my_file_namep; struct stat my_sb; struct stat my_sb2; + kern_return_t my_kr; char *cwd = getwd(NULL); /* Save current working directory so we can restore later */ - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); strcat( my_pathp, "/" ); @@ -870,8 +880,8 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } if ( chdir(cwd) != 0) /* Changes back to original directory, don't screw up the env. */ my_err = -1; @@ -884,16 +894,25 @@ test_passed_exit: */ int access_chmod_fchmod_test( void * the_argp ) { - int my_err; - int my_fd = -1; - char * my_pathp = NULL; - struct stat my_sb; + int error_occurred; + int my_err; + int my_fd = -1; + + char * my_pathp = NULL; + + uid_t euid,ruid; + struct stat my_sb; + + FILE * file_handle; + + kern_return_t my_kr; - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); @@ -905,6 +924,7 @@ int access_chmod_fchmod_test( void * the_argp ) goto test_failed_exit; } + /* test chmod */ my_err = chmod( my_pathp, S_IRWXU ); if ( my_err == -1 ) { @@ -930,17 +950,10 @@ int access_chmod_fchmod_test( void * the_argp ) /* special case when running as root - we get back EPERM when running as root */ my_err = errno; -#if !TARGET_OS_EMBEDDED if ( ( tmp == 0 && my_err != EPERM) || (tmp != 0 && my_err != EACCES) ) { printf( "access failed with errno %d - %s. \n", my_err, strerror( my_err ) ); goto test_failed_exit; } -#else - if ( ( tmp == 0 && my_err != EACCES) || (tmp != 0 && my_err != EACCES) ) { - printf( "access failed with errno %d - %s. \n", my_err, strerror( my_err ) ); - goto test_failed_exit; - } -#endif } /* verify correct modes are set */ @@ -955,7 +968,83 @@ int access_chmod_fchmod_test( void * the_argp ) printf( "chmod call appears to have failed. stat shows incorrect values in st_mode! \n" ); goto test_failed_exit; } + + + /* another test for the access system call -- refer ro radar# 6725311 */ + +#if !TARGET_OS_EMBEDDED + + /* + * This test makes sure that the access system call does not give the current user extra + * permissions on files the current user does not own. From radar #6725311, this could + * happen when the current user calls access() on a file owned by the current user in + * the same directory as the other files not owned by the current user. + * + * Note: This test expects that the effective uid (euid) is set to root. + * + */ + + /* Create a file that root owns */ + file_handle = fopen(FILE_NOTME, "w"); + fclose(file_handle); + + /* Currently running as root (through setreuid manipulation), switch to running as the current user. */ + euid = geteuid(); + ruid = getuid(); + setreuid(ruid, ruid); + + /* Create a file that the current user owns */ + file_handle = fopen(FILE_ME, "w"); + fclose(file_handle); + + error_occurred = 0; + + /* Try to remove the file owned by root (this should fail). */ + my_err = unlink(FILE_NOTME); + + if (my_err < 0) { + my_err = errno; + } + + if (my_err == 0) { + printf("Unresolved: First attempt deleted '" FILE_NOTME "'! \n"); + error_occurred = 1; + } else { + printf("Status: First attempt to delete '" FILE_NOTME "' failed with error %d - %s.\n", my_err, strerror( my_err )); + + /* Set _DELETE_OK on a file that the current user owns */ + access(FILE_ME, _DELETE_OK); + + /* Try to remove the file owned by root again (should give us: EPERM [13]) */ + my_err = unlink(FILE_NOTME); + + if (my_err < 0) { + my_err = errno; + } + + if (my_err == 0) { + printf("Failed: Second attempt deleted '" FILE_NOTME "'!\n"); + error_occurred = 1; + } else if (my_err == 13) { + printf("Passed: Second attempt to delete '" FILE_NOTME "' failed with error %d - %s.\n", my_err, strerror( my_err )); + } else { + printf("Failed: Second attempt to delete '" FILE_NOTME "' failed with error %d - %s.\n", my_err, strerror( my_err )); + error_occurred = 1; + } + } + + /* Reset to running as root */ + setreuid(ruid, euid); + + if(error_occurred == 1) { + goto test_failed_exit; + } +#endif + + /* end of test*/ + + /* test fchmod */ my_fd = open( my_pathp, O_RDONLY, 0 ); if ( my_fd == -1 ) { @@ -994,11 +1083,31 @@ test_passed_exit: close( my_fd ); if ( my_pathp != NULL ) { remove( my_pathp ); - free( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); } +#if !TARGET_OS_EMBEDDED +static bool _prime_groups(void) +{ + /* + * prime groups with a known list to ensure consistent test behavior + */ + + gid_t my_exp_groups[] = { getegid(), 20, 61, 12 }; + int my_err; + + my_err = setgroups( ( sizeof(my_exp_groups) / sizeof(*my_exp_groups) ), &my_exp_groups[0] ); + if ( my_err == -1 ) { + printf( "initial setgroups call failed. got errno %d - %s. \n", errno, strerror( errno ) ); + return false; + } + + return true; +} +#endif + /* ************************************************************************************************************** * Test chown, fchown, lchown, lstat, readlink, symlink system calls. * ************************************************************************************************************** @@ -1006,8 +1115,8 @@ test_passed_exit: int chown_fchown_lchown_lstat_symlink_test( void * the_argp ) { #if !TARGET_OS_EMBEDDED - int my_err, my_group_count, i; - int my_fd = -1; + int my_err, my_group_count, i; + int my_fd = -1; char * my_pathp = NULL; char * my_link_pathp = NULL; uid_t my_orig_uid; @@ -1016,12 +1125,13 @@ int chown_fchown_lchown_lstat_symlink_test( void * the_argp ) struct stat my_sb; gid_t my_groups[ NGROUPS_MAX ]; char my_buffer[ 64 ]; + kern_return_t my_kr; - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); @@ -1033,11 +1143,11 @@ int chown_fchown_lchown_lstat_symlink_test( void * the_argp ) goto test_failed_exit; } - my_link_pathp = (char *) malloc( PATH_MAX ); - if ( my_link_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_link_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } *my_link_pathp = 0x00; strcat( my_link_pathp, &g_target_path[0] ); @@ -1049,9 +1159,12 @@ int chown_fchown_lchown_lstat_symlink_test( void * the_argp ) goto test_failed_exit; } + if ( !_prime_groups() ) { + goto test_failed_exit; + } + /* set up by getting a list of groups */ my_group_count = getgroups( NGROUPS_MAX, &my_groups[0] ); - printf("my_group_count: %d\n", my_group_count); if ( my_group_count == -1 || my_group_count < 1 ) { printf( "getgroups call failed. got errno %d - %s. \n", errno, strerror( errno ) ); @@ -1068,14 +1181,12 @@ int chown_fchown_lchown_lstat_symlink_test( void * the_argp ) my_orig_gid = my_sb.st_gid; my_orig_uid = my_sb.st_uid; - printf( "st_gid: %d, st_uid: %d, my_group_count: %d\n" ); - for ( i = 0; i < my_group_count; i++ ) { if ( my_orig_gid != my_groups[ i ] ) { if ( my_new_gid1 == 0 ) { my_new_gid1 = my_groups[ i ]; } - else { + else if( my_new_gid1 != my_groups[ i ] ) { my_new_gid2 = my_groups[ i ]; break; } @@ -1183,12 +1294,12 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } if ( my_link_pathp != NULL ) { unlink( my_link_pathp ); - free( my_link_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_link_pathp, PATH_MAX); } return( my_err ); #else @@ -1211,37 +1322,45 @@ struct vol_attr_buf { #pragma pack() typedef struct vol_attr_buf vol_attr_buf; +#define STATFS_TEST_PATH "/tmp" + int fs_stat_tests( void * the_argp ) { - int my_err, my_count, i; - int my_buffer_size, my_buffer64_size; - int my_fd = -1; - int is_ufs = 0; + int my_err, my_count, i; + int my_buffer_size, my_buffer64_size; + int my_fd = -1; + int is_ufs = 0; + long my_io_size; + fsid_t my_fsid; + struct attrlist my_attrlist; + vol_attr_buf my_attr_buf; void * my_bufferp = NULL; - void * my_buffer64p = NULL; struct statfs * my_statfsp; + kern_return_t my_kr; + +#if !TARGET_OS_EMBEDDED + void * my_buffer64p = NULL; struct statfs64 * my_statfs64p; - long my_io_size; - fsid_t my_fsid; - struct attrlist my_attrlist; - vol_attr_buf my_attr_buf; - my_buffer_size = (sizeof(struct statfs) * 10); my_buffer64_size = (sizeof(struct statfs64) * 10); - my_bufferp = malloc( my_buffer_size ); - if ( my_bufferp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } - my_buffer64p = malloc( my_buffer64_size ); - if ( my_buffer64p == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; + my_kr = vm_allocate((vm_map_t) mach_task_self(),(vm_address_t*) &my_buffer64p, my_buffer64_size, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; } +#endif + my_buffer_size = (sizeof(struct statfs) * 10); + + my_kr = vm_allocate((vm_map_t) mach_task_self(),(vm_address_t*) &my_bufferp, my_buffer_size, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + my_statfsp = (struct statfs *) my_bufferp; - my_err = statfs( "/", my_statfsp ); + my_err = statfs( STATFS_TEST_PATH, my_statfsp ); if ( my_err == -1 ) { printf( "statfs call failed. got errno %d - %s. \n", errno, strerror( errno ) ); goto test_failed_exit; @@ -1272,9 +1391,10 @@ int fs_stat_tests( void * the_argp ) goto test_failed_exit; } +#if !TARGET_OS_EMBEDDED /* now try statfs64 */ my_statfs64p = (struct statfs64 *) my_buffer64p; - my_err = statfs64( "/", my_statfs64p ); + my_err = statfs64( STATFS_TEST_PATH, my_statfs64p ); if ( my_err == -1 ) { printf( "statfs64 call failed. got errno %d - %s. \n", errno, strerror( errno ) ); goto test_failed_exit; @@ -1306,6 +1426,7 @@ int fs_stat_tests( void * the_argp ) printf( "getfsstat64 call failed. could not find valid f_fstypename! \n" ); goto test_failed_exit; } +#endif /* set up to validate results via multiple sources. we use getattrlist to get volume * related attributes to verify against results from fstatfs and statfs - but only if @@ -1322,13 +1443,14 @@ int fs_stat_tests( void * the_argp ) } } - /* open kernel to use as test file for fstatfs */ - my_fd = open( "/mach_kernel", O_RDONLY, 0 ); + /* open to use as test file for fstatfs */ + my_fd = open( STATFS_TEST_PATH, O_RDONLY, 0 ); if ( my_fd == -1 ) { printf( "open call failed. got errno %d - %s. \n", errno, strerror( errno ) ); goto test_failed_exit; } +#if !TARGET_OS_EMBEDDED /* testing fstatfs64 */ my_statfs64p = (struct statfs64 *) my_buffer64p; my_err = fstatfs64( my_fd, my_statfs64p ); @@ -1343,6 +1465,7 @@ int fs_stat_tests( void * the_argp ) printf( "fstatfs64 call failed. could not find valid f_fstypename! \n" ); goto test_failed_exit; } +#endif /* testing fstatfs */ my_statfsp = (struct statfs *) my_bufferp; @@ -1352,7 +1475,7 @@ int fs_stat_tests( void * the_argp ) goto test_failed_exit; } - /* validate resutls */ + /* validate results */ if ( !(memcmp( &my_statfsp->f_fstypename[0], "hfs", 3 ) == 0 || memcmp( &my_statfsp->f_fstypename[0], "ufs", 3 ) == 0) ) { printf( "fstatfs call failed. could not find valid f_fstypename! \n" ); @@ -1366,13 +1489,13 @@ int fs_stat_tests( void * the_argp ) } /* try again with statfs */ - my_err = statfs( "/mach_kernel", my_statfsp ); + my_err = statfs( STATFS_TEST_PATH , my_statfsp ); if ( my_err == -1 ) { printf( "statfs call failed. got errno %d - %s. \n", errno, strerror( errno ) ); goto test_failed_exit; } - /* validate resutls */ + /* validate results */ if ( my_io_size != my_statfsp->f_iosize || my_fsid.val[0] != my_statfsp->f_fsid.val[0] || my_fsid.val[1] != my_statfsp->f_fsid.val[1] ) { printf( "statfs call failed. wrong f_iosize or f_fsid! \n" ); @@ -1393,11 +1516,13 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_bufferp != NULL ) { - free( my_bufferp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_bufferp, my_buffer_size); } +#if !TARGET_OS_EMBEDDED if ( my_buffer64p != NULL ) { - free( my_buffer64p ); + vm_deallocate(mach_task_self(), (vm_address_t)my_buffer64p, my_buffer64_size); } +#endif return( my_err ); } @@ -1509,7 +1634,7 @@ test_passed_exit: /* ************************************************************************************************************** - * Test getauid, gettid, getuid, geteuid, issetugid, setauid, seteuid, settid, settid_with_pid, setuid system calls. + * Test getauid, gettid, getuid, geteuid, issetugid, setaudit_addr, seteuid, settid, settid_with_pid, setuid system calls. * ************************************************************************************************************** */ int uid_tests( void * the_argp ) @@ -1523,18 +1648,23 @@ int uid_tests( void * the_argp ) goto test_passed_exit; } - /* test issetugid - should return 1 when not root and 0 when root */ - my_err = issetugid( ); - if ( getuid( ) == 0 ) { - if ( my_err == 1 ) { - printf( "issetugid should return false \n" ); - goto test_failed_exit; + /* test issetugid - should return 1 when not root and 0 when root + * Figuring out setugid will not work in single-user mode; skip + * this test in that case. + */ + if (!g_is_single_user) { + my_err = issetugid( ); + if ( getuid( ) == 0 ) { + if ( my_err == 1 ) { + printf( "issetugid should return false \n" ); + goto test_failed_exit; + } } - } - else { - if ( my_err == 0 ) { - printf( "issetugid should return true \n" ); - goto test_failed_exit; + else { + if ( my_err == 0 ) { + printf( "issetugid should return true \n" ); + goto test_failed_exit; + } } } @@ -1550,10 +1680,10 @@ int uid_tests( void * the_argp ) /* * child process */ - uid_t my_ruid, my_euid; - uid_t my_uid, my_temp_uid; - gid_t my_gid, my_temp_gid; - au_id_t my_au_id, my_temp_au_id; + uid_t my_ruid, my_euid; + uid_t my_uid, my_temp_uid; + gid_t my_gid, my_temp_gid; + auditinfo_addr_t my_aia; my_ruid = getuid( ); my_euid = geteuid( ); @@ -1561,7 +1691,7 @@ int uid_tests( void * the_argp ) exit( 0 ); } - /* Test getauid, gettid, setauid, settid, settid_with_pid */ + /* Test getauid, gettid, setaudit_addr, settid, settid_with_pid */ /* get our current uid and gid for comparison later */ my_uid = getuid( ); my_gid = getgid( ); @@ -1628,55 +1758,35 @@ int uid_tests( void * the_argp ) exit( -1 ); } +#if !TARGET_OS_EMBEDDED /* - * test to make sure setauid doesn't cause audit info to get lost from + * test to make sure setaudit_addr doesn't cause audit info to get lost from * the credential. */ - my_err = getauid( &my_au_id ); - if (my_err != 0) { - printf( "getauid - failed with error %d - \"%s\" \n", errno, strerror( errno) ); - exit( -1 ); - } - //printf("current au_id is %d \n", my_au_id); - - my_temp_au_id = 442344; - my_err = setauid( &my_temp_au_id ); + bzero( &my_aia, sizeof(my_aia) ); + my_aia.ai_auid = 442344; + my_aia.ai_asid = AU_ASSIGN_ASID; + my_aia.ai_termid.at_type = AU_IPv4; + my_err = setaudit_addr( &my_aia, sizeof(my_aia) ); if (my_err != 0) { - printf( "setauid - failed with error %d - \"%s\" \n", errno, strerror( errno) ); + printf( "setaudit_addr - failed with error %d - \"%s\" \n", errno, strerror( errno) ); exit( -1 ); } - my_temp_au_id = 0; - my_err = getauid( &my_temp_au_id ); + my_aia.ai_auid = 0; + my_err = getaudit_addr( &my_aia, sizeof(my_aia) ); if (my_err != 0) { - printf( "getauid - failed with error %d - \"%s\" \n", errno, strerror( errno) ); + printf( "getaudit_addr - failed with error %d - \"%s\" \n", errno, strerror( errno) ); exit( -1 ); } - //printf("new au_id is %d \n", my_temp_au_id); + //printf("new audit ID is %d \n", my_aia.ai_auid); - if (my_temp_au_id != 442344) { - printf("test failed - wrong au_id was set - %d \n", my_temp_au_id); + if (my_aia.ai_auid != 442344) { + printf("test failed - wrong audit ID was set - %d \n", my_aia.ai_auid); exit( -1 ); } +#endif - my_err = setauid( &my_au_id ); - if (my_err != 0) { - printf( "setauid - failed with error %d - \"%s\" \n", errno, strerror( errno) ); - exit( -1 ); - } - - my_temp_au_id = 0; - my_err = getauid( &my_temp_au_id ); - if (my_err != 0) { - printf( "getauid - failed with error %d - \"%s\" \n", errno, strerror( errno) ); - exit( -1 ); - } - - if (my_temp_au_id != my_au_id) { - printf("test failed - wrong au_id was set - %d \n", my_temp_au_id); - exit( -1 ); - } - /* change real uid and effective uid to current euid */ my_err = setuid( my_euid ); if ( my_err == -1 ) { @@ -1751,7 +1861,8 @@ test_passed_exit: int mknod_sync_test( void * the_argp ) { int my_err; - char * my_pathp = NULL; + char * my_pathp = NULL; + kern_return_t my_kr; if ( g_skip_setuid_tests != 0 ) { printf("\t skipping this test \n"); @@ -1759,11 +1870,11 @@ int mknod_sync_test( void * the_argp ) goto test_passed_exit; } - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } *my_pathp = 0x00; strcat( my_pathp, "/dev/" ); @@ -1791,8 +1902,8 @@ test_failed_exit: test_passed_exit: if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); } @@ -1808,12 +1919,13 @@ int chflags_fchflags_test( void * the_argp ) u_int my_flags; char * my_pathp = NULL; struct stat my_sb; + kern_return_t my_kr; - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); @@ -1887,8 +1999,8 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); } @@ -1937,7 +2049,9 @@ int execve_kill_vfork_test( void * the_argp ) } if (get_architecture() == INTEL) { - if (bits == 64 && sizeof(long) == 8) { + struct stat sb; + + if (bits == 64 && sizeof(long) == 8) { /* * Running on x86_64 hardware and running in 64-bit mode. * Check cases 1, 2, 3 and fork a child to check 4, 5, 6. @@ -1959,17 +2073,12 @@ int execve_kill_vfork_test( void * the_argp ) argvs[0] = "launch-i386"; if (do_execve_test("helpers/launch-i386", argvs, NULL, 1) != 0) goto test_failed_exit; - /* Test posix_spawn for ppc64 (should fail), i386, x86_64, and ppc (should succeed) */ + /* Test posix_spawn for i386, x86_64 (should succeed) */ errmsg = NULL; - if (do_spawn_test(CPU_TYPE_POWERPC64, 1)) - goto test_failed_exit; if (do_spawn_test(CPU_TYPE_I386, 0)) goto test_failed_exit; if (do_spawn_test(CPU_TYPE_X86_64, 0)) goto test_failed_exit; - if (do_spawn_test(CPU_TYPE_POWERPC, 0)) - goto test_failed_exit; - } else if (bits == 64 && sizeof(long) == 4) { /* @@ -1993,16 +2102,12 @@ int execve_kill_vfork_test( void * the_argp ) argvs[0] = "launch-x86_64"; if (do_execve_test("helpers/launch-x86_64", argvs, NULL, 1) != 0) goto test_failed_exit; - /* Test posix_spawn for ppc64 (should fail), i386, x86_64, and ppc (should succeed) */ + /* Test posix_spawn for i386, x86_64 (should succeed) */ errmsg = NULL; - if (do_spawn_test(CPU_TYPE_POWERPC64, 1)) - goto test_failed_exit; if (do_spawn_test(CPU_TYPE_I386, 0)) goto test_failed_exit; if (do_spawn_test(CPU_TYPE_X86_64, 0)) goto test_failed_exit; - if (do_spawn_test(CPU_TYPE_POWERPC, 0)) - goto test_failed_exit; } else if (bits == 32) { /* Running on i386 hardware. Check cases 4. */ @@ -2010,108 +2115,25 @@ int execve_kill_vfork_test( void * the_argp ) argvs[0] = "sleep-i386"; if (do_execve_test("helpers/sleep-i386", argvs, NULL, 1)) goto test_failed_exit; - /* Test posix_spawn for x86_64 (should fail), i386, and ppc (should succeed) */ + /* Test posix_spawn for x86_64 (should fail), i386 (should succeed) */ errmsg = NULL; if (do_spawn_test(CPU_TYPE_X86_64, 1)) goto test_failed_exit; if (do_spawn_test(CPU_TYPE_I386, 0)) goto test_failed_exit; - if (do_spawn_test(CPU_TYPE_POWERPC, 0)) - goto test_failed_exit; - } - } - else if (get_architecture() == POWERPC) { - if (bits == 64 && sizeof(long) == 8) { - /* - * Running on PPC64 hardware and running in 64-bit mode. - * Check cases 1, 2, 3 and fork a child to check 4, 5, 6. - */ - errmsg = "execve failed: from ppc64 forking and exec()ing 64-bit ppc process w/ 4G pagezero.\n"; - argvs[0] = "sleep-ppc64-4G"; - if (do_execve_test("helpers/sleep-ppc64-4G", argvs, NULL, 1)) goto test_failed_exit; - - errmsg = "execve failed: from ppc64 forking and exec()ing 64-bit ppc process w/ 4K pagezero.\n"; - argvs[0] = "sleep-ppc64-4K"; - if (do_execve_test("helpers/sleep-ppc64-4K", argvs, NULL, 1)) goto test_failed_exit; - - errmsg = "execve failed: from ppc64 forking and exec()ing 32 bit ppc process.\n"; - argvs[0] = "sleep-ppc32"; - if (do_execve_test("helpers/sleep-ppc32", argvs, NULL, 1)) goto test_failed_exit; - - /* Fork off a helper process and load a 32-bit program in it to test 32->64 bit exec(). */ - errmsg = "execve failed to exec the helper process.\n"; - argvs[0] = "launch-ppc"; - if (do_execve_test("helpers/launch-ppc", argvs, NULL, 1) != 0) goto test_failed_exit; - - /* Test posix_spawn for i386 (should fail), ppc64, and ppc (should succeed) */ - errmsg = NULL; - if (do_spawn_test(CPU_TYPE_I386, 1)) - goto test_failed_exit; - if (do_spawn_test(CPU_TYPE_POWERPC64, 0)) - goto test_failed_exit; - if (do_spawn_test(CPU_TYPE_POWERPC, 0)) - goto test_failed_exit; - } - else if (bits == 64 && sizeof(long) == 4) { - /* - * Running on PPC64 hardware, but actually running in 32-bit mode. - * Check cases 4, 5, 6 and fork a child to check 1, 2, 3. - */ - errmsg = "execve failed: from ppc forking and exec()ing ppc process.\n"; - argvs[0] = "sleep-ppc32"; - if (do_execve_test("helpers/sleep-ppc32", argvs, NULL, 0)) goto test_failed_exit; - - errmsg = "execve failed: from ppc forking and exec()ing ppc64 process w/ 4G pagezero.\n"; - argvs[0] = "sleep-ppc64-4G"; - if (do_execve_test("helpers/sleep-ppc64-4G", argvs, NULL, 0)) goto test_failed_exit; - - errmsg = "execve failed: from ppc forking and exec()ing ppc64 process w/ 4K pagezero.\n"; - argvs[0] = "sleep-ppc64-4K"; - if (do_execve_test("helpers/sleep-ppc64-4K", argvs, NULL, 0)) goto test_failed_exit; - - /* Fork off a helper process and load a 64-bit program in it to test 64->32 bit exec(). */ - errmsg = "execve failed to exec the helper process.\n"; - argvs[0] = "launch-ppc"; - if (do_execve_test("helpers/launch-ppc64", argvs, NULL, 1) != 0) goto test_failed_exit; + } else if(get_architecture() == ARM) { - /* Test posix_spawn for i386 (should fail), ppc64, and ppc (should succeed) */ - errmsg = NULL; - if (do_spawn_test(CPU_TYPE_I386, 1)) - goto test_failed_exit; - if (do_spawn_test(CPU_TYPE_POWERPC64, 0)) - goto test_failed_exit; - if (do_spawn_test(CPU_TYPE_POWERPC, 0)) - goto test_failed_exit; - } - else if (bits == 32) { - /* Running on ppc hardware. Check cases 4. */ - errmsg = "execve failed: from ppc forking and exec()ing 32 bit ppc process.\n"; - argvs[0] = "sleep-ppc32"; - if (do_execve_test("helpers/sleep-ppc32", argvs, NULL, 1)) goto test_failed_exit; - /* Test posix_spawn for i386 (should fail) and ppc (should succeed) */ - errmsg = NULL; - /* when under Rosetta, this process is CPU_TYPE_POWERPC, but the system should be able to run CPU_TYPE_I386 binaries */ - if (do_spawn_test(CPU_TYPE_I386, (g_is_under_rosetta ? 0 : 1))) - goto test_failed_exit; - if (do_spawn_test(CPU_TYPE_POWERPC, 0)) - goto test_failed_exit; - } - } - else if(get_architecture() == ARM) { - if (bits == 32) { + errmsg = "execve failed: from arm forking and exec()ing arm process.\n"; + argvs[0] = "sleep-arm"; + if (do_execve_test("helpers/sleep-arm", argvs, NULL, 1)) + goto test_failed_exit; - /* Running on arm hardware. Check cases 2. */ - errmsg = "execve failed: from arm forking and exec()ing 32-bit arm process.\n"; - argvs[0] = "sleep-arm"; - if (do_execve_test("helpers/sleep-arm", argvs, NULL, 1)) - goto test_failed_exit; + /* Test posix_spawn for arm (should succeed) */ + errmsg = NULL; + if (do_spawn_test(CPU_TYPE_ARM, 0)) + goto test_failed_exit; - /* Test posix_spawn for arm (should succeed) */ - errmsg = NULL; - if (do_spawn_test(CPU_TYPE_ARM, 0)) - goto test_failed_exit; - } } else { /* Just in case someone decides we need more architectures in the future */ @@ -2152,9 +2174,12 @@ int groups_test( void * the_argp ) my_real_gid = getgid( ); my_effective_gid = getegid( ); + if ( !_prime_groups() ) { + goto test_failed_exit; + } + /* start by getting list of groups the current user belongs to */ my_orig_group_count = getgroups( NGROUPS_MAX, &my_groups[0] ); - printf("my_orig_group_count: %d\n", my_orig_group_count); if ( my_orig_group_count == -1 || my_orig_group_count < 1 ) { printf( "getgroups call failed. got errno %d - %s. \n", errno, strerror( errno ) ); @@ -2188,7 +2213,6 @@ int groups_test( void * the_argp ) } my_group_count = getgroups( NGROUPS_MAX, &my_groups[0] ); - printf("my_group_count: %d\n", my_group_count); if ( my_group_count == -1 || my_group_count < 1 ) { printf( "getgroups call failed. got errno %d - %s. \n", errno, strerror( errno ) ); @@ -2286,12 +2310,13 @@ int dup_test( void * the_argp ) char * my_pathp = NULL; ssize_t my_count; char my_buffer[64]; + kern_return_t my_kr; - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); @@ -2394,38 +2419,22 @@ test_passed_exit: if ( my_newfd != -1 ) close( my_newfd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); } /* ************************************************************************************************************** - * Test profil, getrusage system calls. - * todo - how do we really test profil is working? + * Test getrusage system call. * ************************************************************************************************************** */ -int getrusage_profil_test( void * the_argp ) +int getrusage_test( void * the_argp ) { int my_err; - char * my_bufferp = NULL; struct rusage my_rusage; - my_bufferp = (char *) malloc( (1024 * 1000) ); - if ( my_bufferp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } - bzero( (void *)my_bufferp, (1024 * 1000) ); - - /* turn on profiling */ - my_err = profil( my_bufferp, (1024 * 1000), 0, 32768 ); - if ( my_err == -1 ) { - printf( "profil failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } - my_err = getrusage( RUSAGE_SELF, &my_rusage ); if ( my_err == -1 ) { printf( "getrusage failed with error %d - \"%s\" \n", errno, strerror( errno) ); @@ -2442,13 +2451,6 @@ int getrusage_profil_test( void * the_argp ) goto test_failed_exit; } - /* turn off profiling (scale value of 0 turns off profiling) */ - my_err = profil( my_bufferp, (1024 * 1000), 0, 0 ); - if ( my_err == -1 ) { - printf( "profil failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } - my_err = 0; goto test_passed_exit; @@ -2456,9 +2458,6 @@ test_failed_exit: my_err = -1; test_passed_exit: - if ( my_bufferp != NULL ) { - free( my_bufferp ); - } return( my_err ); } @@ -2493,12 +2492,13 @@ int signals_test( void * the_argp ) int my_fd = -1; char * my_pathp = NULL; pid_t my_pid, my_wait_pid; + kern_return_t my_kr; - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); @@ -2715,7 +2715,7 @@ int signals_test( void * the_argp ) goto test_failed_exit; } - if ( WIFEXITED( my_status ) && WEXITSTATUS( my_status ) != 0 ) { + if ( WIFSIGNALED( my_status ) || ( WIFEXITED( my_status ) && WEXITSTATUS( my_status ) != 0 ) ) { goto test_failed_exit; } @@ -2729,8 +2729,8 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); } @@ -2743,6 +2743,7 @@ int getlogin_setlogin_test( void * the_argp ) { int my_err, my_status; pid_t my_pid, my_wait_pid; + kern_return_t my_kr; if ( g_skip_setuid_tests != 0 ) { printf("\t skipping this test \n"); @@ -2762,32 +2763,36 @@ int getlogin_setlogin_test( void * the_argp ) /* * child process - do getlogin and setlogin testing. */ - char * my_namep; - int my_len; + char * my_namep = NULL; + int my_len; char * my_new_namep = NULL; - + my_namep = getlogin( ); if ( my_namep == NULL ) { printf( "getlogin returned NULL name pointer \n" ); my_err = -1; goto exit_child; } + my_len = strlen( my_namep ) + 4; - my_new_namep = (char *) malloc( my_len ); - if ( my_new_namep == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - my_err = -1; + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_new_namep, my_len, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + my_err = -1; goto exit_child; - } + } + bzero( (void *)my_new_namep, my_len ); + strcat( my_new_namep, my_namep ); strcat( my_new_namep, "2" ); + /* set new name */ my_err = setlogin( my_new_namep ); if ( my_err == -1 ) { - printf( "setlogin failed with error %d - \"%s\" \n", errno, strerror( errno) ); + printf( "When setting new login name, setlogin failed with error %d - \"%s\" \n", errno, strerror( errno) ); my_err = -1; goto exit_child; } @@ -2799,16 +2804,29 @@ int getlogin_setlogin_test( void * the_argp ) my_err = -1; goto exit_child; } + if ( memcmp( my_namep, my_new_namep, strlen( my_new_namep ) ) != 0 ) { printf( "setlogin failed to set the new name \n" ); my_err = -1; goto exit_child; } + + /* reset to original name */ + my_len = strlen ( my_namep ); + my_namep[ my_len - 1 ] = '\0'; + + my_err = setlogin( my_namep ); + if ( my_err == -1 ) { + printf( "When resetting login name, setlogin failed with error %d - \"%s\" \n", errno, strerror( errno) ); + my_err = -1; + goto exit_child; + } + my_err = 0; exit_child: if ( my_new_namep != NULL ) { - free( my_new_namep ); + vm_deallocate(mach_task_self(), (vm_address_t)my_new_namep, my_len); } exit( my_err ); } @@ -2841,13 +2859,16 @@ test_passed_exit: */ int acct_test( void * the_argp ) { - int my_err, my_status; - int my_fd = -1; - char * my_pathp = NULL; + int my_err, my_status; + int my_fd = -1; + char * my_pathp = NULL; struct acct * my_acctp; - pid_t my_pid, my_wait_pid; - ssize_t my_count; - char my_buffer[ (sizeof(struct acct) + 32) ]; + pid_t my_pid, my_wait_pid; + ssize_t my_count; + char my_buffer[ (sizeof(struct acct) + 32) ]; + kern_return_t my_kr; + int acct_record_found; + char * test_bin_name = NULL; if ( g_skip_setuid_tests != 0 ) { printf("\t skipping this test \n"); @@ -2855,11 +2876,12 @@ int acct_test( void * the_argp ) goto test_passed_exit; } - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); strcat( my_pathp, "/" ); @@ -2886,10 +2908,14 @@ int acct_test( void * the_argp ) goto test_failed_exit; } if ( my_pid == 0 ) { + char *argv[2]; /* supply valid argv array to execv() */ + argv[0] = "/usr/bin/true"; + argv[1] = 0; + /* * child process - do a little work then exit. */ - my_err = execv( "/usr/bin/true", (char **) 0 ); + my_err = execv( argv[0], argv); exit( 0 ); } @@ -2903,10 +2929,11 @@ int acct_test( void * the_argp ) } if ( WIFEXITED( my_status ) && WEXITSTATUS( my_status ) != 0 ) { + printf("unexpected child exit status for accounting test load: %d\n", WEXITSTATUS( my_status)); goto test_failed_exit; } - /* diable process accounting */ + /* disable process accounting */ my_err = acct( NULL ); if ( my_err == -1 ) { printf( "acct failed with error %d - \"%s\" \n", errno, strerror( errno) ); @@ -2922,38 +2949,45 @@ int acct_test( void * the_argp ) lseek( my_fd, 0, SEEK_SET ); bzero( (void *)&my_buffer[0], sizeof(my_buffer) ); - my_count = read( my_fd, &my_buffer[0], sizeof(struct acct) ); - if ( my_count == -1 ) { - printf( "read call failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + acct_record_found = 0; + test_bin_name = "true"; - my_acctp = (struct acct *) &my_buffer[0]; - /* first letters in ac_comm should match the name of the executable */ - if ( getuid( ) != my_acctp->ac_uid || getgid( ) != my_acctp->ac_gid || - my_acctp->ac_comm[0] != 't' || my_acctp->ac_comm[1] != 'r' ) { - if (g_is_under_rosetta) { - // on x86 systems, data written by kernel to accounting info file is little endian; - // but Rosetta processes expects it to be big endian; so swap the uid for our test - if ( getuid( ) != OSSwapInt32(my_acctp->ac_uid) || - getgid( ) != OSSwapInt32(my_acctp->ac_gid) || - my_acctp->ac_comm[0] != 't' || - my_acctp->ac_comm[1] != 'r' ) { - printf( "accounting data does not look correct under Rosetta.\n" ); - } - else { - // is cool under Rosetta - my_err = 0; - goto test_passed_exit; - } - } - else { - printf( "accounting data does not look correct \n" ); - } - goto test_failed_exit; - } - my_err = 0; - goto test_passed_exit; + while(1) { + + my_count = read( my_fd, &my_buffer[0], sizeof(struct acct) ); + + if ( my_count == -1 ) { + printf( "read call failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + + if ( my_count < sizeof(struct acct)) { + /* Indicates EOF or misaligned file size */ + printf("Reached end of accounting records with last read count: %d\n", my_count); + break; + } + + my_acctp = (struct acct *) &my_buffer[0]; + /* first letters in ac_comm should match the name of the executable */ + if ( (getuid() == my_acctp->ac_uid) && (getgid() == my_acctp->ac_gid) && + (!strncmp(my_acctp->ac_comm, test_bin_name, strlen(test_bin_name))) ) { + /* Expected accounting record found */ + acct_record_found = 1; + break; + } + + } + + if (acct_record_found) { + my_err = 0; + goto test_passed_exit; + } else { + printf( "------------------------\n" ); + printf( "Expected Accounting Record for child process %s not found\n", test_bin_name ); + printf( "Expected uid: %lu Expected gid: %lu\n" , (unsigned long) getuid(), (unsigned long) getgid() ); + printf( "Account file path: %s\n", my_pathp ); + goto test_failed_exit; + } test_failed_exit: my_err = -1; @@ -2962,12 +2996,33 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); } +void print_acct_debug_strings( char * my_ac_comm ) +{ + char my_cmd_str[11]; /* sizeof(acct_cmd) + 1 for '\0' if acct_cmd is bogus */ + char my_hex_str[128]; + int i; + + my_hex_str[0] = '\0'; + for(i = 0; i < 10; i++) + { + sprintf( my_hex_str, "%s \'0x%x\' ", my_hex_str, my_ac_comm[i]); + } + + memccpy(my_cmd_str, my_ac_comm, '\0', 10); + my_cmd_str[10] = '\0'; /* In case ac_comm was bogus */ + + + printf( "my_acctp->ac_comm = \"%s\" (should begin with: \"tr\")\n", my_cmd_str); + printf( "my_acctp->ac_comm = \"%s\"\n", my_hex_str); + printf( "------------------------\n" ); +} + /* ************************************************************************************************************** * Test ioctl system calls. @@ -3050,12 +3105,14 @@ int mkdir_rmdir_umask_test( void * the_argp ) char * my_pathp = NULL; mode_t my_orig_mask; struct stat my_sb; + kern_return_t my_kr; + + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); strcat( my_pathp, "/" ); @@ -3105,8 +3162,8 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - rmdir( my_pathp ); - free( my_pathp ); + rmdir( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } if ( did_umask != 0 ) { umask( my_orig_mask ); @@ -3124,6 +3181,7 @@ int chroot_test( void * the_argp ) int my_err, my_status; pid_t my_pid, my_wait_pid; char * my_pathp = NULL; + kern_return_t my_kr; if ( g_skip_setuid_tests != 0 ) { printf("\t skipping this test \n"); @@ -3131,11 +3189,12 @@ int chroot_test( void * the_argp ) goto test_passed_exit; } - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); strcat( my_pathp, "/" ); @@ -3213,7 +3272,7 @@ test_passed_exit: if ( my_err != 0 ) { printf( "rmdir failed with error %d - \"%s\" path %p\n", errno, strerror( errno), my_pathp ); } - free( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); } @@ -3300,13 +3359,16 @@ int fcntl_test( void * the_argp ) { int my_err, my_result, my_tmep; int my_fd = -1; + int my_newfd = -1; char * my_pathp = NULL; + kern_return_t my_kr; + + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); strcat( my_pathp, "/" ); @@ -3354,7 +3416,61 @@ int fcntl_test( void * the_argp ) printf( "fcntl - F_SETFD failed to set FD_CLOEXEC correctly!!! \n" ); goto test_failed_exit; } - + + /* dup it to a new fd with FD_CLOEXEC forced on */ + + my_result = fcntl( my_fd, F_DUPFD_CLOEXEC, 0); + if ( my_result == -1 ) { + printf( "fcntl - F_DUPFD_CLOEXEC - failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + my_newfd = my_result; + + /* check to see that it too is marked with FD_CLOEXEC */ + + my_result = fcntl( my_newfd, F_GETFD, 0); + if ( my_result == -1 ) { + printf( "fcntl - F_GETFD - failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + if ( (my_result & FD_CLOEXEC) == 0 ) { + printf( "fcntl - F_DUPFD_CLOEXEC failed to set FD_CLOEXEC!!! \n" ); + goto test_failed_exit; + } + + close( my_newfd ); + my_newfd = -1; + +#if !TARGET_OS_EMBEDDED /* This section of the test is specific for the desktop platform, refer */ + /* While we're here, dup it via an open of /dev/fd/ .. */ + + { + char devfdpath[PATH_MAX]; + + (void) snprintf( devfdpath, sizeof (devfdpath), + "/dev/fd/%u", my_fd ); + my_result = open( devfdpath, O_RDONLY | O_CLOEXEC ); + } + if ( my_result == -1 ) { + printf( "open call failed on /dev/fd/%u with error %d - \"%s\" \n", my_fd, errno, strerror( errno) ); + goto test_failed_exit; + } + my_newfd = my_result; + + /* check to see that it too is marked with FD_CLOEXEC */ + + my_result = fcntl( my_newfd, F_GETFD, 0); + if ( my_result == -1 ) { + printf( "fcntl - F_GETFD - failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + if ( (my_result & FD_CLOEXEC) == 0 ) { + printf( "fcntl - O_CLOEXEC open of /dev/fd/%u failed to set FD_CLOEXEC!!! \n", my_fd ); + goto test_failed_exit; + } + close ( my_newfd ); + my_newfd = -1; +#endif my_err = 0; goto test_passed_exit; @@ -3362,11 +3478,13 @@ test_failed_exit: my_err = -1; test_passed_exit: + if ( my_newfd != -1) + close ( my_newfd ); if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); } @@ -3441,6 +3559,7 @@ int time_tests( void * the_argp ) struct timeval my_utimes[4]; struct timezone my_tz; struct stat my_sb; + kern_return_t my_kr; if ( g_skip_setuid_tests != 0 ) { printf( "\t skipping this test \n" ); @@ -3448,11 +3567,12 @@ int time_tests( void * the_argp ) goto test_passed_exit; } - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); strcat( my_pathp, "/" ); @@ -3567,8 +3687,8 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); } @@ -3584,12 +3704,14 @@ int rename_test( void * the_argp ) char * my_new_pathp = NULL; ino_t my_file_id; struct stat my_sb; + kern_return_t my_kr; + + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); strcat( my_pathp, "/" ); @@ -3600,11 +3722,12 @@ int rename_test( void * the_argp ) goto test_failed_exit; } - my_new_pathp = (char *) malloc( PATH_MAX ); - if ( my_new_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_new_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + *my_new_pathp = 0x00; strcat( my_new_pathp, &g_target_path[0] ); strcat( my_new_pathp, "/" ); @@ -3656,12 +3779,12 @@ test_failed_exit: test_passed_exit: if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } if ( my_new_pathp != NULL ) { - remove( my_new_pathp ); - free( my_new_pathp ); + remove( my_new_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_new_pathp, PATH_MAX); } return( my_err ); } @@ -3676,12 +3799,14 @@ int locking_test( void * the_argp ) pid_t my_pid, my_wait_pid; int my_fd = -1; char * my_pathp = NULL; + kern_return_t my_kr; + + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); strcat( my_pathp, "/" ); @@ -3776,8 +3901,8 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); } @@ -3794,12 +3919,14 @@ int mkfifo_test( void * the_argp ) char * my_pathp = NULL; ssize_t my_result; off_t my_current_offset; + kern_return_t my_kr; + + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); strcat( my_pathp, "/" ); @@ -3902,8 +4029,8 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); } @@ -3998,6 +4125,7 @@ int limit_tests( void * the_argp ) printf( "soft limits - current %lld should be %lld \n", my_rlimit.rlim_cur, my_current_rlimit.rlim_cur ); goto test_failed_exit; } + #if CONFORMANCE_CHANGES_IN_XNU // can't do this check until conformance changes get into xnu printf( "hard limits - current %lld should be %lld \n", my_rlimit.rlim_max, my_current_rlimit.rlim_max ); if ( my_rlimit.rlim_max != my_current_rlimit.rlim_max ) { @@ -4005,6 +4133,30 @@ int limit_tests( void * the_argp ) goto test_failed_exit; } #endif + + /* + * A test for a limit that won't fit in a signed 32 bits, a la 5414697 + * Note: my_rlimit should still have a valid rlim_max. + */ + long long biglim = 2147483649ll; /* Just over 2^31 */ + my_rlimit.rlim_cur = biglim; + my_err = setrlimit(RLIMIT_CPU, &my_rlimit); + if (my_err == -1) { + printf("failed to set large limit.\n"); + goto test_failed_exit; + } + + bzero(&my_rlimit, sizeof(struct rlimit)); + my_err = getrlimit(RLIMIT_CPU, &my_rlimit); + if (my_err == -1) { + printf("after setting large value, failed to getrlimit().\n"); + goto test_failed_exit; + } + + if (my_rlimit.rlim_cur != biglim) { + printf("didn't retrieve large limit.\n"); + goto test_failed_exit; + } } my_err = 0; @@ -4018,7 +4170,7 @@ test_passed_exit: } /* ************************************************************************************************************** - * Test getattrlist, getdirentries, getdirentriesattr, setattrlist system calls. + * Test getattrlist, getdirentriesattr, setattrlist system calls. * ************************************************************************************************************** */ struct test_attr_buf { @@ -4052,6 +4204,7 @@ int directory_tests( void * the_argp ) struct attrlist my_attrlist; test_attr_buf my_attr_buf[4]; struct statfs my_statfs_buf; + kern_return_t my_kr; /* need to know type of file system */ my_err = statfs( &g_target_path[0], &my_statfs_buf ); @@ -4063,17 +4216,18 @@ int directory_tests( void * the_argp ) is_ufs = 1; } - my_bufp = (char *) malloc( (1024 * 5) ); - if ( my_bufp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } - - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_bufp, (1024 * 5), VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); strcat( my_pathp, "/" ); @@ -4094,37 +4248,6 @@ int directory_tests( void * the_argp ) printf( "open failed with error %d - \"%s\" \n", errno, strerror( errno) ); goto test_failed_exit; } - - done = found_it = 0; - while ( done == 0 ) { - int my_result, i; - struct dirent * my_dirent_p; - - my_result = getdirentries( my_fd, my_bufp, (1024 * 5), &my_base ); - if ( my_result <= 0 ) - break; - for ( i = 0; i < my_result; ) { - my_dirent_p = (struct dirent *) (my_bufp + i); -#if DEBUG - printf( "d_ino %d d_reclen %d d_type %d d_namlen %d \"%s\" \n", - my_dirent_p->d_ino, my_dirent_p->d_reclen, my_dirent_p->d_type, - my_dirent_p->d_namlen, &my_dirent_p->d_name[0] ); -#endif - - i += my_dirent_p->d_reclen; - /* validate results by looking for our test file */ - if ( my_dirent_p->d_type == DT_REG && my_dirent_p->d_ino != 0 && - strlen( my_file_namep ) == my_dirent_p->d_namlen && - memcmp( &my_dirent_p->d_name[0], my_file_namep, my_dirent_p->d_namlen ) == 0 ) { - done = found_it = 1; - break; - } - } - } - if ( found_it == 0 ) { - printf( "getdirentries failed to find test file. \n" ); - goto test_failed_exit; - } /* test get/setattrlist */ memset( &my_attrlist, 0, sizeof(my_attrlist) ); @@ -4206,11 +4329,11 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } if ( my_bufp != NULL ) { - free( my_bufp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_bufp, (1024 * 5)); } return( my_err ); } @@ -4229,6 +4352,7 @@ int exchangedata_test( void * the_argp ) ssize_t my_result; char my_buffer[16]; struct statfs my_statfs_buf; + kern_return_t my_kr; /* need to know type of file system */ my_err = statfs( &g_target_path[0], &my_statfs_buf ); @@ -4242,11 +4366,12 @@ int exchangedata_test( void * the_argp ) goto test_passed_exit; } - my_file1_pathp = (char *) malloc( PATH_MAX ); - if ( my_file1_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_file1_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + *my_file1_pathp = 0x00; strcat( my_file1_pathp, &g_target_path[0] ); strcat( my_file1_pathp, "/" ); @@ -4268,11 +4393,12 @@ int exchangedata_test( void * the_argp ) goto test_failed_exit; } - my_file2_pathp = (char *) malloc( PATH_MAX ); - if ( my_file2_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_file2_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + *my_file2_pathp = 0x00; strcat( my_file2_pathp, &g_target_path[0] ); strcat( my_file2_pathp, "/" ); @@ -4333,14 +4459,14 @@ test_passed_exit: if ( my_fd1 != -1 ) close( my_fd1 ); if ( my_file1_pathp != NULL ) { - remove( my_file1_pathp ); - free( my_file1_pathp ); + remove( my_file1_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_file1_pathp, PATH_MAX); } if ( my_fd2 != -1 ) close( my_fd2 ); if ( my_file2_pathp != NULL ) { - remove( my_file2_pathp ); - free( my_file2_pathp ); + remove( my_file2_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_file2_pathp, PATH_MAX); } return( my_err ); } @@ -4373,10 +4499,12 @@ typedef struct packed_result packed_result; typedef struct packed_result * packed_result_p; #define MAX_MATCHES 10 +#define MAX_EBUSY_RETRIES 5 int searchfs_test( void * the_argp ) { - int my_err, my_items_found = 0; +#if !TARGET_OS_EMBEDDED + int my_err, my_items_found = 0, my_ebusy_count; char * my_pathp = NULL; unsigned long my_matches; unsigned long my_search_options; @@ -4387,6 +4515,7 @@ int searchfs_test( void * the_argp ) struct packed_attr_ref my_info2; packed_result my_result_buffer[ MAX_MATCHES ]; struct statfs my_statfs_buf; + kern_return_t my_kr; /* need to know type of file system */ my_err = statfs( &g_target_path[0], &my_statfs_buf ); @@ -4400,11 +4529,12 @@ int searchfs_test( void * the_argp ) goto test_passed_exit; } - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); strcat( my_pathp, "/" ); @@ -4433,9 +4563,14 @@ int searchfs_test( void * the_argp ) printf( "failed to create a test file name in \"%s\" \n", my_pathp ); goto test_failed_exit; } - + + /* EBUSY count updated below the catalogue_changed label */ + my_ebusy_count = 0; + +catalogue_changed: /* search target volume for all file system objects with "foo" in the name */ /* Set up the attributes we're searching on. */ + my_items_found = 0; /* Set this here in case we're completely restarting */ my_search_blk.searchattrs.bitmapcount = ATTR_BIT_MAP_COUNT; my_search_blk.searchattrs.reserved = 0; my_search_blk.searchattrs.commonattr = ATTR_CMN_NAME; @@ -4524,6 +4659,11 @@ int searchfs_test( void * the_argp ) break; } } + + /* EBUSY indicates catalogue change; retry a few times. */ + if ((my_err == EBUSY) && (my_ebusy_count++ < MAX_EBUSY_RETRIES)) { + goto catalogue_changed; + } if ( !(my_err == 0 || my_err == EAGAIN) ) { printf( "searchfs failed with error %d - \"%s\" \n", my_err, strerror( my_err) ); } @@ -4554,10 +4694,14 @@ test_passed_exit: remove( my_pathp ); *my_ptr = 0x00; strcat( my_pathp, "xxxfoo" ); - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); +#else + printf( "\t--> Not supported on EMBEDDED TARGET\n" ); + return 0; +#endif } @@ -4569,7 +4713,6 @@ test_passed_exit: */ int aio_tests( void * the_argp ) { -#if !TARGET_OS_EMBEDDED int my_err, i; char * my_pathp; struct aiocb * my_aiocbp; @@ -4580,6 +4723,7 @@ int aio_tests( void * the_argp ) struct aiocb * my_aiocb_list[ AIO_TESTS_OUR_COUNT ]; struct aiocb my_aiocbs[ AIO_TESTS_OUR_COUNT ]; char * my_file_paths[ AIO_TESTS_OUR_COUNT ]; + kern_return_t my_kr; /* set up to have the ability to fire off up to AIO_TESTS_OUR_COUNT async IOs at once */ memset( &my_fd_list[0], 0xFF, sizeof( my_fd_list ) ); @@ -4587,17 +4731,18 @@ int aio_tests( void * the_argp ) memset( &my_aiocb_list[0], 0x00, sizeof( my_aiocb_list ) ); memset( &my_file_paths[0], 0x00, sizeof( my_file_paths ) ); for ( i = 0; i < AIO_TESTS_OUR_COUNT; i++ ) { - my_buffers[ i ] = malloc( AIO_TESTS_BUFFER_SIZE ); - if ( my_buffers[ i ] == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_buffers[ i ], AIO_TESTS_BUFFER_SIZE, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_file_paths[ i ], PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } - my_file_paths[ i ] = malloc( PATH_MAX ); - if ( my_file_paths[ i ] == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } my_pathp = my_file_paths[ i ]; *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); @@ -4822,216 +4967,16 @@ test_passed_exit: my_fd_list[ i ] = -1; } if ( my_file_paths[ i ] != NULL ) { - remove( my_file_paths[ i ] ); - free( my_file_paths[ i ] ); + remove( my_file_paths[ i ] ); + vm_deallocate(mach_task_self(), (vm_address_t)my_file_paths[ i ], PATH_MAX); my_file_paths[ i ] = NULL; } if ( my_buffers[ i ] != NULL ) { - free( my_buffers[ i ] ); + vm_deallocate(mach_task_self(), (vm_address_t)my_buffers[ i ], AIO_TESTS_BUFFER_SIZE); my_buffers[ i ] = NULL; } } return( my_err ); -#else - printf( "\t--> Not supported on EMBEDDED TARGET\n" ); - return 0; -#endif -} - - -/* ************************************************************************************************************** - * Test kevent, kqueue system calls. - * ************************************************************************************************************** - */ -int kqueue_tests( void * the_argp ) -{ - int my_err, my_status; - int my_kqueue = -1; - int my_fd = -1; - char * my_pathp = NULL; - pid_t my_pid, my_wait_pid; - size_t my_count; - int my_sockets[ 2 ] = {-1, -1}; - struct kevent my_kevent; - struct timespec my_timeout; - char my_buffer[ 16 ]; - - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } - *my_pathp = 0x00; - strcat( my_pathp, &g_target_path[0] ); - strcat( my_pathp, "/" ); - - /* create a test file */ - my_err = create_random_name( my_pathp, 1 ); - if ( my_err != 0 ) { - goto test_failed_exit; - } - - my_fd = open( my_pathp, O_RDWR, 0 ); - if ( my_fd == -1 ) { - printf( "open call failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } - - my_err = socketpair( AF_UNIX, SOCK_STREAM, 0, &my_sockets[0] ); - if ( my_err == -1 ) { - printf( "socketpair failed with errno %d - %s \n", errno, strerror( errno ) ); - goto test_failed_exit; - } - - /* fork here and use pipe to communicate */ - my_pid = fork( ); - if ( my_pid == -1 ) { - printf( "fork failed with errno %d - %s \n", errno, strerror( errno ) ); - goto test_failed_exit; - } - else if ( my_pid == 0 ) { - /* - * child process - tell parent we are ready to go. - */ - my_count = write( my_sockets[1], "r", 1 ); - if ( my_count == -1 ) { - printf( "write call failed. got errno %d - %s. \n", errno, strerror( errno ) ); - exit( -1 ); - } - - my_count = read( my_sockets[1], &my_buffer[0], 1 ); - if ( my_count == -1 ) { - printf( "read call failed with error %d - \"%s\" \n", errno, strerror( errno) ); - exit( -1 ); - } - if ( my_buffer[0] != 'g' ) { - printf( "read call on socket failed to get \"all done\" message \n" ); - exit( -1 ); - } - - /* now do some work that will trigger events our parent will track */ - my_count = write( my_fd, "11111111", 8 ); - if ( my_count == -1 ) { - printf( "write call failed with error %d - \"%s\" \n", errno, strerror( errno) ); - exit( -1 ); - } - - my_err = unlink( my_pathp ); - if ( my_err == -1 ) { - printf( "unlink failed with error %d - \"%s\" \n", errno, strerror( errno) ); - exit( -1 ); - } - - /* wait for parent to tell us to exit */ - my_count = read( my_sockets[1], &my_buffer[0], 1 ); - if ( my_count == -1 ) { - printf( "read call failed with error %d - \"%s\" \n", errno, strerror( errno) ); - exit( -1 ); - } - if ( my_buffer[0] != 'e' ) { - printf( "read call on socket failed to get \"all done\" message \n" ); - exit( -1 ); - } - exit(0); - } - - /* parent process - wait for child to spin up */ - my_count = read( my_sockets[0], &my_buffer[0], sizeof(my_buffer) ); - if ( my_count == -1 ) { - printf( "read call failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } - if ( my_buffer[0] != 'r' ) { - printf( "read call on socket failed to get \"ready to go message\" \n" ); - goto test_failed_exit; - } - - /* set up a kqueue and register for some events */ - my_kqueue = kqueue( ); - if ( my_kqueue == -1 ) { - printf( "kqueue call failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } - - /* look for our test file to get unlinked or written to */ - EV_SET( &my_kevent, my_fd, EVFILT_VNODE, (EV_ADD | EV_CLEAR), (NOTE_DELETE | NOTE_WRITE), 0, 0 ); - - my_timeout.tv_sec = 0; - my_timeout.tv_nsec = 0; - my_err = kevent( my_kqueue, &my_kevent, 1, NULL, 0, &my_timeout); - if ( my_err == -1 ) { - printf( "kevent call to register events failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } - - /* tell child to get to work */ - my_count = write( my_sockets[0], "g", 1 ); - if ( my_count == -1 ) { - printf( "write call failed. got errno %d - %s. \n", errno, strerror( errno ) ); - goto test_failed_exit; - } - - /* go get vnode events */ - EV_SET( &my_kevent, my_fd, EVFILT_VNODE, (EV_CLEAR), 0, 0, 0 ); - my_err = kevent( my_kqueue, NULL, 0, &my_kevent, 1, NULL ); - if ( my_err == -1 ) { - printf( "kevent call to get vnode events failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } - if ( my_err == 0 ) { - printf( "kevent call to get vnode events did not return any when it should have \n" ); - goto test_failed_exit; - } - if ( (my_kevent.fflags & (NOTE_DELETE | NOTE_WRITE)) == 0 ) { - printf( "kevent call to get vnode events did not return NOTE_DELETE or NOTE_WRITE \n" ); - printf( "fflags 0x%02X \n", my_kevent.fflags ); - goto test_failed_exit; - } - - /* tell child to get to exit */ - my_count = write( my_sockets[0], "e", 1 ); - if ( my_count == -1 ) { - printf( "write call failed. got errno %d - %s. \n", errno, strerror( errno ) ); - goto test_failed_exit; - } - - my_wait_pid = wait4( my_pid, &my_status, 0, NULL ); - if ( my_wait_pid == -1 ) { - printf( "wait4 failed with errno %d - %s \n", errno, strerror( errno ) ); - goto test_failed_exit; - } - - /* wait4 should return our child's pid when it exits */ - if ( my_wait_pid != my_pid ) { - printf( "wait4 did not return child pid - returned %d should be %d \n", my_wait_pid, my_pid ); - goto test_failed_exit; - } - - if ( WIFEXITED( my_status ) && WEXITSTATUS( my_status ) != 0 ) { - printf( "wait4 returned wrong exit status - 0x%02X \n", my_status ); - goto test_failed_exit; - } - - my_err = 0; - goto test_passed_exit; - -test_failed_exit: - my_err = -1; - -test_passed_exit: - if ( my_sockets[0] != -1 ) - close( my_sockets[0] ); - if ( my_sockets[1] != -1 ) - close( my_sockets[1] ); - if ( my_kqueue != -1 ) - close( my_kqueue ); - if ( my_fd != -1 ) - close( my_fd ); - if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); - } - return( my_err ); } @@ -5144,6 +5089,149 @@ test_passed_exit: } + +/* ************************************************************************************************************** + * Test execution from data and stack areas. + * ************************************************************************************************************** + */ +int data_exec_tests( void * the_argp ) +{ + int my_err = 0; + int arch, bits; + posix_spawnattr_t attrp; + char *argv[] = { "helpers/data_exec32nonxspawn", NULL }; + + int my_pid, my_status, ret; + + if ((arch = get_architecture()) == -1) { + printf("data_exec_test: couldn't determine architecture\n"); + goto test_failed_exit; + } + + bits = get_bits(); + + /* + * If the machine is 64-bit capable, run both the 32 and 64 bit versions of the test. + * Otherwise, just run the 32-bit version. + */ + + if (arch == INTEL) { + if (bits == 64) { + if (system("arch -arch x86_64 helpers/data_exec") != 0) { + printf("data_exec-x86_64 failed\n"); + goto test_failed_exit; + } + } + + if (system("arch -arch i386 helpers/data_exec") != 0) { + printf("data_exec-i386 failed\n"); + goto test_failed_exit; + } + + posix_spawnattr_init(&attrp); + posix_spawnattr_setflags(&attrp, _POSIX_SPAWN_ALLOW_DATA_EXEC ); + ret = posix_spawn(&my_pid, "helpers/data_exec32nonxspawn", NULL, &attrp, argv, NULL); + if (ret) { + printf("data_exec-i386 failed in posix_spawn %s\n", strerror(errno)); + goto test_failed_exit; + } + ret = wait4(my_pid, &my_status, 0, NULL); + if (ret == -1) { + printf("data_exec-i386 wait4 failed with errno %d - %s\n", errno, strerror(errno)); + goto test_failed_exit; + } + if (WEXITSTATUS(my_status) != 0) { + printf("data_exec-i386 _POSIX_SPAWN_ALLOW_DATA_EXEC failed\n"); + goto test_failed_exit; + } + } + + /* Add new architectures here similar to the above. */ + + goto test_passed_exit; + +test_failed_exit: + my_err = -1; + +test_passed_exit: + return my_err; +} + +/* ************************************************************************************************************** + * Test KASLR-related functionality + * ************************************************************************************************************** + */ +int kaslr_test( void * the_argp ) +{ + int result = 0; + uint64_t slide = 0; + size_t size; + int slide_enabled; + + size = sizeof(slide_enabled); + result = sysctlbyname("kern.slide", &slide_enabled, &size, NULL, 0); + if (result != 0) { + printf("sysctlbyname(\"kern.slide\") failed with errno %d\n", errno); + goto test_failed_exit; + } + + /* Test positive case first */ + size = sizeof(slide); + result = kas_info(KAS_INFO_KERNEL_TEXT_SLIDE_SELECTOR, &slide, &size); + if (result == 0) { + /* syscall supported, slide must be non-zero if running latest xnu and KASLR is enabled */ + if (slide_enabled && (slide == 0)) { + printf("kas_info(KAS_INFO_KERNEL_TEXT_SLIDE_SELECTOR, &slide, &size) reported slide of 0x%016llx\n", slide); + goto test_failed_exit; + } + if (size != sizeof(slide)) { + printf("kas_info(KAS_INFO_KERNEL_TEXT_SLIDE_SELECTOR, &slide, &size) reported size of %lu\n", size); + goto test_failed_exit; + } + } else { + /* Only ENOTSUP is allowed. If so, assume all calls will be unsupported */ + if (errno == ENOTSUP) { + return 0; + } else { + printf("kas_info(KAS_INFO_KERNEL_TEXT_SLIDE_SELECTOR, &slide, &size) returned unexpected errno (errno %d)\n", errno); + goto test_failed_exit; + } + } + + /* Negative cases for expected failures */ + size = sizeof(slide); + result = kas_info(KAS_INFO_KERNEL_TEXT_SLIDE_SELECTOR, NULL /* EFAULT */, &size); + if ((result == 0) || (errno != EFAULT)) { + printf("kas_info(KAS_INFO_KERNEL_TEXT_SLIDE_SELECTOR, NULL, &size) returned unexpected success or errno (result %d errno %d)\n", result, errno); + goto test_failed_exit; + } + + size = sizeof(slide) + 1; /* EINVAL */ + result = kas_info(KAS_INFO_KERNEL_TEXT_SLIDE_SELECTOR, NULL, &size); + if ((result == 0) || (errno != EINVAL)) { + printf("kas_info(KAS_INFO_KERNEL_TEXT_SLIDE_SELECTOR, NULL, &size+1) returned unexpected success or errno (result %d errno %d)\n", result, errno); + goto test_failed_exit; + } + + result = kas_info(KAS_INFO_KERNEL_TEXT_SLIDE_SELECTOR, NULL /* EFAULT */, NULL /* EFAULT */); + if ((result == 0) || (errno != EFAULT)) { + printf("kas_info(KAS_INFO_KERNEL_TEXT_SLIDE_SELECTOR, NULL, NULL) returned unexpected success or errno (result %d errno %d)\n", result, errno); + goto test_failed_exit; + } + + size = sizeof(slide); + result = kas_info(KAS_INFO_MAX_SELECTOR /* EINVAL */, &slide, &size); + if ((result == 0) || (errno != EINVAL)) { + printf("kas_info(KAS_INFO_MAX_SELECTOR, &slide, &size) returned unexpected success or errno (result %d errno %d)\n", result, errno); + goto test_failed_exit; + } + + return 0; + +test_failed_exit: + return -1; +} + #if TEST_SYSTEM_CALLS /* ************************************************************************************************************** @@ -5155,12 +5243,14 @@ int sample_test( void * the_argp ) int my_err; int my_fd = -1; char * my_pathp = NULL; + kern_return_t my_kr; + + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); strcat( my_pathp, "/" ); @@ -5184,8 +5274,8 @@ test_passed_exit: if ( my_fd != -1 ) close( my_fd ); if ( my_pathp != NULL ) { - remove( my_pathp ); - free( my_pathp ); + remove( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_err ); }