lib/get_high_address.c: Add tst_get_high_address.h for new API
PATCH 1/4 lib/get_high_address.c: Add tst_get_high_address.h for new API
Make sure get_high_address() can be used by new API.
--- include/old/test.h | 4 +--- include/tst_get_high_address.h | 31 +++++++++++++++++++++++++++++++ include/tst_test.h | 1 + lib/get_high_address.c | 1 + 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 include/tst_get_high_address.h
include/old/test.h +1 -3
@@ -63,6 +63,7 @@#include "old_device.h" #include "old_tmpdir.h" #include "tst_minmax.h" +#include "tst_get_high_address.h" /* * Ensure that NUMSIGS is defined.
@@ -203,9 +204,6 @@ extern int tst_count;/* lib/tst_sig.c */ void tst_sig (int fork_flag,void (*handler)(),void (*cleanup)()); -/* lib/get_high_address.c */ -char *get_high_address (void ); -/* lib/self_exec.c */ void maybe_run_child (void (*child)(),const char *fmt, ...);int self_exec (const char *argv0,const char *fmt, ...);
include/tst_get_high_address.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. +* Author: Xiao Yang <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU General Public License along +* with this program. +*/ + +#ifndef TST_GET_HIGH_ADDRESS_H__ +#define TST_GET_HIGH_ADDRESS_H__ + +/* Functions from lib/get_high_address.c */ + +char *get_high_address (void ); + +#endif /* TST_GET_HIGH_ADDRESS_H__ */
include/tst_test.h +1 -0
@@ -40,6 +40,7 @@#include "tst_clone.h" #include "tst_kernel.h" #include "tst_minmax.h" +#include "tst_get_high_address.h" /* * Reports testcase result.
lib/get_high_address.c +1 -0
@@ -33,6 +33,7 @@*/ #include <unistd.h> +#include "tst_get_high_address.h" char *get_high_address (void ) {
Signature · 1 line
1.8.3.1
PATCH 2/4 syscalls/unlink05, 06: Cleanup && Convert to new API
1) Take use of some safe macros
2) Merge unlink06 into unlink05
--- runtest/ltplite | 1 - runtest/quickhit | 2 - runtest/stress.part3 | 1 - runtest/syscalls | 1 - testcases/kernel/syscalls/.gitignore | 1 - testcases/kernel/syscalls/unlink/unlink05.c | 216 +++++++--------------------- testcases/kernel/syscalls/unlink/unlink06.c | 215 --------------------------- 7 files changed, 53 insertions(+), 384 deletions(-) delete mode 100644 testcases/kernel/syscalls/unlink/unlink06.c
runtest/ltplite +0 -1
@@ -965,7 +965,6 @@ uname03 uname03 unlink01 symlink01 -T unlink01 unlink05 unlink05 -unlink06 unlink06 unlink07 unlink07 unlink08 unlink08
runtest/quickhit +0 -2
@@ -255,8 +255,6 @@ uname01 uname01 # Basic test for uname(2) unlink05 unlink05 # Basic test for unlink(2) -unlink06 unlink06 -# unlink(2) of a FIFO unlink07 unlink07 # unlink(2) negative testcases unlink08 unlink08
runtest/stress.part3 +0 -1
@@ -841,7 +841,6 @@ uname03 uname03 unlink01 symlink01 -T unlink01 unlink05 unlink05 -unlink06 unlink06 unlink07 unlink07 unlink08 unlink08
runtest/syscalls +0 -1
@@ -1384,7 +1384,6 @@ cve-2012-0957 cve-2012-0957 unlink01 symlink01 -T unlink01 unlink05 unlink05 -unlink06 unlink06 unlink07 unlink07 unlink08 unlink08
testcases/kernel/syscalls/.gitignore +0 -1
@@ -1083,7 +1083,6 @@ /uname/uname02 /uname/uname03 /unlink/unlink05 -/unlink/unlink06 /unlink/unlink07 /unlink/unlink08 /unlinkat/unlinkat01
testcases/kernel/syscalls/unlink/unlink05.c +53 -163
235 lines not on this page · raw message
testcases/kernel/syscalls/unlink/unlink06.c deleted +0 -215
215 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 3/4 syscalls/unlink07: Cleanup && Convert to new API
In reply to Xiao Yang1) Take use of some safe macros
2) Remove unused code
--- testcases/kernel/syscalls/unlink/unlink07.c | 306 +++++----------------------- 1 file changed, 52 insertions(+), 254 deletions(-)
testcases/kernel/syscalls/unlink/unlink07.c +52 -254
@@ -28,281 +28,79 @@* For further information regarding this notice, see: * * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ -* */ -/* $Id: unlink07.c,v 1.8 2009/11/02 13:57:19 subrata_modak Exp $ */ -/********************************************************** -* -* OS Test - Silicon Graphics, Inc. -* -* TEST IDENTIFIER : unlink07 -* -* EXECUTED BY : anyone -* -* TEST TITLE : unlink(2) negative testcases -* -* PARENT DOCUMENT : usctpl01 -* -* TEST CASE TOTAL : 1 -* -* WALL CLOCK TIME : 1 -* -* CPU TYPES : ALL -* -* AUTHOR : Richard Logan -* -* CO-PILOT : William Roske -* -* DATE STARTED : 03/30/94 -* -* INITIAL RELEASE : UNICOS 7.0 -* -* TEST CASES -* -* 1-8) See Testcases structure below. -* -* INPUT SPECIFICATIONS -* The standard options for system call tests are accepted. -* (See the parse_opts(3) man page). -* -* OUTPUT SPECIFICATIONS -*$ -* DURATION -* Terminates - with frequency and infinite modes. -* -* SIGNALS -* Uses SIGUSR1 to pause before test if option set. -* (See the parse_opts(3) man page). -* -* RESOURCES -* None -* -* ENVIRONMENTAL NEEDS -* No run-time environmental needs. -* -* SPECIAL PROCEDURAL REQUIREMENTS -* None -* -* INTERCASE DEPENDENCIES -* None -* -* DETAILED DESCRIPTION -* This is a Phase I test for the unlink(2) system call. It is intended -* to provide a limited exposure of the system call, for now. It -* should/will be extended when full functional tests are written for -* unlink(2). -* -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* Execute system call -* Check return code, if system call failed (return=-1) -* Log the errno and Issue a FAIL message. -* Otherwise, Issue a PASS message. -* -* Cleanup: -* Print errno log and/or timing stats if options given -* -* -*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <sys/mman.h> +/* +* Description: +* The testcase checks the various errnos of the unlink(2). +* 1) unlink() returns ENOENT if file doesn't exist. +* 2) unlink() returns ENOENT if path is empty. +* 3) unlink() returns ENOENT if path contains a non-existent file. +* 4) unlink() returns EFAULT if address beyond address space. +* 5) unlink() returns ENOTDIR if path contains a regular file. +* 6) unlink() returns ENAMETOOLONG if path contains a regular file. +* 7) unlink() returns EFAULT if address is negative. +*/ +#include <errno.h> #include <string.h> -#include <signal.h> #include <unistd.h> -#include <sys/param.h> /* for PATH_MAX */ -#include "test.h" - -void setup (); -void cleanup (); +#include <sys/param.h> /* for PATH_MAX */ +#include "tst_test.h" -extern char *get_high_address (); +static char longpathname[PATH_MAX +2 ]; -char *TCID ="unlink07" ; -int TST_TOTAL =6 ; - -char *bad_addr =0 ; - -int longpath_setup (); -int no_setup (); -int filepath_setup (); -char Longpathname[PATH_MAX +2 ]; -char High_address[64 ]; - -struct test_case_t { -char *pathname; +static struct test_case_t { +char *name;char *desc;int exp_errno; -int (*setupfunc) (); -} Test_cases[] = { - { -"nonexistfile" ,"non-existent file" ,ENOENT , no_setup}, { -"" ,"path is empty string" ,ENOENT , no_setup}, { -"nefile/file" ,"path contains a non-existent file" , -ENOENT , no_setup}, -#if !defined(UCLINUX) - { - High_address,"address beyond address space" ,EFAULT , no_setup}, -#endif - { -"file/file" ,"path contains a regular file" , -ENOTDIR , filepath_setup}, -#if !defined(UCLINUX) - { - High_address,"address beyond address space" ,EFAULT , no_setup}, -#endif - { - Longpathname,"pathname too long" ,ENAMETOOLONG , longpath_setup}, { - (char *)-1 ,"negative address" ,EFAULT , no_setup}, { -NULL ,NULL ,0 , no_setup} +} tcases[] = { + {"nonexistfile" ,"non-existent file" ,ENOENT }, + {"" ,"path is empty string" ,ENOENT }, + {"nefile/file" ,"path contains a non-existent file" ,ENOENT }, + {NULL ,"address beyond address space" ,EFAULT }, + {"file/file" ,"path contains a regular file" ,ENOTDIR }, + {longpathname,"pathname too long" ,ENAMETOOLONG }, + {(char *)-1 ,"negative address" ,EFAULT }, }; -/*********************************************************************** -* Main -***********************************************************************/ -int main (int ac,char **av) -{ -int lc; -char *fname; -char *desc; -int ind; - -/*************************************************************** -* parse standard options -***************************************************************/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/*************************************************************** -* perform global setup for test -***************************************************************/ -setup (); - -/*************************************************************** -* check looping state if -c option given -***************************************************************/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { - - fname = Test_cases[ind].pathname; - desc = Test_cases[ind].desc; - -#if !defined(UCLINUX ) -if (fname == High_address) - fname =get_high_address (); -#endif -/* -* Call unlink(2) -*/ -TEST (unlink (fname)); - -/* check return code */ -if (TEST_RETURN ==-1 ) { -if (TEST_ERRNO == - Test_cases[ind].exp_errno) -tst_resm (TPASS , -"unlink(<%s>) Failed, errno=%d" , - desc,TEST_ERRNO ); -else -tst_resm (TFAIL , -"unlink(<%s>) Failed, errno=%d, expected errno:%d" , - desc,TEST_ERRNO , - Test_cases - [ind].exp_errno); - }else { -tst_resm (TFAIL , -"unlink(<%s>) returned %ld, expected -1, errno:%d" , - desc,TEST_RETURN , - Test_cases[ind].exp_errno); - } - } - - } - -cleanup (); -tst_exit (); -} - -/*************************************************************** -* setup() - performs all ONE TIME setup for this test. -***************************************************************/ -void setup (void ) +static void verify_unlink (unsigned int n) { -int ind; +struct test_case_t *tc = &tcases[n]; -tst_sig (NOFORK ,DEF_HANDLER , cleanup); +if (!tc->name) + tc->name =get_high_address (); -TEST_PAUSE ; - -tst_tmpdir (); - - bad_addr =mmap (0 ,1 ,PROT_NONE ,MAP_PRIVATE |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); +TEST (unlink (tc->name)); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"unlink(<%s>) succeeded unexpectedly" , + tc->desc); +return ; } - Test_cases[7 ].pathname = bad_addr; -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { - Test_cases[ind].setupfunc (); +if (TEST_ERRNO == tc->exp_errno) { +tst_res (TPASS |TTERRNO ,"unlink(<%s>) failed as expected" , + tc->desc); + }else { +tst_res (TFAIL |TTERRNO ,"unlink(<%s>) failed, expected errno:%s" , + tc->desc,tst_strerrno (tc->exp_errno)); } - -} - -/*************************************************************** -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -***************************************************************/ -void cleanup (void ) -{ -chmod ("unwrite_dir" ,0777 ); -chmod ("unsearch_dir" ,0777 ); - -tst_rmdir (); - } -/****************************************************************** -* -******************************************************************/ -int no_setup (void ) -{ -return 0 ; -} - -/****************************************************************** -* -******************************************************************/ -int longpath_setup (void ) +static void setup (void ) { -int ind; +int fd; -for (ind =0 ; ind <=PATH_MAX +1 ; ind++) { - Longpathname[ind] ='a' ; - } -return 0 ; + fd =SAFE_CREAT ("file" ,0777 ); +if (fd >0 ) +SAFE_CLOSE (fd); +memset (longpathname,'a' ,PATH_MAX +2 ); } -/****************************************************************** -* -******************************************************************/ -int filepath_setup (void ) -{ -int fd; - -if ((fd =creat ("file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup,"creat(file) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); -return 0 ; -} +static struct tst_test test = { + .needs_tmpdir =1 , + .setup = setup, + .tcnt =ARRAY_SIZE (tcases), + .test = verify_unlink, +};
Signature · 1 line
1.8.3.1
PATCH 4/4 syscalls/unlink08: Cleanup && Convert to new API
In reply to Xiao Yang1) Take use of some safe macros
2) Remove unused code
--- testcases/kernel/syscalls/unlink/unlink08.c | 365 ++++++---------------------- 1 file changed, 71 insertions(+), 294 deletions(-)
testcases/kernel/syscalls/unlink/unlink08.c +71 -294
@@ -28,328 +28,105 @@* For further information regarding this notice, see: * * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ -* */ -/* $Id: unlink08.c,v 1.5 2009/11/02 13:57:19 subrata_modak Exp $ */ -/********************************************************** -* -* OS Test - Silicon Graphics, Inc. -* -* TEST IDENTIFIER : unlink08 -* -* EXECUTED BY : anyone -* -* TEST TITLE : unlink(2) negative testcases -* -* PARENT DOCUMENT : usctpl01 -* -* TEST CASE TOTAL : 3 -* -* WALL CLOCK TIME : 1 -* -* CPU TYPES : ALL -* -* AUTHOR : Richard Logan -* -* CO-PILOT : William Roske -* -* DATE STARTED : 03/30/94 -* -* INITIAL RELEASE : UNICOS 7.0 -* -* TEST CASES -* -* 1-3) See Testcases structure below. -* -* INPUT SPECIFICATIONS -* The standard options for system call tests are accepted. -* (See the parse_opts(3) man page). -* -* OUTPUT SPECIFICATIONS -*$ -* DURATION -* Terminates - with frequency and infinite modes. -* -* SIGNALS -* Uses SIGUSR1 to pause before test if option set. -* (See the parse_opts(3) man page). -* -* RESOURCES -* None -* -* ENVIRONMENTAL NEEDS -* No run-time environmental needs. -* -* SPECIAL PROCEDURAL REQUIREMENTS -* None -* -* INTERCASE DEPENDENCIES -* None -* -* DETAILED DESCRIPTION -* This is a Phase I test for the unlink(2) system call. It is intended -* to provide a limited exposure of the system call, for now. It -* should/will be extended when full functional tests are written for -* unlink(2). -* -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* Execute system call -* Check return code, if system call failed (return=-1) -* Log the errno and Issue a FAIL message. -* Otherwise, Issue a PASS message. -* -* Cleanup: -* Print errno log and/or timing stats if options given -* -* -*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ - -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <errno.h> -#include <signal.h> -#include <unistd.h> -#include <string.h> -#include "test.h" -#include "safe_macros.h" -void setup (void ); -void cleanup (void ); +/* +* Description: +* The testcase checks the various errnos of the unlink(2). +* 1) unlink() returns EACCES when deleting file in unwritable directory +* as an unprivileged user. +* 2) unlink() returns EACCES when deleting file in "unsearchable directory +* as an unprivileged user. +* 3) unlink() returns EISDIR when deleting directory in linux. +* 4) unlink() returns EPERM when deleting directory in non-linux. +*/ -char *TCID ="unlink08" ; -int TST_TOTAL =3 ; +#include <errno.h> +#include <stdlib.h> +#include <sys/types.h> +#include <pwd.h> +#include "tst_test.h" -int unwrite_dir_setup (int flag); -int unsearch_dir_setup (int flag); -int dir_setup (int flag); -int no_setup (int flag); +static struct passwd *pw; -struct test_case_t { -char *pathname; +static struct test_case_t { +char *name;char *desc; -int (*setupfunc) (int flag); -int exp_ret;/* -1 means error, 0 means != -1 */ int exp_errno; -} Test_cases[] = { - { -"unwrite_dir/file" ,"unwritable directory" , unwrite_dir_setup, --1 ,EACCES }, { -"unsearch_dir/file" ,"unsearchable directory" , - unsearch_dir_setup,-1 ,EACCES }, -#ifdef linux - { -"regdir" ,"directory" , dir_setup,-1 ,EISDIR }, +int exp_user; +} tcases[] = { + {"unwrite_dir/file" ,"unwritable directory" ,EACCES ,1 }, + {"unsearch_dir/file" ,"unsearchable directory" ,EACCES ,1 }, +#ifdef __linux__ + {"regdir" ,"directory" ,EISDIR ,0 }, #else - { -"regdir" ,"directory" , dir_setup,-1 ,EPERM }, + {"regdir" ,"directory" ,EPERM ,0 }, #endif - { -NULL ,NULL , no_setup,-1 ,0 } }; -/*********************************************************************** -* Main -***********************************************************************/ -int main (int ac,char **av) +static void verify_unlink (struct test_case_t *tc) { -int lc; -char *fname; -char *desc; -int ind; - -/*************************************************************** -* parse standard options -***************************************************************/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/*************************************************************** -* perform global setup for test -***************************************************************/ -setup (); - -/*************************************************************** -* check looping state if -c option given -***************************************************************/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { - - fname = Test_cases[ind].pathname; - desc = Test_cases[ind].desc; - -/* -* Call unlink(2) -*/ -TEST (unlink (fname)); - -/* check return code */ -if (TEST_RETURN ==-1 ) { -if (Test_cases[ind].exp_ret ==-1 ) {/* neg test */ -if (TEST_ERRNO == - Test_cases[ind].exp_errno) -tst_resm (TPASS , -"unlink(<%s>) Failed, errno=%d" , - desc, -TEST_ERRNO ); -else -tst_resm (TFAIL , -"unlink(<%s>) Failed, errno=%d, expected errno:%d" , - desc, -TEST_ERRNO , - Test_cases - [ind].exp_errno); - }else { -tst_resm (TFAIL , -"unlink(<%s>) Failed, errno=%d" , - desc,TEST_ERRNO ); - } - }else { -if (Test_cases[ind].exp_ret ==-1 ) { -tst_resm (TFAIL , -"unlink(<%s>) returned %ld, expected -1, errno:%d" , - desc,TEST_RETURN , - Test_cases[ind].exp_errno); - }else { -tst_resm (TPASS , -"unlink(<%s>) returned %ld" , - desc,TEST_RETURN ); - } - Test_cases[ind].setupfunc (1 ); - } - } - - } - -cleanup (); -tst_exit (); -} - -/*************************************************************** -* setup() - performs all ONE TIME setup for this test. -***************************************************************/ -void setup (void ) -{ -int ind; -int postest =0 ; - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -tst_tmpdir (); - -if (geteuid () ==0 ) { - postest++; +TEST (unlink (tc->name)); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"unlink(<%s>) succeeded unexpectedly" , + tc->desc); +return ; } -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { -if (Test_cases[ind].exp_errno ==EACCES && postest) - Test_cases[ind].exp_ret =0 ;/* set as a pos test */ - Test_cases[ind].setupfunc (0 ); +if (TEST_ERRNO == tc->exp_errno) { +tst_res (TPASS |TTERRNO ,"unlink(<%s>) failed as expected" , + tc->desc); + }else { +tst_res (TFAIL |TTERRNO ,"unlink(<%s>) failed, expected errno:%s" , + tc->desc,tst_strerrno (tc->exp_errno)); } - -} - -/*************************************************************** -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -***************************************************************/ -void cleanup (void ) -{ -chmod ("unwrite_dir" ,0777 ); -chmod ("unsearch_dir" ,0777 ); - -tst_rmdir (); - } -/****************************************************************** -* -******************************************************************/ -int unwrite_dir_setup (int flag) +static void do_unlink (unsigned int n) { -int fd; - -if (!flag) {/* initial setup */ -SAFE_MKDIR (cleanup,"unwrite_dir" ,0777 ); - -if ((fd =creat ("unwrite_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unwrite_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); - -SAFE_CHMOD (cleanup,"unwrite_dir" ,0555 ); - }else {/* resetup */ -SAFE_CHMOD (cleanup,"unwrite_dir" ,0777 ); - -if ((fd =creat ("unwrite_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unwrite_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); +struct test_case_t *cases = &tcases[n]; +pid_t pid; + +if (cases->exp_user) { + pid =SAFE_FORK (); +if (!pid) { +SAFE_SETUID (pw->pw_uid); +verify_unlink (cases); +exit (0 ); } -close (fd); -SAFE_CHMOD (cleanup,"unwrite_dir" ,0555 ); +SAFE_WAITPID (pid,NULL ,0 ); + }else { +verify_unlink (cases); } -return 0 ; } -/****************************************************************** -* -******************************************************************/ -int unsearch_dir_setup (int flag) +static void setup (void ) {int fd; -if (!flag) {/* initial setup */ -SAFE_MKDIR (cleanup,"unsearch_dir" ,0777 ); - -if ((fd =creat ("unsearch_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unsearch_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); - -SAFE_CHMOD (cleanup,"unsearch_dir" ,0666 ); - }else {/* resetup */ -SAFE_CHMOD (cleanup,"unsearch_dir" ,0777 ); +SAFE_MKDIR ("unwrite_dir" ,0777 ); + fd =SAFE_CREAT ("unwrite_dir/file" ,0777 ); +if (fd >0 ) +SAFE_CLOSE (fd); +SAFE_CHMOD ("unwrite_dir" ,0555 ); -if ((fd =creat ("unsearch_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unsearch_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); +SAFE_MKDIR ("unsearch_dir" ,0777 ); + fd =SAFE_CREAT ("unsearch_dir/file" ,0777 ); +if (fd >0 ) +SAFE_CLOSE (fd); +SAFE_CHMOD ("unsearch_dir" ,0666 ); -SAFE_CHMOD (cleanup,"unsearch_dir" ,0666 ); - } -return 0 ; -} +SAFE_MKDIR ("regdir" ,0777 ); -/****************************************************************** -* -******************************************************************/ -int dir_setup (int flag) -{ -SAFE_MKDIR (cleanup,"regdir" ,0777 ); -return 0 ; + pw =SAFE_GETPWNAM ("nobody" ); } -/****************************************************************** -* -******************************************************************/ -int no_setup (int flag) -{ -return 0 ; -} +static struct tst_test test = { + .needs_root =1 , + .forks_child =1 , + .needs_tmpdir =1 , + .setup = setup, + .tcnt =ARRAY_SIZE (tcases), + .test = do_unlink, +};
Signature · 1 line
1.8.3.1
PATCH 1/4 lib/get_high_address.c: Add tst_get_high_address.h for new API
In reply to Xiao YangHi!
Quoted 1 line
Make sure
get_high_address()can be used by new API.
I would he happier if we created better API for the new library. If nothing else the function name is poorly choosen.
I would suggest naming it as tst_get_bad_addr() which better explains what the return value.
Also looking at the code we seem to use several different ways of triggering EFAULT:
* (void*)-1;
* get_high_address() which is sbrk(0) + 4 * PAGE_SIZE
* mmap() with PROT_NONE
I gueess that we may as well unify on one of these, all of them should work but I suppose that mmap() with PROT_NONE would be safest bet here.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/5 syscalls/mremap03: Do not pass MAP_FAILED into mremap()
Running mremap03 -i n got the following errors:
-----------------------------------------------
mremap03 1 TPASS : mremap() Fails, 'old region not mapped', errno 14 mremap03 1 TFAIL : mremap03.c:137: mremap() Fails, 'Unexpected errno 22
...
-----------------------------------------------
When running mremap03 in loops, we passed MAP_FAILED instead of bad address into mremap().
--- testcases/kernel/syscalls/mremap/mremap03.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/mremap/mremap03.c +4 -3
@@ -84,7 +84,8 @@char *TCID ="mremap03" ;int TST_TOTAL =1 ; -char *addr;/* addr of memory mapped region */ +static char *bad_addr; +static char *addr;/* addr of memory mapped region */ int memsize;/* memory mapped size */ int newsize;/* new size of virtual memory block */
@@ -111,7 +112,7 @@ int main(int ac, char **av)* virtual address was not mapped. */ errno =0 ; - addr =mremap (addr, memsize, newsize,MREMAP_MAYMOVE ); + addr =mremap (bad_addr, memsize, newsize,MREMAP_MAYMOVE );TEST_ERRNO = errno;/* Check for the return value of mremap() */
@@ -173,7 +174,7 @@ void setup(void)* Set the old virtual address point to some address * which is not mapped. */ - addr = (char *)get_high_address (); + bad_addr = (char *)get_high_address (); }/*
Signature · 1 line
1.8.3.1
PATCH v2 2/5 lib/get_high_address.c: Add tst_get_bad_addr.h for new API
1) Use mmap() with PROT_NONE to get a bad address and rename get_high_address as tst_get_bad_addr
2) Make sure tst_get_bad_addr can be used by both new API and old API
3) Apply tst_get_bad_addr and remove duplicate tests for EFAULT
4) Just use sbrk(0) + 4 * PAGE_SIZE to test ENOMEM in msync03
--- include/old/test.h | 4 +- include/tst_get_bad_addr.h | 31 ++++++++++++++++ include/tst_test.h | 1 + lib/get_high_address.c | 40 -------------------- lib/tst_get_bad_addr.c | 49 +++++++++++++++++++++++++ testcases/kernel/syscalls/lchown/lchown02.c | 19 +--------- testcases/kernel/syscalls/link/link04.c | 25 ++----------- testcases/kernel/syscalls/lstat/lstat02.c | 10 +---- testcases/kernel/syscalls/mkdir/mkdir01.c | 39 +------------------- testcases/kernel/syscalls/mknod/mknod06.c | 23 ++---------- testcases/kernel/syscalls/mremap/mremap03.c | 2 +- testcases/kernel/syscalls/msync/msync03.c | 2 +- testcases/kernel/syscalls/stat/stat03.c | 17 +-------- testcases/kernel/syscalls/symlink/symlink03.c | 21 ++--------- testcases/kernel/syscalls/truncate/truncate03.c | 8 +--- testcases/kernel/syscalls/unlink/unlink07.c | 28 ++------------ 16 files changed, 103 insertions(+), 216 deletions(-) create mode 100644 include/tst_get_bad_addr.h delete mode 100644 lib/get_high_address.c create mode 100644 lib/tst_get_bad_addr.c
include/old/test.h +1 -3
@@ -63,6 +63,7 @@#include "old_device.h" #include "old_tmpdir.h" #include "tst_minmax.h" +#include "tst_get_bad_addr.h" /* * Ensure that NUMSIGS is defined.
@@ -203,9 +204,6 @@ extern int tst_count;/* lib/tst_sig.c */ void tst_sig (int fork_flag,void (*handler)(),void (*cleanup)()); -/* lib/get_high_address.c */ -char *get_high_address (void ); -/* lib/self_exec.c */ void maybe_run_child (void (*child)(),const char *fmt, ...);int self_exec (const char *argv0,const char *fmt, ...);
include/tst_get_bad_addr.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. +* Author: Xiao Yang <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU General Public License along +* with this program. +*/ + +#ifndef TST_GET_BAD_ADDR_H__ +#define TST_GET_BAD_ADDR_H__ + +/* Functions from lib/tst_get_bad_addr.c */ + +void *tst_get_bad_addr (void ); + +#endif /* TST_GET_BAD_ADDR_H__ */
include/tst_test.h +1 -0
@@ -40,6 +40,7 @@#include "tst_clone.h" #include "tst_kernel.h" #include "tst_minmax.h" +#include "tst_get_bad_addr.h" /* * Reports testcase result.
lib/get_high_address.c deleted +0 -40
@@ -1,40 +0,0 @@ -/* $Header: /cvsroot/ltp/ltp/lib/get_high_address.c,v 1.6 2009/07/20 10:59:32 vapier Exp $ */ - -/* -* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* Further, this software is distributed without any warranty that it is -* free of the rightful claim of any third person regarding infringement -* or the like. Any license provided herein, whether implied or -* otherwise, applies only to this software file. Patent licenses, if -* any, provided herein do not apply to combinations of this program with -* other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -* -* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, -* Mountain View, CA 94043, or: -* -* http://www.sgi.com -* -* For further information regarding this notice, see: -* -* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ -*/ - -#include <unistd.h> - -char *get_high_address (void ) -{ -return (char *)sbrk (0 ) + (4 *getpagesize ()); -}
lib/tst_get_bad_addr.c new file +49 -0
49 lines not on this page · raw message
testcases/kernel/syscalls/lchown/lchown02.c +1 -18
@@ -79,7 +79,6 @@ static void setup_eacces(int pos);static void setup_enotdir (int pos);static void setup_longpath (int pos);static void setup_efault (int pos); -static void setup_highaddress (int pos);static char path[PATH_MAX +2 ];
@@ -93,7 +92,6 @@ struct test_case_t {static struct test_case_t test_cases[] = { {SFILE1 ,"Process is not owner/root" ,EPERM , setup_eperm}, {SFILE2 ,"Search permission denied" ,EACCES , setup_eacces}, - {NULL ,"Address beyond address space" ,EFAULT , setup_highaddress}, {NULL ,"Unaccessible address space" ,EFAULT , setup_efault}, {path,"Pathname too long" ,ENAMETOOLONG , setup_longpath}, {SFILE3 ,"Path contains regular file" ,ENOTDIR , setup_enotdir},
@@ -254,27 +252,12 @@ static void setup_efault(int pos) {char *bad_addr =0 ; - bad_addr =mmap (NULL ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,-1 ,0 ); - -if (bad_addr ==MAP_FAILED ) -tst_brkm (TBROK |TERRNO , cleanup,"mmap failed" ); + bad_addr = (char *)tst_get_bad_addr (); test_cases[pos].pathname = bad_addr; }/* -* setup_efault() -- setup for a test condition where lchown(2) returns -1 and -* sets errno to EFAULT. -* -* Use ltp function get_high_address() to compute high address. -*/ -static void setup_highaddress (int pos) -{ - test_cases[pos].pathname =get_high_address (); -} - -/* * setup_enotdir() - setup function for a test condition for which chown(2) * returns -1 and sets errno to ENOTDIR. *
testcases/kernel/syscalls/link/link04.c +3 -22
@@ -54,9 +54,6 @@static char *bad_addr =0 ;static char longpath[PATH_MAX +2 ]; -#if !defined(UCLINUX ) -char high_addr[64 ]; -#endif struct test_case_t {char *file1;
@@ -73,9 +70,6 @@ struct test_case_t { {"regfile/file" ,"path contains a regular file" ,"nefile" ,"nefile" , ENOTDIR}, {longpath, "pathname too long", "nefile", "nefile", ENAMETOOLONG}, -#if !defined(UCLINUX) - {high_addr, "address beyond address space", "nefile", "nefile", EFAULT}, -#endif {(char *)-1, "negative address", "nefile", "nefile", EFAULT},/* second path is invalid */ {"regfile", "regfile", "", "empty string", ENOENT},
@@ -84,10 +78,6 @@ struct test_case_t { {"regfile" ,"regfile" ,"file/file" , "path contains a regular file", ENOENT}, {"regfile", "regfile", longpath, "pathname too long", ENAMETOOLONG}, -#if !defined(UCLINUX) - {"regfile", "regfile", high_addr, - "address beyond address space", EFAULT}, -#endif {"regfile", "regfile", (char *)-1, "negative address", EFAULT},/* two existing files */ {"regfile", "regfile", "regfile2", "regfile2", EEXIST},
@@ -121,14 +111,6 @@ int main(int ac, char **av) fname2 = test_cases[i].file2; desc2 = test_cases[i].desc2; -#if !defined(UCLINUX ) -if (fname1 == high_addr) - fname1 =get_high_address (); - -if (fname2 == high_addr) - fname2 =get_high_address (); -#endif -TEST (link (fname1, fname2));if (TEST_RETURN ==-1 ) {
@@ -167,10 +149,9 @@ static void setup(void)tst_tmpdir ();#if !defined(UCLINUX ) - bad_addr =SAFE_MMAP (cleanup,0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); - test_cases[6 ].file1 = bad_addr; - test_cases[12 ].file2 = bad_addr; + bad_addr = (char *)tst_get_bad_addr (), + test_cases[5 ].file1 = bad_addr; + test_cases[10 ].file2 = bad_addr;#endif memset (longpath,'a' ,PATH_MAX +1 );
testcases/kernel/syscalls/lstat/lstat02.c +1 -9
@@ -61,7 +61,6 @@ static char elooppathname[sizeof(TEST_ELOOP) * 43] = ".";#if !defined(UCLINUX )static void bad_addr_setup (int ); -static void high_address_setup (int );#endif static struct test_case_t {
@@ -73,7 +72,6 @@ static struct test_case_t { {TEST_ENOENT, ENOENT, NULL}, #if !defined(UCLINUX) {NULL, EFAULT, bad_addr_setup}, - {NULL, EFAULT, high_address_setup}, #endif {longpathname, ENAMETOOLONG, NULL}, {TEST_ENOTDIR, ENOTDIR, NULL},
@@ -143,13 +141,7 @@ static void setup(void)#if !defined(UCLINUX )static void bad_addr_setup (int i) { - test_cases[i].pathname =SAFE_MMAP (cleanup,0 ,1 ,PROT_NONE , -MAP_PRIVATE |MAP_ANONYMOUS ,0 ,0 ); -} - -static void high_address_setup (int i) -{ - test_cases[i].pathname = (char *)get_high_address (); + test_cases[i].pathname = (char *)tst_get_bad_addr (); }#endif
testcases/kernel/syscalls/mkdir/mkdir01.c +2 -37
@@ -116,7 +116,7 @@ void setup();void cleanup ();char *TCID ="mkdir01" ; -int TST_TOTAL =2 ; +int TST_TOTAL =1 ;char *bad_addr =0 ;
@@ -161,37 +161,6 @@ int main(int ac, char **av) "mkdir - path argument pointing below allocated address space succeeded unexpectedly."); } -#if !defined(UCLINUX ) -/* -* TEST CASE: 2 -* mkdir() call with pointer above allocated address space. -*/ - -/* Call mkdir(2) */ -TEST (mkdir (get_high_address (),0777 )); - -/* check return code */ -if (TEST_RETURN ==-1 ) { - } - -if (TEST_RETURN ==-1 ) { -if (TEST_ERRNO ==EFAULT ) { -tst_resm (TPASS , -"mkdir - path argument pointing above allocated address space failed as expected with errno %d : %s" , -TEST_ERRNO , -strerror (TEST_ERRNO )); - }else { -tst_resm (TFAIL , -"mkdir - path argument pointing above allocated address space failed with errno %d : %s but expected %d (EFAULT)" , -TEST_ERRNO , -strerror (TEST_ERRNO ),EFAULT ); - } - }else { -tst_resm (TFAIL , -"mkdir - path argument pointing above allocated address space succeeded unexpectedly." ); - - } -#endif /* if !defined(UCLINUX) */ }
@@ -212,11 +181,7 @@ void setup(void)/* Create a temporary directory and make it current. */ tst_tmpdir (); - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } + bad_addr = (char *)tst_get_bad_addr (); }/***************************************************************
testcases/kernel/syscalls/mknod/mknod06.c +3 -20
@@ -93,7 +93,6 @@ int setup3(); /* setup function to test mknod for ENOTDIR */int longpath_setup ();/* setup function to test mknod for ENAMETOOLONG */ int no_setup ();/* simply returns 0 to the caller */ char Longpathname[PATH_MAX +2 ]; -char High_address_node[64 ];struct test_case_t {/* test case struct. to hold ref. test cond's */ char *pathname;
@@ -105,9 +104,7 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */ "tnode_1", "Specified node already exists", EEXIST, setup1},#if !defined(UCLINUX ) { - (char *)-1, "Negative address", EFAULT, no_setup}, { - High_address_node,"Address beyond address space" ,EFAULT , - no_setup}, + (char *)-1, "Negative address", EFAULT, no_setup}, #endif { "testdir_2/tnode_2", "Non-existent file", ENOENT, no_setup}, {
@@ -119,10 +116,6 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */char *TCID ="mknod06" ;int TST_TOTAL =ARRAY_SIZE (Test_cases); -#if !defined(UCLINUX ) -extern char *get_high_address (); -#else -#endif char *bad_addr =0 ;
@@ -152,12 +145,6 @@ int main(int ac, char **av) node_name = Test_cases[ind].pathname; test_desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (node_name == High_address_node) { - node_name =get_high_address (); - } -#endif -/* * Call mknod(2) to test different test conditions. * verify that it fails with -1 return value and
@@ -218,12 +205,8 @@ void setup(void)tst_tmpdir ();#if !defined(UCLINUX ) - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } - Test_cases[2 ].pathname = bad_addr; + bad_addr = (char *)tst_get_bad_addr (); + Test_cases[1 ].pathname = bad_addr;#endif /* call individual setup functions */ for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) {
testcases/kernel/syscalls/mremap/mremap03.c +1 -1
@@ -174,7 +174,7 @@ void setup(void)* Set the old virtual address point to some address * which is not mapped. */ - bad_addr = (char *)get_high_address (); + bad_addr = (char *)tst_get_bad_addr (); }/*
testcases/kernel/syscalls/msync/msync03.c +1 -1
@@ -137,7 +137,7 @@ static void setup(void)#if !defined(UCLINUX )/* memory pointed to by addr4 was not mapped */ - addr4 =get_high_address (); + addr4 = (char *)sbrk (0 ) + (4 * page_sz);#endif }
testcases/kernel/syscalls/stat/stat03.c +2 -15
@@ -103,7 +103,6 @@ char nobody_uid[] = "nobody";struct passwd *ltpuser;char Longpathname[PATH_MAX +2 ]; -char High_address_node[64 ];struct test_case_t {/* test case struct. to hold ref. test cond's */ char *pathname;
@@ -115,8 +114,6 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */ TEST_FILE1, "No Search permissions to process", EACCES, setup1},#if !defined(UCLINUX ) { - High_address_node, "Address beyond address space", EFAULT, no_setup}, - { (char *)-1, "Negative address", EFAULT, no_setup}, #endif {
@@ -158,12 +155,6 @@ int main(int ac, char **av) file_name = Test_cases[ind].pathname; test_desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (file_name == High_address_node) { - file_name = (char *)get_high_address (); - } -#endif -/* * Call stat(2) to test different test conditions. * verify that it fails with -1 return value and
@@ -238,12 +229,8 @@ void setup(void)tst_tmpdir ();#if !defined(UCLINUX ) - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } - Test_cases[2 ].pathname = bad_addr; + bad_addr = (char *)tst_get_bad_addr (); + Test_cases[1 ].pathname = bad_addr;#endif /* call individual setup functions */
testcases/kernel/syscalls/symlink/symlink03.c +3 -18
@@ -125,13 +125,7 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */TEST_FILE1 ,SYM_FILE1 ,"No Search permissions to process" , EACCES, setup1}, {TEST_FILE2 ,SYM_FILE2 ,"Specified symlink already exists" , - EEXIST, setup2}, -#if !defined(UCLINUX) - { - TESTFILE, High_address_node, "Address beyond address space", - EFAULT, no_setup}, -#endif - { + EEXIST, setup2}, { TESTFILE, (char *)-1, "Negative address", EFAULT, no_setup}, {TESTFILE , Longpathname,"Symlink path too long" ,ENAMETOOLONG , longpath_setup}, {
@@ -171,11 +165,6 @@ int main(int ac, char **av) test_file = Test_cases[ind].file; sym_file = Test_cases[ind].link; test_desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (sym_file == High_address_node) { - sym_file = (char *)get_high_address (); - } -#endif /* * Call symlink(2) to test different test conditions. * verify that it fails with -1 return value and sets
@@ -242,12 +231,8 @@ void setup(void)tst_tmpdir ();#if !defined(UCLINUX ) - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } - Test_cases[3 ].link = bad_addr; + bad_addr = (char *)tst_get_bad_addr (); + Test_cases[2 ].link = bad_addr;#endif /* call individual setup functions */
testcases/kernel/syscalls/truncate/truncate03.c +1 -7
@@ -77,7 +77,6 @@ static struct test_case_t { { TEST_FILE1, TRUNC_LEN, EACCES }, { TEST_FILE2, TRUNC_LEN, ENOTDIR }, #if !defined(UCLINUX) - { NULL, TRUNC_LEN, EFAULT }, { (char *)-1, TRUNC_LEN, EFAULT }, #endif { long_pathname, TRUNC_LEN, ENAMETOOLONG },
@@ -117,7 +116,6 @@ int main(int ac, char **av)void setup (void ) {struct passwd *ltpuser; -char *bad_addr;struct rlimit rlim;sigset_t signalset;
@@ -137,11 +135,7 @@ void setup(void)SAFE_TOUCH (cleanup,"t_file" ,FILE_MODE ,NULL );#if !defined(UCLINUX ) - test_cases[2 ].pathname = (char *)get_high_address (); - - bad_addr =SAFE_MMAP (cleanup,0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); - test_cases[3 ].pathname = bad_addr; + test_cases[2 ].pathname = (char *)tst_get_bad_addr ();#endif memset (long_pathname,'a' ,PATH_MAX +1 );
testcases/kernel/syscalls/unlink/unlink07.c +3 -25
@@ -123,13 +123,9 @@void setup ();void cleanup (); -extern char *get_high_address (); -char *TCID ="unlink07" ;int TST_TOTAL =6 ; -char *bad_addr =0 ; -int longpath_setup ();int no_setup ();int filepath_setup ();
@@ -146,19 +142,9 @@ struct test_case_t { "nonexistfile", "non-existent file", ENOENT, no_setup}, { "", "path is empty string", ENOENT, no_setup}, {"nefile/file" ,"path contains a non-existent file" , - ENOENT, no_setup}, -#if !defined(UCLINUX) - { - High_address, "address beyond address space", EFAULT, no_setup}, -#endif - { + ENOENT, no_setup}, {"file/file" ,"path contains a regular file" , - ENOTDIR, filepath_setup}, -#if !defined(UCLINUX) - { - High_address, "address beyond address space", EFAULT, no_setup}, -#endif - { + ENOTDIR, filepath_setup}, { Longpathname, "pathname too long", ENAMETOOLONG, longpath_setup}, { (char *)-1, "negative address", EFAULT, no_setup}, { NULL, NULL, 0, no_setup}
@@ -196,10 +182,6 @@ int main(int ac, char **av) fname = Test_cases[ind].pathname; desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (fname == High_address) - fname =get_high_address (); -#endif /* * Call unlink(2) */
@@ -245,11 +227,7 @@ void setup(void)tst_tmpdir (); - bad_addr =mmap (0 ,1 ,PROT_NONE ,MAP_PRIVATE |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } - Test_cases[7 ].pathname = bad_addr; + Test_cases[5 ].pathname = (char *)tst_get_bad_addr ();for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { Test_cases[ind].setupfunc ();
Signature · 1 line
1.8.3.1
PATCH v2 2/5 lib/get_high_address.c: Add tst_get_bad_addr.h for new API
Hi!
include/tst_get_bad_addr.h line 7
Quoted 10 lines
include/tst_get_bad_addr.h new file +7
-0@@ -0,0 +1,31 @@ +/* +* Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. +* Author: Xiao Yang <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation.
GPLv2+ is slightly pefered, see the license text in the tst_test.h.
Quoted 110 lines
include/tst_get_bad_addr.h new file +23
-0+* This program is distributed in the hope that it would be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU General Public License along +* with this program. +*/ + +#ifndef TST_GET_BAD_ADDR_H__ +#define TST_GET_BAD_ADDR_H__ + +/* Functions from lib/tst_get_bad_addr.c */ + +void *tst_get_bad_addr (void ); + +#endif /* TST_GET_BAD_ADDR_H__ */ include/tst_test.h +1
-0@@ -40,6 +40,7 @@#include "tst_clone.h" #include "tst_kernel.h" #include "tst_minmax.h" +#include "tst_get_bad_addr.h" /* * Reports testcase result. lib/get_high_address.c deleted +0
-40@@ -1,40 +0,0 @@ -/* $Header: /cvsroot/ltp/ltp/lib/get_high_address.c,v 1.6 2009/07/20 10:59:32 vapier Exp $ */ - -/* -* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* Further, this software is distributed without any warranty that it is -* free of the rightful claim of any third person regarding infringement -* or the like. Any license provided herein, whether implied or -* otherwise, applies only to this software file. Patent licenses, if -* any, provided herein do not apply to combinations of this program with -* other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -* -* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, -* Mountain View, CA 94043, or: -* -* http://www.sgi.com -* -* For further information regarding this notice, see: -* -* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ -*/ - -#include <unistd.h> - -char *get_high_address (void ) -{ -return (char *)sbrk (0 ) + (4 *getpagesize ()); -}lib/tst_get_bad_addr.c new file +23
-0@@ -0,0 +1,49 @@ +/* $Header: /cvsroot/ltp/ltp/lib/get_high_address.c,v 1.6 2009/07/20 10:59:32 vapier Exp $ */ + +/* +* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
lib/tst_get_bad_addr.c line 33
Quoted 10 lines
lib/tst_get_bad_addr.c new file +10
-0+* +* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, +* Mountain View, CA 94043, or: +* +* http://www.sgi.com +* +* For further information regarding this notice, see: +* +* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ +*/
Here as well, we do not use a single line from the original file so we may as well put GPLv2+ header here.
lib/tst_get_bad_addr.c line 46
Quoted 12 lines
lib/tst_get_bad_addr.c new file +12
-0+#include <sys/mman.h> +#define TST_NO_DEFAULT_MAIN +#include "tst_test.h" +#include "tst_get_bad_addr.h" + +void *tst_get_bad_addr (void ) +{ +void *bad_addr; + + bad_addr =mmap (0 ,1 ,PROT_NONE ,MAP_PRIVATE |MAP_ANONYMOUS ,0 ,0 ); +if (bad_addr ==MAP_FAILED ) +tst_brk (TBROK ,"mmap() failed to get bad address" );
I suppose that we have to actually use tst_brkm() and the old test.h if this is supposed to be called from the old library tests. Otherwise things will crash and burn once this tst_brk() gets called.
That is because we route tst_brkm() to the tst_brk() if new library is detected but not the other way around.
Quoted 23 lines
lib/tst_get_bad_addr.c new file +2
-0+return bad_addr; +}testcases/kernel/syscalls/lchown/lchown02.c +0
-2@@ -79,7 +79,6 @@ static void setup_eacces(int pos);static void setup_enotdir (int pos);static void setup_longpath (int pos);static void setup_efault (int pos); -static void setup_highaddress (int pos);static char path[PATH_MAX +2 ];@@ -93,7 +92,6 @@ struct test_case_t {static struct test_case_t test_cases[] = { {SFILE1 ,"Process is not owner/root" ,EPERM , setup_eperm}, {SFILE2 ,"Search permission denied" ,EACCES , setup_eacces}, - {NULL ,"Address beyond address space" ,EFAULT , setup_highaddress}, {NULL ,"Unaccessible address space" ,EFAULT , setup_efault}, {path,"Pathname too long" ,ENAMETOOLONG , setup_longpath}, {SFILE3 ,"Path contains regular file" ,ENOTDIR , setup_enotdir},
testcases/kernel/syscalls/lchown/lchown02.c static void setup_efault(int pos) · line 255
Quoted 9 lines
testcases/kernel/syscalls/lchown/lchown02.c +1
-5@@ -254,27 +252,12 @@ static void setup_efault(int pos) {char *bad_addr =0 ; - bad_addr =mmap (NULL ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,-1 ,0 ); - -if (bad_addr ==MAP_FAILED ) -tst_brkm (TBROK |TERRNO , cleanup,"mmap failed" ); + bad_addr = (char *)tst_get_bad_addr ();
^
Plese get rid of useless casts like this one.
Quoted 69 lines
testcases/kernel/syscalls/lchown/lchown02.c +0
-11test_cases[pos].pathname = bad_addr; }/* -* setup_efault() -- setup for a test condition where lchown(2) returns -1 and -* sets errno to EFAULT. -* -* Use ltp function get_high_address() to compute high address. -*/ -static void setup_highaddress (int pos) -{ - test_cases[pos].pathname =get_high_address (); -} - -/* * setup_enotdir() - setup function for a test condition for which chown(2) * returns -1 and sets errno to ENOTDIR. * testcases/kernel/syscalls/link/link04.c +0
-18@@ -54,9 +54,6 @@static char *bad_addr =0 ;static char longpath[PATH_MAX +2 ]; -#if !defined(UCLINUX ) -char high_addr[64 ]; -#endif struct test_case_t {char *file1;@@ -73,9 +70,6 @@ struct test_case_t { {"regfile/file" ,"path contains a regular file" ,"nefile" ,"nefile" , ENOTDIR}, {longpath, "pathname too long", "nefile", "nefile", ENAMETOOLONG}, -#if !defined(UCLINUX) - {high_addr, "address beyond address space", "nefile", "nefile", EFAULT}, -#endif {(char *)-1, "negative address", "nefile", "nefile", EFAULT},/* second path is invalid */ {"regfile", "regfile", "", "empty string", ENOENT},@@ -84,10 +78,6 @@ struct test_case_t { {"regfile" ,"regfile" ,"file/file" , "path contains a regular file", ENOENT}, {"regfile", "regfile", longpath, "pathname too long", ENAMETOOLONG}, -#if !defined(UCLINUX) - {"regfile", "regfile", high_addr, - "address beyond address space", EFAULT}, -#endif {"regfile", "regfile", (char *)-1, "negative address", EFAULT},/* two existing files */ {"regfile", "regfile", "regfile2", "regfile2", EEXIST},@@ -121,14 +111,6 @@ int main(int ac, char **av) fname2 = test_cases[i].file2; desc2 = test_cases[i].desc2; -#if !defined(UCLINUX ) -if (fname1 == high_addr) - fname1 =get_high_address (); - -if (fname2 == high_addr) - fname2 =get_high_address (); -#endif -TEST (link (fname1, fname2));if (TEST_RETURN ==-1 ) {
testcases/kernel/syscalls/link/link04.c static void setup(void) · line 152
Quoted 8 lines
testcases/kernel/syscalls/link/link04.c +1
-4@@ -167,10 +149,9 @@ static void setup(void)tst_tmpdir ();#if !defined(UCLINUX ) - bad_addr =SAFE_MMAP (cleanup,0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); - test_cases[6 ].file1 = bad_addr; - test_cases[12 ].file2 = bad_addr; + bad_addr = (char *)tst_get_bad_addr(),
^
Here as well.
And the same applies to the rest of the patchset.
testcases/kernel/syscalls/link/link04.c static void setup(void) · line 154
Quoted 2 lines
testcases/kernel/syscalls/link/link04.c +2
-0+ test_cases[5 ].file1 = bad_addr; + test_cases[10 ].file2 = bad_addr;
Also assigning to random array members here is kind of ugly, we usually go for pointer to a pointer and assignd &bad_addr in the test structure.
But given that it has been there already, if we want to fix it, it should be done in a follow up patch...
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/4 lib/get_high_address.c: Add tst_get_bad_addr.h for new API
1) Use mmap() with PROT_NONE to get a bad address and rename get_high_address as tst_get_bad_addr
2) Make sure tst_get_bad_addr can be used by both new API and old API
3) Apply tst_get_bad_addr and remove duplicate tests for EFAULT
4) Just use sbrk(0) + 4 * PAGE_SIZE to test ENOMEM in msync03
5) remove UCLINUX
--- include/old/test.h | 4 +-- include/tst_get_bad_addr.h | 37 +++++++++++++++++++++ include/tst_test.h | 1 + lib/get_high_address.c | 40 ---------------------- lib/tst_get_bad_addr.c | 31 +++++++++++++++++ testcases/kernel/syscalls/lchown/lchown02.c | 28 ++-------------- testcases/kernel/syscalls/link/link04.c | 33 ++++--------------- testcases/kernel/syscalls/lstat/lstat02.c | 23 +++---------- testcases/kernel/syscalls/mkdir/mkdir01.c | 39 ++-------------------- testcases/kernel/syscalls/mknod/mknod06.c | 33 +++---------------- testcases/kernel/syscalls/mremap/mremap03.c | 13 +------- testcases/kernel/syscalls/msync/msync03.c | 9 +---- testcases/kernel/syscalls/rmdir/rmdir05.c | 44 ++----------------------- testcases/kernel/syscalls/stat/stat03.c | 30 +++-------------- testcases/kernel/syscalls/symlink/symlink03.c | 32 ++++-------------- testcases/kernel/syscalls/truncate/truncate03.c | 15 ++------- testcases/kernel/syscalls/unlink/unlink07.c | 33 ++++--------------- 17 files changed, 112 insertions(+), 333 deletions(-) create mode 100644 include/tst_get_bad_addr.h delete mode 100644 lib/get_high_address.c create mode 100644 lib/tst_get_bad_addr.c
include/old/test.h +1 -3
@@ -63,6 +63,7 @@#include "old_device.h" #include "old_tmpdir.h" #include "tst_minmax.h" +#include "tst_get_bad_addr.h" /* * Ensure that NUMSIGS is defined.
@@ -203,9 +204,6 @@ extern int tst_count;/* lib/tst_sig.c */ void tst_sig (int fork_flag,void (*handler)(),void (*cleanup)()); -/* lib/get_high_address.c */ -char *get_high_address (void ); -/* lib/self_exec.c */ void maybe_run_child (void (*child)(),const char *fmt, ...);int self_exec (const char *argv0,const char *fmt, ...);
include/tst_get_bad_addr.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. +* Author: Xiao Yang <[email protected]> +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef TST_GET_BAD_ADDR_H__ +#define TST_GET_BAD_ADDR_H__ + +/* Functions from lib/tst_get_bad_addr.c */ +void *tst_get_bad_addr_ (void (*cleanup_fn) (void )); + +#ifdef TST_TEST_H__ +static inline void *tst_get_bad_addr (void ) +{ +return tst_get_bad_addr_ (NULL ); +} +#else +static inline void *tst_get_bad_addr (void (*cleanup_fn)(void )) +{ +return tst_get_bad_addr_ (cleanup_fn); +} +#endif + +#endif /* TST_GET_BAD_ADDR_H__ */
include/tst_test.h +1 -0
@@ -40,6 +40,7 @@#include "tst_clone.h" #include "tst_kernel.h" #include "tst_minmax.h" +#include "tst_get_bad_addr.h" /* * Reports testcase result.
lib/get_high_address.c deleted +0 -40
@@ -1,40 +0,0 @@ -/* $Header: /cvsroot/ltp/ltp/lib/get_high_address.c,v 1.6 2009/07/20 10:59:32 vapier Exp $ */ - -/* -* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* Further, this software is distributed without any warranty that it is -* free of the rightful claim of any third person regarding infringement -* or the like. Any license provided herein, whether implied or -* otherwise, applies only to this software file. Patent licenses, if -* any, provided herein do not apply to combinations of this program with -* other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -* -* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, -* Mountain View, CA 94043, or: -* -* http://www.sgi.com -* -* For further information regarding this notice, see: -* -* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ -*/ - -#include <unistd.h> - -char *get_high_address (void ) -{ -return (char *)sbrk (0 ) + (4 *getpagesize ()); -}
lib/tst_get_bad_addr.c new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <sys/mman.h> +#include "test.h" +#include "tst_get_bad_addr.h" + +void *tst_get_bad_addr_ (void (*cleanup_fn) (void )) +{ +void *bad_addr; + + bad_addr =mmap (0 ,1 ,PROT_NONE ,MAP_PRIVATE |MAP_ANONYMOUS ,0 ,0 ); +if (bad_addr ==MAP_FAILED ) +tst_brkm (TBROK , cleanup_fn,"mmap() failed to get bad address" ); + +return bad_addr; +}
testcases/kernel/syscalls/lchown/lchown02.c +3 -25
@@ -74,12 +74,13 @@TCID_DEFINE (lchown02);int TST_TOTAL =7 ; +static void setup (void ); +static void cleanup (void );static void setup_eperm (int pos);static void setup_eacces (int pos);static void setup_enotdir (int pos);static void setup_longpath (int pos);static void setup_efault (int pos); -static void setup_highaddress (int pos);static char path[PATH_MAX +2 ];
@@ -93,7 +94,6 @@ struct test_case_t {static struct test_case_t test_cases[] = { {SFILE1 ,"Process is not owner/root" ,EPERM , setup_eperm}, {SFILE2 ,"Search permission denied" ,EACCES , setup_eacces}, - {NULL ,"Address beyond address space" ,EFAULT , setup_highaddress}, {NULL ,"Unaccessible address space" ,EFAULT , setup_efault}, {path,"Pathname too long" ,ENAMETOOLONG , setup_longpath}, {SFILE3 ,"Path contains regular file" ,ENOTDIR , setup_enotdir},
@@ -103,9 +103,6 @@ static struct test_case_t test_cases[] = {static struct passwd *ltpuser; -static void setup (void ); -static void cleanup (void ); -int main (int argc,char *argv[]) {int lc;
@@ -252,26 +249,7 @@ static void setup_eacces(int pos LTP_ATTRIBUTE_UNUSED)*/ static void setup_efault (int pos) { -char *bad_addr =0 ; - - bad_addr =mmap (NULL ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,-1 ,0 ); - -if (bad_addr ==MAP_FAILED ) -tst_brkm (TBROK |TERRNO , cleanup,"mmap failed" ); - - test_cases[pos].pathname = bad_addr; -} - -/* -* setup_efault() -- setup for a test condition where lchown(2) returns -1 and -* sets errno to EFAULT. -* -* Use ltp function get_high_address() to compute high address. -*/ -static void setup_highaddress (int pos) -{ - test_cases[pos].pathname =get_high_address (); + test_cases[pos].pathname =tst_get_bad_addr (cleanup); }/*
testcases/kernel/syscalls/link/link04.c +6 -27
@@ -51,12 +51,7 @@#include "test.h" #include "safe_macros.h" -static char *bad_addr =0 ; -static char longpath[PATH_MAX +2 ]; -#if !defined(UCLINUX ) -char high_addr[64 ]; -#endif struct test_case_t {char *file1;
@@ -73,10 +68,7 @@ struct test_case_t { {"regfile/file" ,"path contains a regular file" ,"nefile" ,"nefile" , ENOTDIR}, {longpath, "pathname too long", "nefile", "nefile", ENAMETOOLONG}, -#if !defined(UCLINUX) - {high_addr, "address beyond address space", "nefile", "nefile", EFAULT}, -#endif - {(char *)-1, "negative address", "nefile", "nefile", EFAULT}, + {NULL, "negative address", "nefile", "nefile", EFAULT},/* second path is invalid */ {"regfile", "regfile", "", "empty string", ENOENT}, {"regfile", "regfile", "neefile/file",
@@ -84,11 +76,7 @@ struct test_case_t { {"regfile" ,"regfile" ,"file/file" , "path contains a regular file", ENOENT}, {"regfile", "regfile", longpath, "pathname too long", ENAMETOOLONG}, -#if !defined(UCLINUX) - {"regfile", "regfile", high_addr, - "address beyond address space", EFAULT}, -#endif - {"regfile", "regfile", (char *)-1, "negative address", EFAULT}, + {"regfile", "regfile", NULL, "negative address", EFAULT},/* two existing files */ {"regfile", "regfile", "regfile2", "regfile2", EEXIST}, };
@@ -121,13 +109,11 @@ int main(int ac, char **av) fname2 = test_cases[i].file2; desc2 = test_cases[i].desc2; -#if !defined(UCLINUX ) -if (fname1 == high_addr) - fname1 =get_high_address (); +if (!fname1) + fname1 =tst_get_bad_addr (cleanup); -if (fname2 == high_addr) - fname2 =get_high_address (); -#endif +if (!fname2) + fname2 =tst_get_bad_addr (cleanup);TEST (link (fname1, fname2));
@@ -166,13 +152,6 @@ static void setup(void)tst_tmpdir (); -#if !defined(UCLINUX ) - bad_addr =SAFE_MMAP (cleanup,0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); - test_cases[6 ].file1 = bad_addr; - test_cases[12 ].file2 = bad_addr; -#endif -memset (longpath,'a' ,PATH_MAX +1 );SAFE_TOUCH (cleanup,"regfile" ,0777 ,NULL );SAFE_TOUCH (cleanup,"regfile2" ,0777 ,NULL );
testcases/kernel/syscalls/lstat/lstat02.c +4 -19
@@ -59,10 +59,10 @@static char longpathname[PATH_MAX +2 ];static char elooppathname[sizeof (TEST_ELOOP ) *43 ] ="." ; -#if !defined(UCLINUX ) +static void setup (void ); +static void lstat_verify (int ); +static void cleanup (void );static void bad_addr_setup (int ); -static void high_address_setup (int ); -#endif static struct test_case_t { char *pathname;
@@ -71,10 +71,7 @@ static struct test_case_t { } test_cases[] = { {TEST_EACCES, EACCES, NULL}, {TEST_ENOENT, ENOENT, NULL}, -#if !defined(UCLINUX) {NULL, EFAULT, bad_addr_setup}, - {NULL, EFAULT, high_address_setup}, -#endif {longpathname, ENAMETOOLONG, NULL}, {TEST_ENOTDIR, ENOTDIR, NULL}, {elooppathname, ELOOP, NULL},
@@ -83,10 +80,6 @@ static struct test_case_t {char *TCID ="lstat02" ;int TST_TOTAL =ARRAY_SIZE (test_cases); -static void setup (void ); -static void lstat_verify (int ); -static void cleanup (void ); -int main (int ac,char **av) {int lc;
@@ -140,18 +133,10 @@ static void setup(void)strcat (elooppathname,TEST_ELOOP ); } -#if !defined(UCLINUX )static void bad_addr_setup (int i) { - test_cases[i].pathname =SAFE_MMAP (cleanup,0 ,1 ,PROT_NONE , -MAP_PRIVATE |MAP_ANONYMOUS ,0 ,0 ); -} - -static void high_address_setup (int i) -{ - test_cases[i].pathname = (char *)get_high_address (); + test_cases[i].pathname =tst_get_bad_addr (cleanup); } -#endif static void lstat_verify (int i) {
testcases/kernel/syscalls/mkdir/mkdir01.c +2 -37
@@ -116,7 +116,7 @@ void setup();void cleanup ();char *TCID ="mkdir01" ; -int TST_TOTAL =2 ; +int TST_TOTAL =1 ;char *bad_addr =0 ;
@@ -161,37 +161,6 @@ int main(int ac, char **av) "mkdir - path argument pointing below allocated address space succeeded unexpectedly."); } -#if !defined(UCLINUX ) -/* -* TEST CASE: 2 -* mkdir() call with pointer above allocated address space. -*/ - -/* Call mkdir(2) */ -TEST (mkdir (get_high_address (),0777 )); - -/* check return code */ -if (TEST_RETURN ==-1 ) { - } - -if (TEST_RETURN ==-1 ) { -if (TEST_ERRNO ==EFAULT ) { -tst_resm (TPASS , -"mkdir - path argument pointing above allocated address space failed as expected with errno %d : %s" , -TEST_ERRNO , -strerror (TEST_ERRNO )); - }else { -tst_resm (TFAIL , -"mkdir - path argument pointing above allocated address space failed with errno %d : %s but expected %d (EFAULT)" , -TEST_ERRNO , -strerror (TEST_ERRNO ),EFAULT ); - } - }else { -tst_resm (TFAIL , -"mkdir - path argument pointing above allocated address space succeeded unexpectedly." ); - - } -#endif /* if !defined(UCLINUX) */ }
@@ -212,11 +181,7 @@ void setup(void)/* Create a temporary directory and make it current. */ tst_tmpdir (); - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } + bad_addr =tst_get_bad_addr (cleanup); }/***************************************************************
testcases/kernel/syscalls/mknod/mknod06.c +4 -29
@@ -93,7 +93,6 @@ int setup3(); /* setup function to test mknod for ENOTDIR */int longpath_setup ();/* setup function to test mknod for ENAMETOOLONG */ int no_setup ();/* simply returns 0 to the caller */ char Longpathname[PATH_MAX +2 ]; -char High_address_node[64 ];struct test_case_t {/* test case struct. to hold ref. test cond's */ char *pathname;
@@ -101,15 +100,8 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */int exp_errno;int (*setupfunc) (); } Test_cases[] = { - { - "tnode_1", "Specified node already exists", EEXIST, setup1}, -#if !defined(UCLINUX) - { - (char *)-1, "Negative address", EFAULT, no_setup}, { - High_address_node, "Address beyond address space", EFAULT, - no_setup}, -#endif - { + {"tnode_1", "Specified node already exists", EEXIST, setup1}, { + NULL, "Negative address", EFAULT, no_setup}, { "testdir_2/tnode_2", "Non-existent file", ENOENT, no_setup}, { "", "Pathname is empty", ENOENT, no_setup}, { Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, {
@@ -119,12 +111,6 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */char *TCID ="mknod06" ;int TST_TOTAL =ARRAY_SIZE (Test_cases); -#if !defined(UCLINUX ) -extern char *get_high_address (); -#else -#endif - -char *bad_addr =0 ;void setup ();/* setup function for the tests */ void cleanup ();/* cleanup function for the tests */
@@ -152,11 +138,8 @@ int main(int ac, char **av) node_name = Test_cases[ind].pathname; test_desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (node_name == High_address_node) { - node_name =get_high_address (); - } -#endif +if (!node_name) + node_name =tst_get_bad_addr (cleanup);/* * Call mknod(2) to test different test conditions.
@@ -217,14 +200,6 @@ void setup(void)/* Make a temp dir and cd to it */ tst_tmpdir (); -#if !defined(UCLINUX ) - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } - Test_cases[2 ].pathname = bad_addr; -#endif /* call individual setup functions */ for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { Test_cases[ind].setupfunc ();
testcases/kernel/syscalls/mremap/mremap03.c +1 -12
@@ -92,7 +92,6 @@ int newsize; /* new size of virtual memory block */void setup ();/* Main setup function of test */ void cleanup ();/* cleanup function for the test */ -#if !defined(UCLINUX )int main (int ac,char **av) {int lc;
@@ -174,7 +173,7 @@ void setup(void)* Set the old virtual address point to some address * which is not mapped. */ - bad_addr = (char *)get_high_address (); + bad_addr =tst_get_bad_addr (cleanup); }/*
@@ -187,13 +186,3 @@ void cleanup(void)/* Exit the program */ } - -#else - -int main (void ) -{ -tst_resm (TINFO ,"test is not available on uClinux" ); -tst_exit (); -} - -#endif /* if !defined(UCLINUX) */
testcases/kernel/syscalls/msync/msync03.c +1 -8
@@ -57,10 +57,7 @@ static int fd;static char *addr1;static char *addr2;static char *addr3; - -#if !defined(UCLINUX )static char *addr4; -#endif static size_t page_sz;
@@ -74,9 +71,7 @@ static struct test_case_t { { &addr1, INV_SYNC, EINVAL }, { &addr2, MS_SYNC, EINVAL }, { &addr3, MS_SYNC, EINVAL }, -#if !defined(UCLINUX) { &addr4, MS_SYNC, ENOMEM }, -#endif };static void msync_verify (struct test_case_t *tc);
@@ -135,10 +130,8 @@ static void setup(void)SAFE_GETRLIMIT (NULL ,RLIMIT_DATA , &rl); addr3 = (char *)rl.rlim_max; -#if !defined(UCLINUX )/* memory pointed to by addr4 was not mapped */ - addr4 =get_high_address (); -#endif + addr4 =sbrk (0 ) + (4 * page_sz); }static void msync_verify (struct test_case_t *tc)
testcases/kernel/syscalls/rmdir/rmdir05.c +2 -42
68 lines not on this page · raw message
testcases/kernel/syscalls/stat/stat03.c +4 -26
@@ -103,7 +103,6 @@ char nobody_uid[] = "nobody";struct passwd *ltpuser;char Longpathname[PATH_MAX +2 ]; -char High_address_node[64 ];struct test_case_t {/* test case struct. to hold ref. test cond's */ char *pathname;
@@ -111,15 +110,8 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */int exp_errno;int (*setupfunc) (); } Test_cases[] = { - { - TEST_FILE1, "No Search permissions to process", EACCES, setup1}, -#if !defined(UCLINUX) - { - High_address_node, "Address beyond address space", EFAULT, no_setup}, - { - (char *)-1, "Negative address", EFAULT, no_setup}, -#endif - { + {TEST_FILE1, "No Search permissions to process", EACCES, setup1}, { + NULL, "Negative address", EFAULT, no_setup}, { Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, { "", "Pathname is empty", ENOENT, no_setup}, { TEST_FILE2, "Path contains regular file", ENOTDIR, setup2}, {
@@ -129,8 +121,6 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */char *TCID ="stat03" ;int TST_TOTAL =ARRAY_SIZE (Test_cases); -char *bad_addr =0 ; -void setup ();/* Main setup function for the tests */ void cleanup ();/* cleanup function for the test */
@@ -158,11 +148,8 @@ int main(int ac, char **av) file_name = Test_cases[ind].pathname; test_desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (file_name == High_address_node) { - file_name = (char *)get_high_address (); - } -#endif +if (!file_name) + file_name =tst_get_bad_addr (cleanup);/* * Call stat(2) to test different test conditions.
@@ -237,15 +224,6 @@ void setup(void)/* Make a temp dir and cd to it */ tst_tmpdir (); -#if !defined(UCLINUX ) - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } - Test_cases[2 ].pathname = bad_addr; -#endif -/* call individual setup functions */ for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { Test_cases[ind].setupfunc ();
testcases/kernel/syscalls/symlink/symlink03.c +6 -26
@@ -103,8 +103,6 @@char *TCID ="symlink03" ;int TST_TOTAL =1 ; -char *bad_addr =0 ; -int no_setup ();int setup1 ();/* setup function to test symlink for EACCES */ int setup2 ();/* setup function to test symlink for EEXIST */
@@ -121,18 +119,11 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */int exp_errno;int (*setupfunc) (); } Test_cases[] = { - { -TEST_FILE1 ,SYM_FILE1 ,"No Search permissions to process" , + {TEST_FILE1 ,SYM_FILE1 ,"No Search permissions to process" , EACCES, setup1}, {TEST_FILE2 ,SYM_FILE2 ,"Specified symlink already exists" , - EEXIST, setup2}, -#if !defined(UCLINUX) - { - TESTFILE, High_address_node, "Address beyond address space", - EFAULT, no_setup}, -#endif - { - TESTFILE, (char *)-1, "Negative address", EFAULT, no_setup}, { + EEXIST, setup2}, { + TESTFILE, NULL, "Negative address", EFAULT, no_setup}, {TESTFILE , Longpathname,"Symlink path too long" ,ENAMETOOLONG , longpath_setup}, { TESTFILE, "", "Symlink Pathname is empty", ENOENT, no_setup}, {
@@ -171,11 +162,9 @@ int main(int ac, char **av) test_file = Test_cases[ind].file; sym_file = Test_cases[ind].link; test_desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (sym_file == High_address_node) { - sym_file = (char *)get_high_address (); - } -#endif + +if (!sym_file) + sym_file =tst_get_bad_addr (cleanup);/* * Call symlink(2) to test different test conditions. * verify that it fails with -1 return value and sets
@@ -241,15 +230,6 @@ void setup(void)tst_tmpdir (); -#if !defined(UCLINUX ) - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } - Test_cases[3 ].link = bad_addr; -#endif -/* call individual setup functions */ for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { Test_cases[ind].setupfunc ();
testcases/kernel/syscalls/truncate/truncate03.c +3 -12
@@ -76,10 +76,7 @@ static struct test_case_t { } test_cases[] = { { TEST_FILE1, TRUNC_LEN, EACCES }, { TEST_FILE2, TRUNC_LEN, ENOTDIR }, -#if !defined(UCLINUX) { NULL, TRUNC_LEN, EFAULT }, - { (char *)-1, TRUNC_LEN, EFAULT }, -#endif { long_pathname, TRUNC_LEN, ENAMETOOLONG }, { "", TRUNC_LEN, ENOENT }, { TEST_DIR1, TRUNC_LEN, EISDIR },
@@ -117,7 +114,6 @@ int main(int ac, char **av)void setup (void ) {struct passwd *ltpuser; -char *bad_addr;struct rlimit rlim;sigset_t signalset;
@@ -136,14 +132,6 @@ void setup(void)SAFE_TOUCH (cleanup,"t_file" ,FILE_MODE ,NULL ); -#if !defined(UCLINUX ) - test_cases[2 ].pathname = (char *)get_high_address (); - - bad_addr =SAFE_MMAP (cleanup,0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); - test_cases[3 ].pathname = bad_addr; -#endif -memset (long_pathname,'a' ,PATH_MAX +1 );SAFE_MKDIR (cleanup,TEST_DIR1 ,DIR_MODE );
@@ -166,6 +154,9 @@ void setup(void)void truncate_verify (struct test_case_t *tc) { +if (!tc->pathname) + tc->pathname =tst_get_bad_addr (cleanup); +TEST (truncate (tc->pathname, tc->length));if (TEST_RETURN !=-1 ) {
testcases/kernel/syscalls/unlink/unlink07.c +6 -27
@@ -123,13 +123,9 @@void setup ();void cleanup (); -extern char *get_high_address (); -char *TCID ="unlink07" ;int TST_TOTAL =6 ; -char *bad_addr =0 ; -int longpath_setup ();int no_setup ();int filepath_setup ();
@@ -146,21 +142,11 @@ struct test_case_t { "nonexistfile", "non-existent file", ENOENT, no_setup}, { "", "path is empty string", ENOENT, no_setup}, {"nefile/file" ,"path contains a non-existent file" , - ENOENT, no_setup}, -#if !defined(UCLINUX) - { - High_address, "address beyond address space", EFAULT, no_setup}, -#endif - { + ENOENT, no_setup}, {"file/file" ,"path contains a regular file" , - ENOTDIR, filepath_setup}, -#if !defined(UCLINUX) - { - High_address, "address beyond address space", EFAULT, no_setup}, -#endif - { + ENOTDIR, filepath_setup}, { Longpathname, "pathname too long", ENAMETOOLONG, longpath_setup}, { - (char *)-1, "negative address", EFAULT, no_setup}, { + NULL, "negative address", EFAULT, no_setup}, { NULL, NULL, 0, no_setup} };
@@ -196,10 +182,9 @@ int main(int ac, char **av) fname = Test_cases[ind].pathname; desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (fname == High_address) - fname =get_high_address (); -#endif +if (!fname) + fname =tst_get_bad_addr (cleanup); +/* * Call unlink(2) */
@@ -245,12 +230,6 @@ void setup(void)tst_tmpdir (); - bad_addr =mmap (0 ,1 ,PROT_NONE ,MAP_PRIVATE |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } - Test_cases[7 ].pathname = bad_addr; -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { Test_cases[ind].setupfunc (); }
Signature · 1 line
1.8.3.1
PATCH v3 2/4 syscalls/unlink05, 06: Cleanup && Convert to new API
1) Take use of some safe macros
2) Merge unlink06 into unlink05
--- runtest/ltplite | 1 - runtest/quickhit | 2 - runtest/stress.part3 | 1 - runtest/syscalls | 1 - testcases/kernel/syscalls/.gitignore | 1 - testcases/kernel/syscalls/unlink/unlink05.c | 253 +++++++--------------------- testcases/kernel/syscalls/unlink/unlink06.c | 215 ----------------------- 7 files changed, 62 insertions(+), 412 deletions(-) delete mode 100644 testcases/kernel/syscalls/unlink/unlink06.c
runtest/ltplite +0 -1
@@ -964,7 +964,6 @@ uname03 uname03 unlink01 symlink01 -T unlink01 unlink05 unlink05 -unlink06 unlink06 unlink07 unlink07 unlink08 unlink08
runtest/quickhit +0 -2
@@ -255,8 +255,6 @@ uname01 uname01 # Basic test for uname(2) unlink05 unlink05 # Basic test for unlink(2) -unlink06 unlink06 -# unlink(2) of a FIFO unlink07 unlink07 # unlink(2) negative testcases unlink08 unlink08
runtest/stress.part3 +0 -1
@@ -840,7 +840,6 @@ uname03 uname03 unlink01 symlink01 -T unlink01 unlink05 unlink05 -unlink06 unlink06 unlink07 unlink07 unlink08 unlink08
runtest/syscalls +0 -1
@@ -1383,7 +1383,6 @@ cve-2012-0957 cve-2012-0957 unlink01 symlink01 -T unlink01 unlink05 unlink05 -unlink06 unlink06 unlink07 unlink07 unlink08 unlink08
testcases/kernel/syscalls/.gitignore +0 -1
@@ -1082,7 +1082,6 @@ /uname/uname02 /uname/uname03 /unlink/unlink05 -/unlink/unlink06 /unlink/unlink07 /unlink/unlink08 /unlinkat/unlinkat01
testcases/kernel/syscalls/unlink/unlink05.c +62 -191
271 lines not on this page · raw message
testcases/kernel/syscalls/unlink/unlink06.c deleted +0 -215
215 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 3/4 syscalls/unlink07: Cleanup && Convert to new API
In reply to Xiao Yang1) Take use of some safe macros
2) Remove duplicate tests for EFAULT
--- testcases/kernel/syscalls/unlink/unlink07.c | 321 ++++++---------------------- 1 file changed, 60 insertions(+), 261 deletions(-)
testcases/kernel/syscalls/unlink/unlink07.c +60 -261
@@ -1,287 +1,86 @@/* * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. * -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* Further, this software is distributed without any warranty that it is -* free of the rightful claim of any third person regarding infringement -* or the like. Any license provided herein, whether implied or -* otherwise, applies only to this software file. Patent licenses, if -* any, provided herein do not apply to combinations of this program with -* other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -* -* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, -* Mountain View, CA 94043, or: -* -* http://www.sgi.com -* -* For further information regarding this notice, see: -* -* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ -* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* +* Description: +* The testcase checks the various errnos of the unlink(2). +* 1) unlink() returns ENOENT if file doesn't exist. +* 2) unlink() returns ENOENT if path is empty. +* 3) unlink() returns ENOENT if path contains a non-existent file. +* 4) unlink() returns EFAULT if address beyond address space. +* 5) unlink() returns ENOTDIR if path contains a regular file. +* 6) unlink() returns ENAMETOOLONG if path contains a regular file. +* 7) unlink() returns EFAULT if address is negative. */ -/* $Id: unlink07.c,v 1.8 2009/11/02 13:57:19 subrata_modak Exp $ */ -/********************************************************** -* -* OS Test - Silicon Graphics, Inc. -* -* TEST IDENTIFIER : unlink07 -* -* EXECUTED BY : anyone -* -* TEST TITLE : unlink(2) negative testcases -* -* PARENT DOCUMENT : usctpl01 -* -* TEST CASE TOTAL : 1 -* -* WALL CLOCK TIME : 1 -* -* CPU TYPES : ALL -* -* AUTHOR : Richard Logan -* -* CO-PILOT : William Roske -* -* DATE STARTED : 03/30/94 -* -* INITIAL RELEASE : UNICOS 7.0 -* -* TEST CASES -* -* 1-8) See Testcases structure below. -* -* INPUT SPECIFICATIONS -* The standard options for system call tests are accepted. -* (See the parse_opts(3) man page). -* -* OUTPUT SPECIFICATIONS -*$ -* DURATION -* Terminates - with frequency and infinite modes. -* -* SIGNALS -* Uses SIGUSR1 to pause before test if option set. -* (See the parse_opts(3) man page). -* -* RESOURCES -* None -* -* ENVIRONMENTAL NEEDS -* No run-time environmental needs. -* -* SPECIAL PROCEDURAL REQUIREMENTS -* None -* -* INTERCASE DEPENDENCIES -* None -* -* DETAILED DESCRIPTION -* This is a Phase I test for the unlink(2) system call. It is intended -* to provide a limited exposure of the system call, for now. It -* should/will be extended when full functional tests are written for -* unlink(2). -* -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* Execute system call -* Check return code, if system call failed (return=-1) -* Log the errno and Issue a FAIL message. -* Otherwise, Issue a PASS message. -* -* Cleanup: -* Print errno log and/or timing stats if options given -* -* -*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <sys/mman.h> #include <errno.h> #include <string.h> -#include <signal.h> #include <unistd.h> -#include <sys/param.h> /* for PATH_MAX */ -#include "test.h" +#include <sys/param.h> /* for PATH_MAX */ +#include "tst_test.h" -void setup (); -void cleanup (); +static char longpathname[PATH_MAX +2 ]; -char *TCID ="unlink07" ; -int TST_TOTAL =6 ; - -int longpath_setup (); -int no_setup (); -int filepath_setup (); -char Longpathname[PATH_MAX +2 ]; -char High_address[64 ]; - -struct test_case_t { -char *pathname; +static struct test_case_t { +char *name;char *desc;int exp_errno; -int (*setupfunc) (); -} Test_cases[] = { - { -"nonexistfile" ,"non-existent file" ,ENOENT , no_setup}, { -"" ,"path is empty string" ,ENOENT , no_setup}, { -"nefile/file" ,"path contains a non-existent file" , -ENOENT , no_setup}, { -"file/file" ,"path contains a regular file" , -ENOTDIR , filepath_setup}, { - Longpathname,"pathname too long" ,ENAMETOOLONG , longpath_setup}, { -NULL ,"negative address" ,EFAULT , no_setup}, { -NULL ,NULL ,0 , no_setup} +} tcases[] = { + {"nonexistfile" ,"non-existent file" ,ENOENT }, + {"" ,"path is empty string" ,ENOENT }, + {"nefile/file" ,"path contains a non-existent file" ,ENOENT }, + {NULL ,"negative address" ,EFAULT }, + {"file/file" ,"path contains a regular file" ,ENOTDIR }, + {longpathname,"pathname too long" ,ENAMETOOLONG }, }; -/*********************************************************************** -* Main -***********************************************************************/ -int main (int ac,char **av) +static void verify_unlink (unsigned int n) { -int lc; -char *fname; -char *desc; -int ind; - -/*************************************************************** -* parse standard options -***************************************************************/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/*************************************************************** -* perform global setup for test -***************************************************************/ -setup (); - -/*************************************************************** -* check looping state if -c option given -***************************************************************/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { - - fname = Test_cases[ind].pathname; - desc = Test_cases[ind].desc; - -if (!fname) - fname =tst_get_bad_addr (cleanup); +struct test_case_t *tc = &tcases[n]; -/* -* Call unlink(2) -*/ -TEST (unlink (fname)); - -/* check return code */ -if (TEST_RETURN ==-1 ) { -if (TEST_ERRNO == - Test_cases[ind].exp_errno) -tst_resm (TPASS , -"unlink(<%s>) Failed, errno=%d" , - desc,TEST_ERRNO ); -else -tst_resm (TFAIL , -"unlink(<%s>) Failed, errno=%d, expected errno:%d" , - desc,TEST_ERRNO , - Test_cases - [ind].exp_errno); - }else { -tst_resm (TFAIL , -"unlink(<%s>) returned %ld, expected -1, errno:%d" , - desc,TEST_RETURN , - Test_cases[ind].exp_errno); - } - } +if (!tc->name) + tc->name =tst_get_bad_addr (); +TEST (unlink (tc->name)); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"unlink(<%s>) succeeded unexpectedly" , + tc->desc); +return ; } -cleanup (); -tst_exit (); -} - -/*************************************************************** -* setup() - performs all ONE TIME setup for this test. -***************************************************************/ -void setup (void ) -{ -int ind; - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -tst_tmpdir (); - -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { - Test_cases[ind].setupfunc (); +if (TEST_ERRNO == tc->exp_errno) { +tst_res (TPASS |TTERRNO ,"unlink(<%s>) failed as expected" , + tc->desc); + }else { +tst_res (TFAIL |TTERRNO ,"unlink(<%s>) failed, expected errno:%s" , + tc->desc,tst_strerrno (tc->exp_errno)); } - } -/*************************************************************** -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -***************************************************************/ -void cleanup (void ) +static void setup (void ) { -chmod ("unwrite_dir" ,0777 ); -chmod ("unsearch_dir" ,0777 ); - -tst_rmdir (); - -} - -/****************************************************************** -* -******************************************************************/ -int no_setup (void ) -{ -return 0 ; -} - -/****************************************************************** -* -******************************************************************/ -int longpath_setup (void ) -{ -int ind; - -for (ind =0 ; ind <=PATH_MAX +1 ; ind++) { - Longpathname[ind] ='a' ; - } -return 0 ; +SAFE_TOUCH ("file" ,0777 ,NULL ); +memset (longpathname,'a' ,PATH_MAX +2 ); } -/****************************************************************** -* -******************************************************************/ -int filepath_setup (void ) -{ -int fd; - -if ((fd =creat ("file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup,"creat(file) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); -return 0 ; -} +static struct tst_test test = { + .needs_tmpdir =1 , + .setup = setup, + .tcnt =ARRAY_SIZE (tcases), + .test = verify_unlink, +};
Signature · 1 line
1.8.3.1
PATCH v3 4/4 syscalls/unlink08: Cleanup && Convert to new API
In reply to Xiao Yang1) Take use of some safe macros
2) Remove unused code
--- testcases/kernel/syscalls/unlink/unlink08.c | 402 ++++++---------------------- 1 file changed, 79 insertions(+), 323 deletions(-)
testcases/kernel/syscalls/unlink/unlink08.c +79 -323
@@ -1,355 +1,111 @@/* * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. * -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* Further, this software is distributed without any warranty that it is -* free of the rightful claim of any third person regarding infringement -* or the like. Any license provided herein, whether implied or -* otherwise, applies only to this software file. Patent licenses, if -* any, provided herein do not apply to combinations of this program with -* other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -* -* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, -* Mountain View, CA 94043, or: -* -* http://www.sgi.com -* -* For further information regarding this notice, see: -* -* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ -* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* $Id: unlink08.c,v 1.5 2009/11/02 13:57:19 subrata_modak Exp $ */ -/********************************************************** -* -* OS Test - Silicon Graphics, Inc. -* -* TEST IDENTIFIER : unlink08 -* -* EXECUTED BY : anyone -* -* TEST TITLE : unlink(2) negative testcases -* -* PARENT DOCUMENT : usctpl01 -* -* TEST CASE TOTAL : 3 -* -* WALL CLOCK TIME : 1 -* -* CPU TYPES : ALL -* -* AUTHOR : Richard Logan -* -* CO-PILOT : William Roske -* -* DATE STARTED : 03/30/94 -* -* INITIAL RELEASE : UNICOS 7.0 -* -* TEST CASES -* -* 1-3) See Testcases structure below. -* -* INPUT SPECIFICATIONS -* The standard options for system call tests are accepted. -* (See the parse_opts(3) man page). -* -* OUTPUT SPECIFICATIONS -*$ -* DURATION -* Terminates - with frequency and infinite modes. -* -* SIGNALS -* Uses SIGUSR1 to pause before test if option set. -* (See the parse_opts(3) man page). -* -* RESOURCES -* None -* -* ENVIRONMENTAL NEEDS -* No run-time environmental needs. -* -* SPECIAL PROCEDURAL REQUIREMENTS -* None -* -* INTERCASE DEPENDENCIES -* None -* -* DETAILED DESCRIPTION -* This is a Phase I test for the unlink(2) system call. It is intended -* to provide a limited exposure of the system call, for now. It -* should/will be extended when full functional tests are written for -* unlink(2). -* -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* Execute system call -* Check return code, if system call failed (return=-1) -* Log the errno and Issue a FAIL message. -* Otherwise, Issue a PASS message. -* -* Cleanup: -* Print errno log and/or timing stats if options given -* -* -*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ - -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <errno.h> -#include <signal.h> -#include <unistd.h> -#include <string.h> -#include "test.h" -#include "safe_macros.h" -void setup (void ); -void cleanup (void ); +/* +* Description: +* The testcase checks the various errnos of the unlink(2). +* 1) unlink() returns EACCES when deleting file in unwritable directory +* as an unprivileged user. +* 2) unlink() returns EACCES when deleting file in "unsearchable directory +* as an unprivileged user. +* 3) unlink() returns EISDIR when deleting directory in linux. +* 4) unlink() returns EPERM when deleting directory in non-linux. +*/ -char *TCID ="unlink08" ; -int TST_TOTAL =3 ; +#include <errno.h> +#include <stdlib.h> +#include <sys/types.h> +#include <pwd.h> +#include "tst_test.h" -int unwrite_dir_setup (int flag); -int unsearch_dir_setup (int flag); -int dir_setup (int flag); -int no_setup (int flag); +static struct passwd *pw; -struct test_case_t { -char *pathname; +static struct test_case_t { +char *name;char *desc; -int (*setupfunc) (int flag); -int exp_ret;/* -1 means error, 0 means != -1 */ int exp_errno; -} Test_cases[] = { - { -"unwrite_dir/file" ,"unwritable directory" , unwrite_dir_setup, --1 ,EACCES }, { -"unsearch_dir/file" ,"unsearchable directory" , - unsearch_dir_setup,-1 ,EACCES }, -#ifdef linux - { -"regdir" ,"directory" , dir_setup,-1 ,EISDIR }, +int exp_user; +} tcases[] = { + {"unwrite_dir/file" ,"unwritable directory" ,EACCES ,1 }, + {"unsearch_dir/file" ,"unsearchable directory" ,EACCES ,1 }, +#ifdef __linux__ + {"regdir" ,"directory" ,EISDIR ,0 }, #else - { -"regdir" ,"directory" , dir_setup,-1 ,EPERM }, + {"regdir" ,"directory" ,EPERM ,0 }, #endif - { -NULL ,NULL , no_setup,-1 ,0 } }; -/*********************************************************************** -* Main -***********************************************************************/ -int main (int ac,char **av) -{ -int lc; -char *fname; -char *desc; -int ind; - -/*************************************************************** -* parse standard options -***************************************************************/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/*************************************************************** -* perform global setup for test -***************************************************************/ -setup (); - -/*************************************************************** -* check looping state if -c option given -***************************************************************/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { - - fname = Test_cases[ind].pathname; - desc = Test_cases[ind].desc; - -/* -* Call unlink(2) -*/ -TEST (unlink (fname)); - -/* check return code */ -if (TEST_RETURN ==-1 ) { -if (Test_cases[ind].exp_ret ==-1 ) {/* neg test */ -if (TEST_ERRNO == - Test_cases[ind].exp_errno) -tst_resm (TPASS , -"unlink(<%s>) Failed, errno=%d" , - desc, -TEST_ERRNO ); -else -tst_resm (TFAIL , -"unlink(<%s>) Failed, errno=%d, expected errno:%d" , - desc, -TEST_ERRNO , - Test_cases - [ind].exp_errno); - }else { -tst_resm (TFAIL , -"unlink(<%s>) Failed, errno=%d" , - desc,TEST_ERRNO ); - } - }else { -if (Test_cases[ind].exp_ret ==-1 ) { -tst_resm (TFAIL , -"unlink(<%s>) returned %ld, expected -1, errno:%d" , - desc,TEST_RETURN , - Test_cases[ind].exp_errno); - }else { -tst_resm (TPASS , -"unlink(<%s>) returned %ld" , - desc,TEST_RETURN ); - } - Test_cases[ind].setupfunc (1 ); - } - } - - } - -cleanup (); -tst_exit (); -} - -/*************************************************************** -* setup() - performs all ONE TIME setup for this test. -***************************************************************/ -void setup (void ) +static void verify_unlink (struct test_case_t *tc) { -int ind; -int postest =0 ; - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -tst_tmpdir (); - -if (geteuid () ==0 ) { - postest++; +TEST (unlink (tc->name)); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"unlink(<%s>) succeeded unexpectedly" , + tc->desc); +return ; } -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { -if (Test_cases[ind].exp_errno ==EACCES && postest) - Test_cases[ind].exp_ret =0 ;/* set as a pos test */ - Test_cases[ind].setupfunc (0 ); +if (TEST_ERRNO == tc->exp_errno) { +tst_res (TPASS |TTERRNO ,"unlink(<%s>) failed as expected" , + tc->desc); + }else { +tst_res (TFAIL |TTERRNO ,"unlink(<%s>) failed, expected errno:%s" , + tc->desc,tst_strerrno (tc->exp_errno)); } - -} - -/*************************************************************** -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -***************************************************************/ -void cleanup (void ) -{ -chmod ("unwrite_dir" ,0777 ); -chmod ("unsearch_dir" ,0777 ); - -tst_rmdir (); - } -/****************************************************************** -* -******************************************************************/ -int unwrite_dir_setup (int flag) +static void do_unlink (unsigned int n) { -int fd; - -if (!flag) {/* initial setup */ -SAFE_MKDIR (cleanup,"unwrite_dir" ,0777 ); - -if ((fd =creat ("unwrite_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unwrite_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); +struct test_case_t *cases = &tcases[n]; +pid_t pid; + +if (cases->exp_user) { + pid =SAFE_FORK (); +if (!pid) { +SAFE_SETUID (pw->pw_uid); +verify_unlink (cases); +exit (0 ); } -close (fd); - -SAFE_CHMOD (cleanup,"unwrite_dir" ,0555 ); - }else {/* resetup */ -SAFE_CHMOD (cleanup,"unwrite_dir" ,0777 ); -if ((fd =creat ("unwrite_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unwrite_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); - -SAFE_CHMOD (cleanup,"unwrite_dir" ,0555 ); +SAFE_WAITPID (pid,NULL ,0 ); + }else { +verify_unlink (cases); } -return 0 ; } -/****************************************************************** -* -******************************************************************/ -int unsearch_dir_setup (int flag) +static void setup (void ) { -int fd; - -if (!flag) {/* initial setup */ -SAFE_MKDIR (cleanup,"unsearch_dir" ,0777 ); - -if ((fd =creat ("unsearch_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unsearch_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); +SAFE_MKDIR ("unwrite_dir" ,0777 ); +SAFE_TOUCH ("unwrite_dir/file" ,0777 ,NULL ); +SAFE_CHMOD ("unwrite_dir" ,0555 ); -SAFE_CHMOD (cleanup,"unsearch_dir" ,0666 ); - }else {/* resetup */ -SAFE_CHMOD (cleanup,"unsearch_dir" ,0777 ); +SAFE_MKDIR ("unsearch_dir" ,0777 ); +SAFE_TOUCH ("unsearch_dir/file" ,0777 ,NULL ); +SAFE_CHMOD ("unsearch_dir" ,0666 ); -if ((fd =creat ("unsearch_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unsearch_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); +SAFE_MKDIR ("regdir" ,0777 ); -SAFE_CHMOD (cleanup,"unsearch_dir" ,0666 ); - } -return 0 ; + pw =SAFE_GETPWNAM ("nobody" ); } -/****************************************************************** -* -******************************************************************/ -int dir_setup (int flag) -{ -SAFE_MKDIR (cleanup,"regdir" ,0777 ); -return 0 ; -} - -/****************************************************************** -* -******************************************************************/ -int no_setup (int flag) -{ -return 0 ; -} +static struct tst_test test = { + .needs_root =1 , + .forks_child =1 , + .needs_tmpdir =1 , + .setup = setup, + .tcnt =ARRAY_SIZE (tcases), + .test = do_unlink, +};
Signature · 1 line
1.8.3.1
PATCH v3 1/4 lib/get_high_address.c: Add tst_get_bad_addr.h for new API
In reply to Xiao YangHi!
testcases/kernel/syscalls/link/link04.c int main(int ac, char **av) · line 113
Quoted 2 lines
testcases/kernel/syscalls/link/link04.c +2
-0+if (!fname1) + fname1 =tst_get_bad_addr (cleanup);
Here we should call the function only once in the setup() since this will allocate two pages of memory for each test iteration and the test may get out of memory if we pass large enough -i parameter.
I would do something similar in test setup():
void *bad_add = tst_get_bad_addr(NULL);
loop over test structure {
if (!tc->fname)
tc->fname = bad_addr;
}Quoted 163 lines
testcases/kernel/syscalls/link/link04.c +2
-10-if (fname2 == high_addr) - fname2 =get_high_address (); -#endif +if (!fname2) + fname2 =tst_get_bad_addr (cleanup);TEST (link (fname1, fname2));@@ -166,13 +152,6 @@ static void setup(void)tst_tmpdir (); -#if !defined(UCLINUX ) - bad_addr =SAFE_MMAP (cleanup,0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); - test_cases[6 ].file1 = bad_addr; - test_cases[12 ].file2 = bad_addr; -#endif -memset (longpath,'a' ,PATH_MAX +1 );SAFE_TOUCH (cleanup,"regfile" ,0777 ,NULL );SAFE_TOUCH (cleanup,"regfile2" ,0777 ,NULL );testcases/kernel/syscalls/lstat/lstat02.c +4
-19@@ -59,10 +59,10 @@static char longpathname[PATH_MAX +2 ];static char elooppathname[sizeof (TEST_ELOOP ) *43 ] ="." ; -#if !defined(UCLINUX ) +static void setup (void ); +static void lstat_verify (int ); +static void cleanup (void );static void bad_addr_setup (int ); -static void high_address_setup (int ); -#endif static struct test_case_t { char *pathname;@@ -71,10 +71,7 @@ static struct test_case_t { } test_cases[] = { {TEST_EACCES, EACCES, NULL}, {TEST_ENOENT, ENOENT, NULL}, -#if !defined(UCLINUX) {NULL, EFAULT, bad_addr_setup}, - {NULL, EFAULT, high_address_setup}, -#endif {longpathname, ENAMETOOLONG, NULL}, {TEST_ENOTDIR, ENOTDIR, NULL}, {elooppathname, ELOOP, NULL},@@ -83,10 +80,6 @@ static struct test_case_t {char *TCID ="lstat02" ;int TST_TOTAL =ARRAY_SIZE (test_cases); -static void setup (void ); -static void lstat_verify (int ); -static void cleanup (void ); -int main (int ac,char **av) {int lc;@@ -140,18 +133,10 @@ static void setup(void)strcat (elooppathname,TEST_ELOOP ); } -#if !defined(UCLINUX )static void bad_addr_setup (int i) { - test_cases[i].pathname =SAFE_MMAP (cleanup,0 ,1 ,PROT_NONE , -MAP_PRIVATE |MAP_ANONYMOUS ,0 ,0 ); -} - -static void high_address_setup (int i) -{ - test_cases[i].pathname = (char *)get_high_address (); + test_cases[i].pathname =tst_get_bad_addr (cleanup); } -#endif static void lstat_verify (int i) {testcases/kernel/syscalls/mkdir/mkdir01.c +2
-37@@ -116,7 +116,7 @@ void setup();void cleanup ();char *TCID ="mkdir01" ; -int TST_TOTAL =2 ; +int TST_TOTAL =1 ;char *bad_addr =0 ;@@ -161,37 +161,6 @@ int main(int ac, char **av) "mkdir - path argument pointing below allocated address space succeeded unexpectedly."); } -#if !defined(UCLINUX ) -/* -* TEST CASE: 2 -* mkdir() call with pointer above allocated address space. -*/ - -/* Call mkdir(2) */ -TEST (mkdir (get_high_address (),0777 )); - -/* check return code */ -if (TEST_RETURN ==-1 ) { - } - -if (TEST_RETURN ==-1 ) { -if (TEST_ERRNO ==EFAULT ) { -tst_resm (TPASS , -"mkdir - path argument pointing above allocated address space failed as expected with errno %d : %s" , -TEST_ERRNO , -strerror (TEST_ERRNO )); - }else { -tst_resm (TFAIL , -"mkdir - path argument pointing above allocated address space failed with errno %d : %s but expected %d (EFAULT)" , -TEST_ERRNO , -strerror (TEST_ERRNO ),EFAULT ); - } - }else { -tst_resm (TFAIL , -"mkdir - path argument pointing above allocated address space succeeded unexpectedly." ); - - } -#endif /* if !defined(UCLINUX) */ }@@ -212,11 +181,7 @@ void setup(void)/* Create a temporary directory and make it current. */ tst_tmpdir (); - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } + bad_addr =tst_get_bad_addr (cleanup); }/*************************************************************** testcases/kernel/syscalls/mknod/mknod06.c +0
-2@@ -93,7 +93,6 @@ int setup3(); /* setup function to test mknod for ENOTDIR */int longpath_setup ();/* setup function to test mknod for ENAMETOOLONG */ int no_setup ();/* simply returns 0 to the caller */ char Longpathname[PATH_MAX +2 ]; -char High_address_node[64 ];struct test_case_t {/* test case struct. to hold ref. test cond's */ char *pathname;@@ -101,15 +100,8 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */int exp_errno;int (*setupfunc) (); } Test_cases[] = { - {
testcases/kernel/syscalls/mknod/mknod06.c struct test_case_t { /* test case struct. to hold ref. test cond's */ · line 104
Quoted 10 lines
testcases/kernel/syscalls/mknod/mknod06.c +2
-8- "tnode_1", "Specified node already exists", EEXIST, setup1}, -#if !defined(UCLINUX ) - { - (char *)-1, "Negative address", EFAULT, no_setup}, { - High_address_node,"Address beyond address space" ,EFAULT , - no_setup}, -#endif - { + {"tnode_1", "Specified node already exists", EEXIST, setup1}, { + NULL, "Negative address", EFAULT, no_setup}, {
^
This should say "Invalid address" now.
Quoted 17 lines
testcases/kernel/syscalls/mknod/mknod06.c +0
-6"testdir_2/tnode_2", "Non-existent file", ENOENT, no_setup}, { "", "Pathname is empty", ENOENT, no_setup}, { Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, {@@ -119,12 +111,6 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */char *TCID ="mknod06" ;int TST_TOTAL =ARRAY_SIZE (Test_cases); -#if !defined(UCLINUX ) -extern char *get_high_address (); -#else -#endif - -char *bad_addr =0 ;void setup ();/* setup function for the tests */ void cleanup ();/* cleanup function for the tests */
testcases/kernel/syscalls/mknod/mknod06.c int main(int ac, char **av) · line 142
Quoted 10 lines
testcases/kernel/syscalls/mknod/mknod06.c +2
-5@@ -152,11 +138,8 @@ int main(int ac, char **av) node_name = Test_cases[ind].pathname; test_desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (node_name == High_address_node) { - node_name =get_high_address (); - } -#endif +if (!node_name) + node_name =tst_get_bad_addr (cleanup);
Here as well, the tst_get_bad_addr() should be called only once in the test setup.
Quoted 17 lines
testcases/kernel/syscalls/stat/stat03.c +0
-2@@ -103,7 +103,6 @@ char nobody_uid[] = "nobody";struct passwd *ltpuser;char Longpathname[PATH_MAX +2 ]; -char High_address_node[64 ];struct test_case_t {/* test case struct. to hold ref. test cond's */ char *pathname;@@ -111,15 +110,8 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */int exp_errno;int (*setupfunc) (); } Test_cases[] = { - {
testcases/kernel/syscalls/stat/stat03.c struct test_case_t { /* test case struct. to hold ref. test cond's */ · line 114
Quoted 10 lines
testcases/kernel/syscalls/stat/stat03.c +2
-8- TEST_FILE1, "No Search permissions to process", EACCES, setup1}, -#if !defined(UCLINUX ) - { - High_address_node, "Address beyond address space", EFAULT, no_setup}, - { - (char *)-1, "Negative address", EFAULT, no_setup}, -#endif - { + {TEST_FILE1, "No Search permissions to process", EACCES, setup1}, { + NULL, "Negative address", EFAULT, no_setup}, {
^
Here as well, should be changed to "Invalid address"
Quoted 13 lines
testcases/kernel/syscalls/stat/stat03.c +0
-2Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, { "", "Pathname is empty", ENOENT, no_setup}, { TEST_FILE2, "Path contains regular file", ENOTDIR, setup2}, {@@ -129,8 +121,6 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */char *TCID ="stat03" ;int TST_TOTAL =ARRAY_SIZE (Test_cases); -char *bad_addr =0 ; -void setup ();/* Main setup function for the tests */ void cleanup ();/* cleanup function for the test */
testcases/kernel/syscalls/stat/stat03.c int main(int ac, char **av) · line 152
Quoted 10 lines
testcases/kernel/syscalls/stat/stat03.c +2
-5@@ -158,11 +148,8 @@ int main(int ac, char **av) file_name = Test_cases[ind].pathname; test_desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (file_name == High_address_node) { - file_name = (char *)get_high_address (); - } -#endif +if (!file_name) + file_name =tst_get_bad_addr (cleanup);
Here as well the function should be called once in the test setup.
Quoted 40 lines
testcases/kernel/syscalls/stat/stat03.c +0
-9/* * Call stat(2) to test different test conditions. @@ -237,15 +224,6 @@ void setup(void)/* Make a temp dir and cd to it */ tst_tmpdir (); -#if !defined(UCLINUX ) - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } - Test_cases[2 ].pathname = bad_addr; -#endif -/* call individual setup functions */ for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { Test_cases[ind].setupfunc ();testcases/kernel/syscalls/symlink/symlink03.c +1
-4@@ -103,8 +103,6 @@char *TCID ="symlink03" ;int TST_TOTAL =1 ; -char *bad_addr =0 ; -int no_setup ();int setup1 ();/* setup function to test symlink for EACCES */ int setup2 ();/* setup function to test symlink for EEXIST */ @@ -121,18 +119,11 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */int exp_errno;int (*setupfunc) (); } Test_cases[] = { - { -TEST_FILE1 ,SYM_FILE1 ,"No Search permissions to process" , + {TEST_FILE1 ,SYM_FILE1 ,"No Search permissions to process" , EACCES, setup1}, { TEST_FILE2, SYM_FILE2, "Specified symlink already exists",
testcases/kernel/syscalls/symlink/symlink03.c struct test_case_t { /* test case struct. to hold ref. test cond's */ · line 126
Quoted 10 lines
testcases/kernel/syscalls/symlink/symlink03.c +2
-8- EEXIST, setup2}, -#if !defined(UCLINUX ) - { -TESTFILE , High_address_node,"Address beyond address space" , - EFAULT, no_setup}, -#endif - { - TESTFILE, (char *)-1, "Negative address", EFAULT, no_setup}, { + EEXIST, setup2}, { + TESTFILE, NULL, "Negative address", EFAULT, no_setup}, {
^
And here as well.
Quoted 5 lines
testcases/kernel/syscalls/symlink/symlink03.c +0
-0TESTFILE , Longpathname,"Symlink path too long" ,ENAMETOOLONG , longpath_setup}, { TESTFILE, "", "Symlink Pathname is empty", ENOENT, no_setup}, {@@ -171,11 +162,9 @@ int main(int ac, char **av) test_file = Test_cases[ind].file;
testcases/kernel/syscalls/symlink/symlink03.c int main(int ac, char **av) · line 167
Quoted 10 lines
testcases/kernel/syscalls/symlink/symlink03.c +3
-5sym_file = Test_cases[ind].link; test_desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (sym_file == High_address_node) { - sym_file = (char *)get_high_address (); - } -#endif + +if (!sym_file) + sym_file =tst_get_bad_addr (cleanup);
And here as well.
Quoted 58 lines
testcases/kernel/syscalls/symlink/symlink03.c +0
-9/* * Call symlink(2) to test different test conditions. * verify that it fails with -1 return value and sets @@ -241,15 +230,6 @@ void setup(void)tst_tmpdir (); -#if !defined(UCLINUX ) - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } - Test_cases[3 ].link = bad_addr; -#endif -/* call individual setup functions */ for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { Test_cases[ind].setupfunc ();testcases/kernel/syscalls/truncate/truncate03.c +0
-12@@ -76,10 +76,7 @@ static struct test_case_t { } test_cases[] = { { TEST_FILE1, TRUNC_LEN, EACCES }, { TEST_FILE2, TRUNC_LEN, ENOTDIR }, -#if !defined(UCLINUX) { NULL, TRUNC_LEN, EFAULT }, - { (char *)-1, TRUNC_LEN, EFAULT }, -#endif { long_pathname, TRUNC_LEN, ENAMETOOLONG }, { "", TRUNC_LEN, ENOENT }, { TEST_DIR1, TRUNC_LEN, EISDIR },@@ -117,7 +114,6 @@ int main(int ac, char **av)void setup (void ) {struct passwd *ltpuser; -char *bad_addr;struct rlimit rlim;sigset_t signalset;@@ -136,14 +132,6 @@ void setup(void)SAFE_TOUCH (cleanup,"t_file" ,FILE_MODE ,NULL ); -#if !defined(UCLINUX ) - test_cases[2 ].pathname = (char *)get_high_address (); - - bad_addr =SAFE_MMAP (cleanup,0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); - test_cases[3 ].pathname = bad_addr; -#endif -memset (long_pathname,'a' ,PATH_MAX +1 );SAFE_MKDIR (cleanup,TEST_DIR1 ,DIR_MODE );
testcases/kernel/syscalls/truncate/truncate03.c void setup(void) · line 158
Quoted 5 lines
testcases/kernel/syscalls/truncate/truncate03.c +2
-0@@ -166,6 +154,9 @@ void setup(void)void truncate_verify (struct test_case_t *tc) { +if (!tc->pathname) + tc->pathname =tst_get_bad_addr (cleanup);
And here as well.
Quoted 33 lines
testcases/kernel/syscalls/truncate/truncate03.c +0
-0TEST (truncate (tc->pathname, tc->length));if (TEST_RETURN !=-1 ) {testcases/kernel/syscalls/unlink/unlink07.c +1
-10@@ -123,13 +123,9 @@void setup ();void cleanup (); -extern char *get_high_address (); -char *TCID ="unlink07" ;int TST_TOTAL =6 ; -char *bad_addr =0 ; -int longpath_setup ();int no_setup ();int filepath_setup ();@@ -146,21 +142,11 @@ struct test_case_t { "nonexistfile", "non-existent file", ENOENT, no_setup}, { "", "path is empty string", ENOENT, no_setup}, {"nefile/file" ,"path contains a non-existent file" , - ENOENT, no_setup}, -#if !defined(UCLINUX) - { - High_address, "address beyond address space", EFAULT, no_setup}, -#endif - { + ENOENT, no_setup}, { "file/file", "path contains a regular file",
testcases/kernel/syscalls/unlink/unlink07.c struct test_case_t { · line 149
Quoted 10 lines
testcases/kernel/syscalls/unlink/unlink07.c +2
-7- ENOTDIR, filepath_setup}, -#if !defined(UCLINUX ) - { - High_address, "address beyond address space", EFAULT, no_setup}, -#endif - { + ENOTDIR, filepath_setup}, { Longpathname, "pathname too long", ENAMETOOLONG, longpath_setup}, { - (char *)-1, "negative address", EFAULT, no_setup}, { + NULL, "negative address", EFAULT, no_setup}, {
^
And here as well.
testcases/kernel/syscalls/unlink/unlink07.c int main(int ac, char **av) · line 186
Quoted 13 lines
testcases/kernel/syscalls/unlink/unlink07.c +2
-4NULL, NULL, 0, no_setup} };@@ -196,10 +182,9 @@ int main(int ac, char **av) fname = Test_cases[ind].pathname; desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (fname == High_address) - fname =get_high_address (); -#endif +if (!fname) + fname =tst_get_bad_addr (cleanup);
And here as well.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 1/4 lib/get_high_address.c: Add tst_get_bad_addr.h for new API
1) Use mmap() with PROT_NONE to get a bad address and rename get_high_address as tst_get_bad_addr
2) Make sure tst_get_bad_addr can be used by both new API and old API
3) Apply tst_get_bad_addr and remove duplicate tests for EFAULT
4) Just use sbrk(0) + 4 * PAGE_SIZE to test ENOMEM in msync03
5) Remove UCLINUX
--- include/old/test.h | 4 +-- include/tst_get_bad_addr.h | 25 ++++++++++++++ include/tst_test.h | 1 + lib/get_high_address.c | 40 ---------------------- lib/tst_get_bad_addr.c | 31 +++++++++++++++++ testcases/kernel/syscalls/lchown/lchown02.c | 28 ++-------------- testcases/kernel/syscalls/link/link04.c | 43 ++++++++---------------- testcases/kernel/syscalls/lstat/lstat02.c | 23 +++---------- testcases/kernel/syscalls/mkdir/mkdir01.c | 39 ++-------------------- testcases/kernel/syscalls/mknod/mknod06.c | 34 +++---------------- testcases/kernel/syscalls/mremap/mremap03.c | 13 +------- testcases/kernel/syscalls/msync/msync03.c | 9 +---- testcases/kernel/syscalls/rmdir/rmdir05.c | 44 ++----------------------- testcases/kernel/syscalls/stat/stat03.c | 31 +++-------------- testcases/kernel/syscalls/symlink/symlink03.c | 32 ++++-------------- testcases/kernel/syscalls/truncate/truncate03.c | 19 ++++------- testcases/kernel/syscalls/unlink/unlink07.c | 32 +++--------------- 17 files changed, 111 insertions(+), 337 deletions(-) create mode 100644 include/tst_get_bad_addr.h delete mode 100644 lib/get_high_address.c create mode 100644 lib/tst_get_bad_addr.c
include/old/test.h +1 -3
@@ -63,6 +63,7 @@#include "old_device.h" #include "old_tmpdir.h" #include "tst_minmax.h" +#include "tst_get_bad_addr.h" /* * Ensure that NUMSIGS is defined.
@@ -203,9 +204,6 @@ extern int tst_count;/* lib/tst_sig.c */ void tst_sig (int fork_flag,void (*handler)(),void (*cleanup)()); -/* lib/get_high_address.c */ -char *get_high_address (void ); -/* lib/self_exec.c */ void maybe_run_child (void (*child)(),const char *fmt, ...);int self_exec (const char *argv0,const char *fmt, ...);
include/tst_get_bad_addr.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. +* Author: Xiao Yang <[email protected]> +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef TST_GET_BAD_ADDR_H__ +#define TST_GET_BAD_ADDR_H__ + +/* Functions from lib/tst_get_bad_addr.c */ +void *tst_get_bad_addr (void (*cleanup_fn) (void )); + +#endif /* TST_GET_BAD_ADDR_H__ */
include/tst_test.h +1 -0
@@ -40,6 +40,7 @@#include "tst_clone.h" #include "tst_kernel.h" #include "tst_minmax.h" +#include "tst_get_bad_addr.h" /* * Reports testcase result.
lib/get_high_address.c deleted +0 -40
@@ -1,40 +0,0 @@ -/* $Header: /cvsroot/ltp/ltp/lib/get_high_address.c,v 1.6 2009/07/20 10:59:32 vapier Exp $ */ - -/* -* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* Further, this software is distributed without any warranty that it is -* free of the rightful claim of any third person regarding infringement -* or the like. Any license provided herein, whether implied or -* otherwise, applies only to this software file. Patent licenses, if -* any, provided herein do not apply to combinations of this program with -* other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -* -* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, -* Mountain View, CA 94043, or: -* -* http://www.sgi.com -* -* For further information regarding this notice, see: -* -* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ -*/ - -#include <unistd.h> - -char *get_high_address (void ) -{ -return (char *)sbrk (0 ) + (4 *getpagesize ()); -}
lib/tst_get_bad_addr.c new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <sys/mman.h> +#include "test.h" +#include "tst_get_bad_addr.h" + +void *tst_get_bad_addr (void (*cleanup_fn) (void )) +{ +void *bad_addr; + + bad_addr =mmap (0 ,1 ,PROT_NONE ,MAP_PRIVATE |MAP_ANONYMOUS ,0 ,0 ); +if (bad_addr ==MAP_FAILED ) +tst_brkm (TBROK , cleanup_fn,"mmap() failed to get bad address" ); + +return bad_addr; +}
testcases/kernel/syscalls/lchown/lchown02.c +3 -25
@@ -74,12 +74,13 @@TCID_DEFINE (lchown02);int TST_TOTAL =7 ; +static void setup (void ); +static void cleanup (void );static void setup_eperm (int pos);static void setup_eacces (int pos);static void setup_enotdir (int pos);static void setup_longpath (int pos);static void setup_efault (int pos); -static void setup_highaddress (int pos);static char path[PATH_MAX +2 ];
@@ -93,7 +94,6 @@ struct test_case_t {static struct test_case_t test_cases[] = { {SFILE1 ,"Process is not owner/root" ,EPERM , setup_eperm}, {SFILE2 ,"Search permission denied" ,EACCES , setup_eacces}, - {NULL ,"Address beyond address space" ,EFAULT , setup_highaddress}, {NULL ,"Unaccessible address space" ,EFAULT , setup_efault}, {path,"Pathname too long" ,ENAMETOOLONG , setup_longpath}, {SFILE3 ,"Path contains regular file" ,ENOTDIR , setup_enotdir},
@@ -103,9 +103,6 @@ static struct test_case_t test_cases[] = {static struct passwd *ltpuser; -static void setup (void ); -static void cleanup (void ); -int main (int argc,char *argv[]) {int lc;
@@ -252,26 +249,7 @@ static void setup_eacces(int pos LTP_ATTRIBUTE_UNUSED)*/ static void setup_efault (int pos) { -char *bad_addr =0 ; - - bad_addr =mmap (NULL ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,-1 ,0 ); - -if (bad_addr ==MAP_FAILED ) -tst_brkm (TBROK |TERRNO , cleanup,"mmap failed" ); - - test_cases[pos].pathname = bad_addr; -} - -/* -* setup_efault() -- setup for a test condition where lchown(2) returns -1 and -* sets errno to EFAULT. -* -* Use ltp function get_high_address() to compute high address. -*/ -static void setup_highaddress (int pos) -{ - test_cases[pos].pathname =get_high_address (); + test_cases[pos].pathname =tst_get_bad_addr (cleanup); }/*
testcases/kernel/syscalls/link/link04.c +14 -29
84 lines not on this page · raw message
testcases/kernel/syscalls/lstat/lstat02.c +4 -19
@@ -59,10 +59,10 @@static char longpathname[PATH_MAX +2 ];static char elooppathname[sizeof (TEST_ELOOP ) *43 ] ="." ; -#if !defined(UCLINUX ) +static void setup (void ); +static void lstat_verify (int ); +static void cleanup (void );static void bad_addr_setup (int ); -static void high_address_setup (int ); -#endif static struct test_case_t { char *pathname;
@@ -71,10 +71,7 @@ static struct test_case_t { } test_cases[] = { {TEST_EACCES, EACCES, NULL}, {TEST_ENOENT, ENOENT, NULL}, -#if !defined(UCLINUX) {NULL, EFAULT, bad_addr_setup}, - {NULL, EFAULT, high_address_setup}, -#endif {longpathname, ENAMETOOLONG, NULL}, {TEST_ENOTDIR, ENOTDIR, NULL}, {elooppathname, ELOOP, NULL},
@@ -83,10 +80,6 @@ static struct test_case_t {char *TCID ="lstat02" ;int TST_TOTAL =ARRAY_SIZE (test_cases); -static void setup (void ); -static void lstat_verify (int ); -static void cleanup (void ); -int main (int ac,char **av) {int lc;
@@ -140,18 +133,10 @@ static void setup(void)strcat (elooppathname,TEST_ELOOP ); } -#if !defined(UCLINUX )static void bad_addr_setup (int i) { - test_cases[i].pathname =SAFE_MMAP (cleanup,0 ,1 ,PROT_NONE , -MAP_PRIVATE |MAP_ANONYMOUS ,0 ,0 ); -} - -static void high_address_setup (int i) -{ - test_cases[i].pathname = (char *)get_high_address (); + test_cases[i].pathname =tst_get_bad_addr (cleanup); } -#endif static void lstat_verify (int i) {
testcases/kernel/syscalls/mkdir/mkdir01.c +2 -37
@@ -116,7 +116,7 @@ void setup();void cleanup ();char *TCID ="mkdir01" ; -int TST_TOTAL =2 ; +int TST_TOTAL =1 ;char *bad_addr =0 ;
@@ -161,37 +161,6 @@ int main(int ac, char **av) "mkdir - path argument pointing below allocated address space succeeded unexpectedly."); } -#if !defined(UCLINUX ) -/* -* TEST CASE: 2 -* mkdir() call with pointer above allocated address space. -*/ - -/* Call mkdir(2) */ -TEST (mkdir (get_high_address (),0777 )); - -/* check return code */ -if (TEST_RETURN ==-1 ) { - } - -if (TEST_RETURN ==-1 ) { -if (TEST_ERRNO ==EFAULT ) { -tst_resm (TPASS , -"mkdir - path argument pointing above allocated address space failed as expected with errno %d : %s" , -TEST_ERRNO , -strerror (TEST_ERRNO )); - }else { -tst_resm (TFAIL , -"mkdir - path argument pointing above allocated address space failed with errno %d : %s but expected %d (EFAULT)" , -TEST_ERRNO , -strerror (TEST_ERRNO ),EFAULT ); - } - }else { -tst_resm (TFAIL , -"mkdir - path argument pointing above allocated address space succeeded unexpectedly." ); - - } -#endif /* if !defined(UCLINUX) */ }
@@ -212,11 +181,7 @@ void setup(void)/* Create a temporary directory and make it current. */ tst_tmpdir (); - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } + bad_addr =tst_get_bad_addr (cleanup); }/***************************************************************
testcases/kernel/syscalls/mknod/mknod06.c +4 -30
@@ -93,7 +93,6 @@ int setup3(); /* setup function to test mknod for ENOTDIR */int longpath_setup ();/* setup function to test mknod for ENAMETOOLONG */ int no_setup ();/* simply returns 0 to the caller */ char Longpathname[PATH_MAX +2 ]; -char High_address_node[64 ];struct test_case_t {/* test case struct. to hold ref. test cond's */ char *pathname;
@@ -101,15 +100,8 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */int exp_errno;int (*setupfunc) (); } Test_cases[] = { - { - "tnode_1", "Specified node already exists", EEXIST, setup1}, -#if !defined(UCLINUX) - { - (char *)-1, "Negative address", EFAULT, no_setup}, { - High_address_node, "Address beyond address space", EFAULT, - no_setup}, -#endif - { + {"tnode_1", "Specified node already exists", EEXIST, setup1}, { + NULL, "Invalid address", EFAULT, no_setup}, { "testdir_2/tnode_2", "Non-existent file", ENOENT, no_setup}, { "", "Pathname is empty", ENOENT, no_setup}, { Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, {
@@ -119,12 +111,6 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */char *TCID ="mknod06" ;int TST_TOTAL =ARRAY_SIZE (Test_cases); -#if !defined(UCLINUX ) -extern char *get_high_address (); -#else -#endif - -char *bad_addr =0 ;void setup ();/* setup function for the tests */ void cleanup ();/* cleanup function for the tests */
@@ -152,12 +138,6 @@ int main(int ac, char **av) node_name = Test_cases[ind].pathname; test_desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (node_name == High_address_node) { - node_name =get_high_address (); - } -#endif -/* * Call mknod(2) to test different test conditions. * verify that it fails with -1 return value and
@@ -217,16 +197,10 @@ void setup(void)/* Make a temp dir and cd to it */ tst_tmpdir (); -#if !defined(UCLINUX ) - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } - Test_cases[2 ].pathname = bad_addr; -#endif /* call individual setup functions */ for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { +if (!Test_cases[ind].pathname) + Test_cases[ind].pathname =tst_get_bad_addr (cleanup); Test_cases[ind].setupfunc (); } }
testcases/kernel/syscalls/mremap/mremap03.c +1 -12
@@ -92,7 +92,6 @@ int newsize; /* new size of virtual memory block */void setup ();/* Main setup function of test */ void cleanup ();/* cleanup function for the test */ -#if !defined(UCLINUX )int main (int ac,char **av) {int lc;
@@ -174,7 +173,7 @@ void setup(void)* Set the old virtual address point to some address * which is not mapped. */ - bad_addr = (char *)get_high_address (); + bad_addr =tst_get_bad_addr (cleanup); }/*
@@ -187,13 +186,3 @@ void cleanup(void)/* Exit the program */ } - -#else - -int main (void ) -{ -tst_resm (TINFO ,"test is not available on uClinux" ); -tst_exit (); -} - -#endif /* if !defined(UCLINUX) */
testcases/kernel/syscalls/msync/msync03.c +1 -8
@@ -57,10 +57,7 @@ static int fd;static char *addr1;static char *addr2;static char *addr3; - -#if !defined(UCLINUX )static char *addr4; -#endif static size_t page_sz;
@@ -74,9 +71,7 @@ static struct test_case_t { { &addr1, INV_SYNC, EINVAL }, { &addr2, MS_SYNC, EINVAL }, { &addr3, MS_SYNC, EINVAL }, -#if !defined(UCLINUX) { &addr4, MS_SYNC, ENOMEM }, -#endif };static void msync_verify (struct test_case_t *tc);
@@ -135,10 +130,8 @@ static void setup(void)SAFE_GETRLIMIT (NULL ,RLIMIT_DATA , &rl); addr3 = (char *)rl.rlim_max; -#if !defined(UCLINUX )/* memory pointed to by addr4 was not mapped */ - addr4 =get_high_address (); -#endif + addr4 =sbrk (0 ) + (4 * page_sz); }static void msync_verify (struct test_case_t *tc)
testcases/kernel/syscalls/rmdir/rmdir05.c +2 -42
68 lines not on this page · raw message
testcases/kernel/syscalls/stat/stat03.c +4 -27
@@ -103,7 +103,6 @@ char nobody_uid[] = "nobody";struct passwd *ltpuser;char Longpathname[PATH_MAX +2 ]; -char High_address_node[64 ];struct test_case_t {/* test case struct. to hold ref. test cond's */ char *pathname;
@@ -111,15 +110,8 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */int exp_errno;int (*setupfunc) (); } Test_cases[] = { - { - TEST_FILE1, "No Search permissions to process", EACCES, setup1}, -#if !defined(UCLINUX) - { - High_address_node, "Address beyond address space", EFAULT, no_setup}, - { - (char *)-1, "Negative address", EFAULT, no_setup}, -#endif - { + {TEST_FILE1, "No Search permissions to process", EACCES, setup1}, { + NULL, "Invalid address", EFAULT, no_setup}, { Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, { "", "Pathname is empty", ENOENT, no_setup}, { TEST_FILE2, "Path contains regular file", ENOTDIR, setup2}, {
@@ -129,8 +121,6 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */char *TCID ="stat03" ;int TST_TOTAL =ARRAY_SIZE (Test_cases); -char *bad_addr =0 ; -void setup ();/* Main setup function for the tests */ void cleanup ();/* cleanup function for the test */
@@ -158,12 +148,6 @@ int main(int ac, char **av) file_name = Test_cases[ind].pathname; test_desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (file_name == High_address_node) { - file_name = (char *)get_high_address (); - } -#endif -/* * Call stat(2) to test different test conditions. * verify that it fails with -1 return value and
@@ -237,17 +221,10 @@ void setup(void)/* Make a temp dir and cd to it */ tst_tmpdir (); -#if !defined(UCLINUX ) - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } - Test_cases[2 ].pathname = bad_addr; -#endif -/* call individual setup functions */ for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { +if (!Test_cases[ind].pathname) + Test_cases[ind].pathname =tst_get_bad_addr (cleanup); Test_cases[ind].setupfunc (); } }
testcases/kernel/syscalls/symlink/symlink03.c +6 -26
@@ -103,8 +103,6 @@char *TCID ="symlink03" ;int TST_TOTAL =1 ; -char *bad_addr =0 ; -int no_setup ();int setup1 ();/* setup function to test symlink for EACCES */ int setup2 ();/* setup function to test symlink for EEXIST */
@@ -121,18 +119,11 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */int exp_errno;int (*setupfunc) (); } Test_cases[] = { - { -TEST_FILE1 ,SYM_FILE1 ,"No Search permissions to process" , + {TEST_FILE1 ,SYM_FILE1 ,"No Search permissions to process" , EACCES, setup1}, {TEST_FILE2 ,SYM_FILE2 ,"Specified symlink already exists" , - EEXIST, setup2}, -#if !defined(UCLINUX) - { - TESTFILE, High_address_node, "Address beyond address space", - EFAULT, no_setup}, -#endif - { - TESTFILE, (char *)-1, "Negative address", EFAULT, no_setup}, { + EEXIST, setup2}, { + TESTFILE, NULL, "Invalid address", EFAULT, no_setup}, {TESTFILE , Longpathname,"Symlink path too long" ,ENAMETOOLONG , longpath_setup}, { TESTFILE, "", "Symlink Pathname is empty", ENOENT, no_setup}, {
@@ -171,11 +162,7 @@ int main(int ac, char **av) test_file = Test_cases[ind].file; sym_file = Test_cases[ind].link; test_desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (sym_file == High_address_node) { - sym_file = (char *)get_high_address (); - } -#endif +/* * Call symlink(2) to test different test conditions. * verify that it fails with -1 return value and sets
@@ -241,17 +228,10 @@ void setup(void)tst_tmpdir (); -#if !defined(UCLINUX ) - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } - Test_cases[3 ].link = bad_addr; -#endif -/* call individual setup functions */ for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { +if (!Test_cases[ind].link) + Test_cases[ind].link =tst_get_bad_addr (cleanup); Test_cases[ind].setupfunc (); } }
testcases/kernel/syscalls/truncate/truncate03.c +7 -12
@@ -76,10 +76,7 @@ static struct test_case_t { } test_cases[] = { { TEST_FILE1, TRUNC_LEN, EACCES }, { TEST_FILE2, TRUNC_LEN, ENOTDIR }, -#if !defined(UCLINUX) { NULL, TRUNC_LEN, EFAULT }, - { (char *)-1, TRUNC_LEN, EFAULT }, -#endif { long_pathname, TRUNC_LEN, ENAMETOOLONG }, { "", TRUNC_LEN, ENOENT }, { TEST_DIR1, TRUNC_LEN, EISDIR },
@@ -117,9 +114,9 @@ int main(int ac, char **av)void setup (void ) {struct passwd *ltpuser; -char *bad_addr;struct rlimit rlim;sigset_t signalset; +int n;tst_sig (NOFORK ,DEF_HANDLER , cleanup);
@@ -136,14 +133,6 @@ void setup(void)SAFE_TOUCH (cleanup,"t_file" ,FILE_MODE ,NULL ); -#if !defined(UCLINUX ) - test_cases[2 ].pathname = (char *)get_high_address (); - - bad_addr =SAFE_MMAP (cleanup,0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); - test_cases[3 ].pathname = bad_addr; -#endif -memset (long_pathname,'a' ,PATH_MAX +1 );SAFE_MKDIR (cleanup,TEST_DIR1 ,DIR_MODE );
@@ -162,6 +151,12 @@ void setup(void)TEST (sigprocmask (SIG_BLOCK , &signalset,NULL ));if (TEST_RETURN !=0 )tst_brkm (TBROK |TTERRNO , cleanup,"sigprocmask" ); + +for (n =0 ; n <TST_TOTAL ; n++) { +if (!test_cases[n].pathname) + test_cases[n].pathname =tst_get_bad_addr (cleanup); + } + }void truncate_verify (struct test_case_t *tc)
testcases/kernel/syscalls/unlink/unlink07.c +5 -27
@@ -123,13 +123,9 @@void setup ();void cleanup (); -extern char *get_high_address (); -char *TCID ="unlink07" ;int TST_TOTAL =6 ; -char *bad_addr =0 ; -int longpath_setup ();int no_setup ();int filepath_setup ();
@@ -146,21 +142,11 @@ struct test_case_t { "nonexistfile", "non-existent file", ENOENT, no_setup}, { "", "path is empty string", ENOENT, no_setup}, {"nefile/file" ,"path contains a non-existent file" , - ENOENT, no_setup}, -#if !defined(UCLINUX) - { - High_address, "address beyond address space", EFAULT, no_setup}, -#endif - { + ENOENT, no_setup}, {"file/file" ,"path contains a regular file" , - ENOTDIR, filepath_setup}, -#if !defined(UCLINUX) - { - High_address, "address beyond address space", EFAULT, no_setup}, -#endif - { + ENOTDIR, filepath_setup}, { Longpathname, "pathname too long", ENAMETOOLONG, longpath_setup}, { - (char *)-1, "negative address", EFAULT, no_setup}, { + NULL, "invalid address", EFAULT, no_setup}, { NULL, NULL, 0, no_setup} };
@@ -196,10 +182,6 @@ int main(int ac, char **av) fname = Test_cases[ind].pathname; desc = Test_cases[ind].desc; -#if !defined(UCLINUX ) -if (fname == High_address) - fname =get_high_address (); -#endif /* * Call unlink(2) */
@@ -245,13 +227,9 @@ void setup(void)tst_tmpdir (); - bad_addr =mmap (0 ,1 ,PROT_NONE ,MAP_PRIVATE |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } - Test_cases[7 ].pathname = bad_addr; -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { +if (!Test_cases[ind].pathname) + Test_cases[ind].pathname =tst_get_bad_addr (cleanup); Test_cases[ind].setupfunc (); }
Signature · 1 line
1.8.3.1
PATCH v4 2/4 syscalls/unlink05, 06: Cleanup && Convert to new API
1) Take use of some safe macros
2) Merge unlink06 into unlink05
--- runtest/ltplite | 1 - runtest/quickhit | 2 - runtest/stress.part3 | 1 - runtest/syscalls | 1 - testcases/kernel/syscalls/.gitignore | 1 - testcases/kernel/syscalls/unlink/unlink05.c | 253 +++++++--------------------- testcases/kernel/syscalls/unlink/unlink06.c | 215 ----------------------- 7 files changed, 62 insertions(+), 412 deletions(-) delete mode 100644 testcases/kernel/syscalls/unlink/unlink06.c
runtest/ltplite +0 -1
@@ -964,7 +964,6 @@ uname03 uname03 unlink01 symlink01 -T unlink01 unlink05 unlink05 -unlink06 unlink06 unlink07 unlink07 unlink08 unlink08
runtest/quickhit +0 -2
@@ -255,8 +255,6 @@ uname01 uname01 # Basic test for uname(2) unlink05 unlink05 # Basic test for unlink(2) -unlink06 unlink06 -# unlink(2) of a FIFO unlink07 unlink07 # unlink(2) negative testcases unlink08 unlink08
runtest/stress.part3 +0 -1
@@ -840,7 +840,6 @@ uname03 uname03 unlink01 symlink01 -T unlink01 unlink05 unlink05 -unlink06 unlink06 unlink07 unlink07 unlink08 unlink08
runtest/syscalls +0 -1
@@ -1383,7 +1383,6 @@ cve-2012-0957 cve-2012-0957 unlink01 symlink01 -T unlink01 unlink05 unlink05 -unlink06 unlink06 unlink07 unlink07 unlink08 unlink08
testcases/kernel/syscalls/.gitignore +0 -1
@@ -1082,7 +1082,6 @@ /uname/uname02 /uname/uname03 /unlink/unlink05 -/unlink/unlink06 /unlink/unlink07 /unlink/unlink08 /unlinkat/unlinkat01
testcases/kernel/syscalls/unlink/unlink05.c +62 -191
271 lines not on this page · raw message
testcases/kernel/syscalls/unlink/unlink06.c deleted +0 -215
215 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v4 2/4 syscalls/unlink05, 06: Cleanup && Convert to new API
Hi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 3/4 syscalls/unlink07: Cleanup && Convert to new API
In reply to Xiao Yang1) Take use of some safe macros
2) Remove duplicate tests for EFAULT
--- testcases/kernel/syscalls/unlink/unlink07.c | 320 ++++++---------------------- 1 file changed, 62 insertions(+), 258 deletions(-)
testcases/kernel/syscalls/unlink/unlink07.c +62 -258
@@ -1,286 +1,90 @@/* * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. * -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* Further, this software is distributed without any warranty that it is -* free of the rightful claim of any third person regarding infringement -* or the like. Any license provided herein, whether implied or -* otherwise, applies only to this software file. Patent licenses, if -* any, provided herein do not apply to combinations of this program with -* other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -* -* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, -* Mountain View, CA 94043, or: -* -* http://www.sgi.com -* -* For further information regarding this notice, see: -* -* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ -* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* +* Description: +* The testcase checks the various errnos of the unlink(2). +* 1) unlink() returns ENOENT if file doesn't exist. +* 2) unlink() returns ENOENT if path is empty. +* 3) unlink() returns ENOENT if path contains a non-existent file. +* 4) unlink() returns EFAULT if address beyond address space. +* 5) unlink() returns ENOTDIR if path contains a regular file. +* 6) unlink() returns ENAMETOOLONG if path contains a regular file. +* 7) unlink() returns EFAULT if address is invalid. */ -/* $Id: unlink07.c,v 1.8 2009/11/02 13:57:19 subrata_modak Exp $ */ -/********************************************************** -* -* OS Test - Silicon Graphics, Inc. -* -* TEST IDENTIFIER : unlink07 -* -* EXECUTED BY : anyone -* -* TEST TITLE : unlink(2) negative testcases -* -* PARENT DOCUMENT : usctpl01 -* -* TEST CASE TOTAL : 1 -* -* WALL CLOCK TIME : 1 -* -* CPU TYPES : ALL -* -* AUTHOR : Richard Logan -* -* CO-PILOT : William Roske -* -* DATE STARTED : 03/30/94 -* -* INITIAL RELEASE : UNICOS 7.0 -* -* TEST CASES -* -* 1-8) See Testcases structure below. -* -* INPUT SPECIFICATIONS -* The standard options for system call tests are accepted. -* (See the parse_opts(3) man page). -* -* OUTPUT SPECIFICATIONS -*$ -* DURATION -* Terminates - with frequency and infinite modes. -* -* SIGNALS -* Uses SIGUSR1 to pause before test if option set. -* (See the parse_opts(3) man page). -* -* RESOURCES -* None -* -* ENVIRONMENTAL NEEDS -* No run-time environmental needs. -* -* SPECIAL PROCEDURAL REQUIREMENTS -* None -* -* INTERCASE DEPENDENCIES -* None -* -* DETAILED DESCRIPTION -* This is a Phase I test for the unlink(2) system call. It is intended -* to provide a limited exposure of the system call, for now. It -* should/will be extended when full functional tests are written for -* unlink(2). -* -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* Execute system call -* Check return code, if system call failed (return=-1) -* Log the errno and Issue a FAIL message. -* Otherwise, Issue a PASS message. -* -* Cleanup: -* Print errno log and/or timing stats if options given -* -* -*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <sys/mman.h> #include <errno.h> #include <string.h> -#include <signal.h> #include <unistd.h> -#include <sys/param.h> /* for PATH_MAX */ -#include "test.h" - -void setup (); -void cleanup (); +#include <sys/param.h> /* for PATH_MAX */ +#include "tst_test.h" -char *TCID ="unlink07" ; -int TST_TOTAL =6 ; +static char longpathname[PATH_MAX +2 ]; -int longpath_setup (); -int no_setup (); -int filepath_setup (); -char Longpathname[PATH_MAX +2 ]; -char High_address[64 ]; - -struct test_case_t { -char *pathname; +static struct test_case_t { +char *name;char *desc;int exp_errno; -int (*setupfunc) (); -} Test_cases[] = { - { -"nonexistfile" ,"non-existent file" ,ENOENT , no_setup}, { -"" ,"path is empty string" ,ENOENT , no_setup}, { -"nefile/file" ,"path contains a non-existent file" , -ENOENT , no_setup}, { -"file/file" ,"path contains a regular file" , -ENOTDIR , filepath_setup}, { - Longpathname,"pathname too long" ,ENAMETOOLONG , longpath_setup}, { -NULL ,"invalid address" ,EFAULT , no_setup}, { -NULL ,NULL ,0 , no_setup} +} tcases[] = { + {"nonexistfile" ,"non-existent file" ,ENOENT }, + {"" ,"path is empty string" ,ENOENT }, + {"nefile/file" ,"path contains a non-existent file" ,ENOENT }, + {NULL ,"invalid address" ,EFAULT }, + {"file/file" ,"path contains a regular file" ,ENOTDIR }, + {longpathname,"pathname too long" ,ENAMETOOLONG }, }; -/*********************************************************************** -* Main -***********************************************************************/ -int main (int ac,char **av) +static void verify_unlink (unsigned int n) { -int lc; -char *fname; -char *desc; -int ind; - -/*************************************************************** -* parse standard options -***************************************************************/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/*************************************************************** -* perform global setup for test -***************************************************************/ -setup (); - -/*************************************************************** -* check looping state if -c option given -***************************************************************/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { - - fname = Test_cases[ind].pathname; - desc = Test_cases[ind].desc; - -/* -* Call unlink(2) -*/ -TEST (unlink (fname)); - -/* check return code */ -if (TEST_RETURN ==-1 ) { -if (TEST_ERRNO == - Test_cases[ind].exp_errno) -tst_resm (TPASS , -"unlink(<%s>) Failed, errno=%d" , - desc,TEST_ERRNO ); -else -tst_resm (TFAIL , -"unlink(<%s>) Failed, errno=%d, expected errno:%d" , - desc,TEST_ERRNO , - Test_cases - [ind].exp_errno); - }else { -tst_resm (TFAIL , -"unlink(<%s>) returned %ld, expected -1, errno:%d" , - desc,TEST_RETURN , - Test_cases[ind].exp_errno); - } - } +struct test_case_t *tc = &tcases[n]; +TEST (unlink (tc->name)); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"unlink(<%s>) succeeded unexpectedly" , + tc->desc); +return ; } -cleanup (); -tst_exit (); -} - -/*************************************************************** -* setup() - performs all ONE TIME setup for this test. -***************************************************************/ -void setup (void ) -{ -int ind; - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -tst_tmpdir (); - -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { -if (!Test_cases[ind].pathname) - Test_cases[ind].pathname =tst_get_bad_addr (cleanup); - Test_cases[ind].setupfunc (); +if (TEST_ERRNO == tc->exp_errno) { +tst_res (TPASS |TTERRNO ,"unlink(<%s>) failed as expected" , + tc->desc); + }else { +tst_res (TFAIL |TTERRNO ,"unlink(<%s>) failed, expected errno:%s" , + tc->desc,tst_strerrno (tc->exp_errno)); } - } -/*************************************************************** -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -***************************************************************/ -void cleanup (void ) +static void setup (void ) { -chmod ("unwrite_dir" ,0777 ); -chmod ("unsearch_dir" ,0777 ); +int n; -tst_rmdir (); - -} - -/****************************************************************** -* -******************************************************************/ -int no_setup (void ) -{ -return 0 ; -} +SAFE_TOUCH ("file" ,0777 ,NULL ); -/****************************************************************** -* -******************************************************************/ -int longpath_setup (void ) -{ -int ind; +memset (longpathname,'a' ,PATH_MAX +2 ); -for (ind =0 ; ind <=PATH_MAX +1 ; ind++) { - Longpathname[ind] ='a' ; +for (n =0 ; n <ARRAY_SIZE (tcases); n++) { +if (!tcases[n].name) + tcases[n].name =tst_get_bad_addr (NULL ); } -return 0 ; - } -/****************************************************************** -* -******************************************************************/ -int filepath_setup (void ) -{ -int fd; - -if ((fd =creat ("file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup,"creat(file) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); -return 0 ; -} +static struct tst_test test = { + .needs_tmpdir =1 , + .setup = setup, + .tcnt =ARRAY_SIZE (tcases), + .test = verify_unlink, +};
Signature · 1 line
1.8.3.1
PATCH v4 3/4 syscalls/unlink07: Cleanup && Convert to new API
Hi!
Pushed with minor fixes (the description wasn't correct sice we have only one EFAULT test now), thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 4/4 syscalls/unlink08: Cleanup && Convert to new API
In reply to Xiao Yang1) Take use of some safe macros
2) Remove unused code
--- testcases/kernel/syscalls/unlink/unlink08.c | 402 ++++++---------------------- 1 file changed, 79 insertions(+), 323 deletions(-)
testcases/kernel/syscalls/unlink/unlink08.c +79 -323
@@ -1,355 +1,111 @@/* * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. * -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* Further, this software is distributed without any warranty that it is -* free of the rightful claim of any third person regarding infringement -* or the like. Any license provided herein, whether implied or -* otherwise, applies only to this software file. Patent licenses, if -* any, provided herein do not apply to combinations of this program with -* other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -* -* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, -* Mountain View, CA 94043, or: -* -* http://www.sgi.com -* -* For further information regarding this notice, see: -* -* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ -* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* $Id: unlink08.c,v 1.5 2009/11/02 13:57:19 subrata_modak Exp $ */ -/********************************************************** -* -* OS Test - Silicon Graphics, Inc. -* -* TEST IDENTIFIER : unlink08 -* -* EXECUTED BY : anyone -* -* TEST TITLE : unlink(2) negative testcases -* -* PARENT DOCUMENT : usctpl01 -* -* TEST CASE TOTAL : 3 -* -* WALL CLOCK TIME : 1 -* -* CPU TYPES : ALL -* -* AUTHOR : Richard Logan -* -* CO-PILOT : William Roske -* -* DATE STARTED : 03/30/94 -* -* INITIAL RELEASE : UNICOS 7.0 -* -* TEST CASES -* -* 1-3) See Testcases structure below. -* -* INPUT SPECIFICATIONS -* The standard options for system call tests are accepted. -* (See the parse_opts(3) man page). -* -* OUTPUT SPECIFICATIONS -*$ -* DURATION -* Terminates - with frequency and infinite modes. -* -* SIGNALS -* Uses SIGUSR1 to pause before test if option set. -* (See the parse_opts(3) man page). -* -* RESOURCES -* None -* -* ENVIRONMENTAL NEEDS -* No run-time environmental needs. -* -* SPECIAL PROCEDURAL REQUIREMENTS -* None -* -* INTERCASE DEPENDENCIES -* None -* -* DETAILED DESCRIPTION -* This is a Phase I test for the unlink(2) system call. It is intended -* to provide a limited exposure of the system call, for now. It -* should/will be extended when full functional tests are written for -* unlink(2). -* -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* Execute system call -* Check return code, if system call failed (return=-1) -* Log the errno and Issue a FAIL message. -* Otherwise, Issue a PASS message. -* -* Cleanup: -* Print errno log and/or timing stats if options given -* -* -*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ - -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <errno.h> -#include <signal.h> -#include <unistd.h> -#include <string.h> -#include "test.h" -#include "safe_macros.h" -void setup (void ); -void cleanup (void ); +/* +* Description: +* The testcase checks the various errnos of the unlink(2). +* 1) unlink() returns EACCES when deleting file in unwritable directory +* as an unprivileged user. +* 2) unlink() returns EACCES when deleting file in "unsearchable directory +* as an unprivileged user. +* 3) unlink() returns EISDIR when deleting directory in linux. +* 4) unlink() returns EPERM when deleting directory in non-linux. +*/ -char *TCID ="unlink08" ; -int TST_TOTAL =3 ; +#include <errno.h> +#include <stdlib.h> +#include <sys/types.h> +#include <pwd.h> +#include "tst_test.h" -int unwrite_dir_setup (int flag); -int unsearch_dir_setup (int flag); -int dir_setup (int flag); -int no_setup (int flag); +static struct passwd *pw; -struct test_case_t { -char *pathname; +static struct test_case_t { +char *name;char *desc; -int (*setupfunc) (int flag); -int exp_ret;/* -1 means error, 0 means != -1 */ int exp_errno; -} Test_cases[] = { - { -"unwrite_dir/file" ,"unwritable directory" , unwrite_dir_setup, --1 ,EACCES }, { -"unsearch_dir/file" ,"unsearchable directory" , - unsearch_dir_setup,-1 ,EACCES }, -#ifdef linux - { -"regdir" ,"directory" , dir_setup,-1 ,EISDIR }, +int exp_user; +} tcases[] = { + {"unwrite_dir/file" ,"unwritable directory" ,EACCES ,1 }, + {"unsearch_dir/file" ,"unsearchable directory" ,EACCES ,1 }, +#ifdef __linux__ + {"regdir" ,"directory" ,EISDIR ,0 }, #else - { -"regdir" ,"directory" , dir_setup,-1 ,EPERM }, + {"regdir" ,"directory" ,EPERM ,0 }, #endif - { -NULL ,NULL , no_setup,-1 ,0 } }; -/*********************************************************************** -* Main -***********************************************************************/ -int main (int ac,char **av) -{ -int lc; -char *fname; -char *desc; -int ind; - -/*************************************************************** -* parse standard options -***************************************************************/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/*************************************************************** -* perform global setup for test -***************************************************************/ -setup (); - -/*************************************************************** -* check looping state if -c option given -***************************************************************/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { - - fname = Test_cases[ind].pathname; - desc = Test_cases[ind].desc; - -/* -* Call unlink(2) -*/ -TEST (unlink (fname)); - -/* check return code */ -if (TEST_RETURN ==-1 ) { -if (Test_cases[ind].exp_ret ==-1 ) {/* neg test */ -if (TEST_ERRNO == - Test_cases[ind].exp_errno) -tst_resm (TPASS , -"unlink(<%s>) Failed, errno=%d" , - desc, -TEST_ERRNO ); -else -tst_resm (TFAIL , -"unlink(<%s>) Failed, errno=%d, expected errno:%d" , - desc, -TEST_ERRNO , - Test_cases - [ind].exp_errno); - }else { -tst_resm (TFAIL , -"unlink(<%s>) Failed, errno=%d" , - desc,TEST_ERRNO ); - } - }else { -if (Test_cases[ind].exp_ret ==-1 ) { -tst_resm (TFAIL , -"unlink(<%s>) returned %ld, expected -1, errno:%d" , - desc,TEST_RETURN , - Test_cases[ind].exp_errno); - }else { -tst_resm (TPASS , -"unlink(<%s>) returned %ld" , - desc,TEST_RETURN ); - } - Test_cases[ind].setupfunc (1 ); - } - } - - } - -cleanup (); -tst_exit (); -} - -/*************************************************************** -* setup() - performs all ONE TIME setup for this test. -***************************************************************/ -void setup (void ) +static void verify_unlink (struct test_case_t *tc) { -int ind; -int postest =0 ; - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -tst_tmpdir (); - -if (geteuid () ==0 ) { - postest++; +TEST (unlink (tc->name)); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"unlink(<%s>) succeeded unexpectedly" , + tc->desc); +return ; } -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { -if (Test_cases[ind].exp_errno ==EACCES && postest) - Test_cases[ind].exp_ret =0 ;/* set as a pos test */ - Test_cases[ind].setupfunc (0 ); +if (TEST_ERRNO == tc->exp_errno) { +tst_res (TPASS |TTERRNO ,"unlink(<%s>) failed as expected" , + tc->desc); + }else { +tst_res (TFAIL |TTERRNO ,"unlink(<%s>) failed, expected errno:%s" , + tc->desc,tst_strerrno (tc->exp_errno)); } - -} - -/*************************************************************** -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -***************************************************************/ -void cleanup (void ) -{ -chmod ("unwrite_dir" ,0777 ); -chmod ("unsearch_dir" ,0777 ); - -tst_rmdir (); - } -/****************************************************************** -* -******************************************************************/ -int unwrite_dir_setup (int flag) +static void do_unlink (unsigned int n) { -int fd; - -if (!flag) {/* initial setup */ -SAFE_MKDIR (cleanup,"unwrite_dir" ,0777 ); - -if ((fd =creat ("unwrite_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unwrite_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); +struct test_case_t *cases = &tcases[n]; +pid_t pid; + +if (cases->exp_user) { + pid =SAFE_FORK (); +if (!pid) { +SAFE_SETUID (pw->pw_uid); +verify_unlink (cases); +exit (0 ); } -close (fd); - -SAFE_CHMOD (cleanup,"unwrite_dir" ,0555 ); - }else {/* resetup */ -SAFE_CHMOD (cleanup,"unwrite_dir" ,0777 ); -if ((fd =creat ("unwrite_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unwrite_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); - -SAFE_CHMOD (cleanup,"unwrite_dir" ,0555 ); +SAFE_WAITPID (pid,NULL ,0 ); + }else { +verify_unlink (cases); } -return 0 ; } -/****************************************************************** -* -******************************************************************/ -int unsearch_dir_setup (int flag) +static void setup (void ) { -int fd; - -if (!flag) {/* initial setup */ -SAFE_MKDIR (cleanup,"unsearch_dir" ,0777 ); - -if ((fd =creat ("unsearch_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unsearch_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); +SAFE_MKDIR ("unwrite_dir" ,0777 ); +SAFE_TOUCH ("unwrite_dir/file" ,0777 ,NULL ); +SAFE_CHMOD ("unwrite_dir" ,0555 ); -SAFE_CHMOD (cleanup,"unsearch_dir" ,0666 ); - }else {/* resetup */ -SAFE_CHMOD (cleanup,"unsearch_dir" ,0777 ); +SAFE_MKDIR ("unsearch_dir" ,0777 ); +SAFE_TOUCH ("unsearch_dir/file" ,0777 ,NULL ); +SAFE_CHMOD ("unsearch_dir" ,0666 ); -if ((fd =creat ("unsearch_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unsearch_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); +SAFE_MKDIR ("regdir" ,0777 ); -SAFE_CHMOD (cleanup,"unsearch_dir" ,0666 ); - } -return 0 ; + pw =SAFE_GETPWNAM ("nobody" ); } -/****************************************************************** -* -******************************************************************/ -int dir_setup (int flag) -{ -SAFE_MKDIR (cleanup,"regdir" ,0777 ); -return 0 ; -} - -/****************************************************************** -* -******************************************************************/ -int no_setup (int flag) -{ -return 0 ; -} +static struct tst_test test = { + .needs_root =1 , + .forks_child =1 , + .needs_tmpdir =1 , + .setup = setup, + .tcnt =ARRAY_SIZE (tcases), + .test = do_unlink, +};
Signature · 1 line
1.8.3.1
PATCH v4 4/4 syscalls/unlink08: Cleanup && Convert to new API
Hi!
Pushed with minor changes (got rid of the non-linux code), thanks.
This patchset was a nice cleanup :-)
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 1/4 lib/get_high_address.c: Add tst_get_bad_addr.h for new API
In reply to Xiao YangHi!
Pushed with minor changes, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 3/5 syscalls/unlink05, 06: Cleanup && Convert to new API
In reply to Xiao Yang1) Take use of some safe macros
2) Merge unlink06 into unlink05
--- runtest/ltplite | 1 - runtest/quickhit | 2 - runtest/stress.part3 | 1 - runtest/syscalls | 1 - testcases/kernel/syscalls/.gitignore | 1 - testcases/kernel/syscalls/unlink/unlink05.c | 215 +++++++--------------------- testcases/kernel/syscalls/unlink/unlink06.c | 215 ---------------------------- 7 files changed, 52 insertions(+), 384 deletions(-) delete mode 100644 testcases/kernel/syscalls/unlink/unlink06.c
runtest/ltplite +0 -1
@@ -964,7 +964,6 @@ uname03 uname03 unlink01 symlink01 -T unlink01 unlink05 unlink05 -unlink06 unlink06 unlink07 unlink07 unlink08 unlink08
runtest/quickhit +0 -2
@@ -255,8 +255,6 @@ uname01 uname01 # Basic test for uname(2) unlink05 unlink05 # Basic test for unlink(2) -unlink06 unlink06 -# unlink(2) of a FIFO unlink07 unlink07 # unlink(2) negative testcases unlink08 unlink08
runtest/stress.part3 +0 -1
@@ -840,7 +840,6 @@ uname03 uname03 unlink01 symlink01 -T unlink01 unlink05 unlink05 -unlink06 unlink06 unlink07 unlink07 unlink08 unlink08
runtest/syscalls +0 -1
@@ -1383,7 +1383,6 @@ cve-2012-0957 cve-2012-0957 unlink01 symlink01 -T unlink01 unlink05 unlink05 -unlink06 unlink06 unlink07 unlink07 unlink08 unlink08
testcases/kernel/syscalls/.gitignore +0 -1
@@ -1082,7 +1082,6 @@ /uname/uname02 /uname/uname03 /unlink/unlink05 -/unlink/unlink06 /unlink/unlink07 /unlink/unlink08 /unlinkat/unlinkat01
testcases/kernel/syscalls/unlink/unlink05.c +52 -163
234 lines not on this page · raw message
testcases/kernel/syscalls/unlink/unlink06.c deleted +0 -215
215 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 4/5 syscalls/unlink07: Cleanup && Convert to new API
In reply to Xiao Yang1) Take use of some safe macros
2) Remove duplicate tests for EFAULT
--- testcases/kernel/syscalls/unlink/unlink07.c | 282 +++++----------------------- 1 file changed, 50 insertions(+), 232 deletions(-)
testcases/kernel/syscalls/unlink/unlink07.c +50 -232
@@ -28,259 +28,77 @@* For further information regarding this notice, see: * * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ -* */ -/* $Id: unlink07.c,v 1.8 2009/11/02 13:57:19 subrata_modak Exp $ */ -/********************************************************** -* -* OS Test - Silicon Graphics, Inc. -* -* TEST IDENTIFIER : unlink07 -* -* EXECUTED BY : anyone -* -* TEST TITLE : unlink(2) negative testcases -* -* PARENT DOCUMENT : usctpl01 -* -* TEST CASE TOTAL : 1 -* -* WALL CLOCK TIME : 1 -* -* CPU TYPES : ALL -* -* AUTHOR : Richard Logan -* -* CO-PILOT : William Roske -* -* DATE STARTED : 03/30/94 -* -* INITIAL RELEASE : UNICOS 7.0 -* -* TEST CASES -* -* 1-8) See Testcases structure below. -* -* INPUT SPECIFICATIONS -* The standard options for system call tests are accepted. -* (See the parse_opts(3) man page). -* -* OUTPUT SPECIFICATIONS -*$ -* DURATION -* Terminates - with frequency and infinite modes. -* -* SIGNALS -* Uses SIGUSR1 to pause before test if option set. -* (See the parse_opts(3) man page). -* -* RESOURCES -* None -* -* ENVIRONMENTAL NEEDS -* No run-time environmental needs. -* -* SPECIAL PROCEDURAL REQUIREMENTS -* None -* -* INTERCASE DEPENDENCIES -* None -* -* DETAILED DESCRIPTION -* This is a Phase I test for the unlink(2) system call. It is intended -* to provide a limited exposure of the system call, for now. It -* should/will be extended when full functional tests are written for -* unlink(2). -* -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* Execute system call -* Check return code, if system call failed (return=-1) -* Log the errno and Issue a FAIL message. -* Otherwise, Issue a PASS message. -* -* Cleanup: -* Print errno log and/or timing stats if options given -* -* -*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <sys/mman.h> +/* +* Description: +* The testcase checks the various errnos of the unlink(2). +* 1) unlink() returns ENOENT if file doesn't exist. +* 2) unlink() returns ENOENT if path is empty. +* 3) unlink() returns ENOENT if path contains a non-existent file. +* 4) unlink() returns EFAULT if address beyond address space. +* 5) unlink() returns ENOTDIR if path contains a regular file. +* 6) unlink() returns ENAMETOOLONG if path contains a regular file. +* 7) unlink() returns EFAULT if address is negative. +*/ +#include <errno.h> #include <string.h> -#include <signal.h> #include <unistd.h> -#include <sys/param.h> /* for PATH_MAX */ -#include "test.h" +#include <sys/param.h> /* for PATH_MAX */ +#include "tst_test.h" -void setup (); -void cleanup (); +static char longpathname[PATH_MAX +2 ]; -char *TCID ="unlink07" ; -int TST_TOTAL =6 ; - -int longpath_setup (); -int no_setup (); -int filepath_setup (); -char Longpathname[PATH_MAX +2 ]; -char High_address[64 ]; - -struct test_case_t { -char *pathname; +static struct test_case_t { +char *name;char *desc;int exp_errno; -int (*setupfunc) (); -} Test_cases[] = { - { -"nonexistfile" ,"non-existent file" ,ENOENT , no_setup}, { -"" ,"path is empty string" ,ENOENT , no_setup}, { -"nefile/file" ,"path contains a non-existent file" , -ENOENT , no_setup}, { -"file/file" ,"path contains a regular file" , -ENOTDIR , filepath_setup}, { - Longpathname,"pathname too long" ,ENAMETOOLONG , longpath_setup}, { - (char *)-1 ,"negative address" ,EFAULT , no_setup}, { -NULL ,NULL ,0 , no_setup} +} tcases[] = { + {"nonexistfile" ,"non-existent file" ,ENOENT }, + {"" ,"path is empty string" ,ENOENT }, + {"nefile/file" ,"path contains a non-existent file" ,ENOENT }, + {NULL ,"negative address" ,EFAULT }, + {"file/file" ,"path contains a regular file" ,ENOTDIR }, + {longpathname,"pathname too long" ,ENAMETOOLONG }, }; -/*********************************************************************** -* Main -***********************************************************************/ -int main (int ac,char **av) +static void verify_unlink (unsigned int n) { -int lc; -char *fname; -char *desc; -int ind; - -/*************************************************************** -* parse standard options -***************************************************************/ -tst_parse_opts (ac, av,NULL ,NULL ); +struct test_case_t *tc = &tcases[n]; -/*************************************************************** -* perform global setup for test -***************************************************************/ -setup (); - -/*************************************************************** -* check looping state if -c option given -***************************************************************/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { - - fname = Test_cases[ind].pathname; - desc = Test_cases[ind].desc; - -/* -* Call unlink(2) -*/ -TEST (unlink (fname)); - -/* check return code */ -if (TEST_RETURN ==-1 ) { -if (TEST_ERRNO == - Test_cases[ind].exp_errno) -tst_resm (TPASS , -"unlink(<%s>) Failed, errno=%d" , - desc,TEST_ERRNO ); -else -tst_resm (TFAIL , -"unlink(<%s>) Failed, errno=%d, expected errno:%d" , - desc,TEST_ERRNO , - Test_cases - [ind].exp_errno); - }else { -tst_resm (TFAIL , -"unlink(<%s>) returned %ld, expected -1, errno:%d" , - desc,TEST_RETURN , - Test_cases[ind].exp_errno); - } - } +if (!tc->name) + tc->name =tst_get_bad_addr (); +TEST (unlink (tc->name)); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"unlink(<%s>) succeeded unexpectedly" , + tc->desc); +return ; } -cleanup (); -tst_exit (); -} - -/*************************************************************** -* setup() - performs all ONE TIME setup for this test. -***************************************************************/ -void setup (void ) -{ -int ind; - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -tst_tmpdir (); - - Test_cases[5 ].pathname = (char *)tst_get_bad_addr (); - -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { - Test_cases[ind].setupfunc (); +if (TEST_ERRNO == tc->exp_errno) { +tst_res (TPASS |TTERRNO ,"unlink(<%s>) failed as expected" , + tc->desc); + }else { +tst_res (TFAIL |TTERRNO ,"unlink(<%s>) failed, expected errno:%s" , + tc->desc,tst_strerrno (tc->exp_errno)); } - -} - -/*************************************************************** -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -***************************************************************/ -void cleanup (void ) -{ -chmod ("unwrite_dir" ,0777 ); -chmod ("unsearch_dir" ,0777 ); - -tst_rmdir (); - } -/****************************************************************** -* -******************************************************************/ -int no_setup (void ) +static void setup (void ) { -return 0 ; -} +int fd; -/****************************************************************** -* -******************************************************************/ -int longpath_setup (void ) -{ -int ind; - -for (ind =0 ; ind <=PATH_MAX +1 ; ind++) { - Longpathname[ind] ='a' ; - } -return 0 ; + fd =SAFE_CREAT ("file" ,0777 ); +SAFE_CLOSE (fd); +memset (longpathname,'a' ,PATH_MAX +2 ); } -/****************************************************************** -* -******************************************************************/ -int filepath_setup (void ) -{ -int fd; - -if ((fd =creat ("file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup,"creat(file) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); -return 0 ; -} +static struct tst_test test = { + .needs_tmpdir =1 , + .setup = setup, + .tcnt =ARRAY_SIZE (tcases), + .test = verify_unlink, +};
Signature · 1 line
1.8.3.1
PATCH v2 5/5 syscalls/unlink08: Cleanup && Convert to new API
In reply to Xiao Yang1) Take use of some safe macros
2) Remove unused code
--- testcases/kernel/syscalls/unlink/unlink08.c | 363 ++++++---------------------- 1 file changed, 69 insertions(+), 294 deletions(-)
testcases/kernel/syscalls/unlink/unlink08.c +69 -294
@@ -28,328 +28,103 @@* For further information regarding this notice, see: * * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ -* */ -/* $Id: unlink08.c,v 1.5 2009/11/02 13:57:19 subrata_modak Exp $ */ -/********************************************************** -* -* OS Test - Silicon Graphics, Inc. -* -* TEST IDENTIFIER : unlink08 -* -* EXECUTED BY : anyone -* -* TEST TITLE : unlink(2) negative testcases -* -* PARENT DOCUMENT : usctpl01 -* -* TEST CASE TOTAL : 3 -* -* WALL CLOCK TIME : 1 -* -* CPU TYPES : ALL -* -* AUTHOR : Richard Logan -* -* CO-PILOT : William Roske -* -* DATE STARTED : 03/30/94 -* -* INITIAL RELEASE : UNICOS 7.0 -* -* TEST CASES -* -* 1-3) See Testcases structure below. -* -* INPUT SPECIFICATIONS -* The standard options for system call tests are accepted. -* (See the parse_opts(3) man page). -* -* OUTPUT SPECIFICATIONS -*$ -* DURATION -* Terminates - with frequency and infinite modes. -* -* SIGNALS -* Uses SIGUSR1 to pause before test if option set. -* (See the parse_opts(3) man page). -* -* RESOURCES -* None -* -* ENVIRONMENTAL NEEDS -* No run-time environmental needs. -* -* SPECIAL PROCEDURAL REQUIREMENTS -* None -* -* INTERCASE DEPENDENCIES -* None -* -* DETAILED DESCRIPTION -* This is a Phase I test for the unlink(2) system call. It is intended -* to provide a limited exposure of the system call, for now. It -* should/will be extended when full functional tests are written for -* unlink(2). -* -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* Execute system call -* Check return code, if system call failed (return=-1) -* Log the errno and Issue a FAIL message. -* Otherwise, Issue a PASS message. -* -* Cleanup: -* Print errno log and/or timing stats if options given -* -* -*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ - -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <errno.h> -#include <signal.h> -#include <unistd.h> -#include <string.h> -#include "test.h" -#include "safe_macros.h" -void setup (void ); -void cleanup (void ); +/* +* Description: +* The testcase checks the various errnos of the unlink(2). +* 1) unlink() returns EACCES when deleting file in unwritable directory +* as an unprivileged user. +* 2) unlink() returns EACCES when deleting file in "unsearchable directory +* as an unprivileged user. +* 3) unlink() returns EISDIR when deleting directory in linux. +* 4) unlink() returns EPERM when deleting directory in non-linux. +*/ -char *TCID ="unlink08" ; -int TST_TOTAL =3 ; +#include <errno.h> +#include <stdlib.h> +#include <sys/types.h> +#include <pwd.h> +#include "tst_test.h" -int unwrite_dir_setup (int flag); -int unsearch_dir_setup (int flag); -int dir_setup (int flag); -int no_setup (int flag); +static struct passwd *pw; -struct test_case_t { -char *pathname; +static struct test_case_t { +char *name;char *desc; -int (*setupfunc) (int flag); -int exp_ret;/* -1 means error, 0 means != -1 */ int exp_errno; -} Test_cases[] = { - { -"unwrite_dir/file" ,"unwritable directory" , unwrite_dir_setup, --1 ,EACCES }, { -"unsearch_dir/file" ,"unsearchable directory" , - unsearch_dir_setup,-1 ,EACCES }, -#ifdef linux - { -"regdir" ,"directory" , dir_setup,-1 ,EISDIR }, +int exp_user; +} tcases[] = { + {"unwrite_dir/file" ,"unwritable directory" ,EACCES ,1 }, + {"unsearch_dir/file" ,"unsearchable directory" ,EACCES ,1 }, +#ifdef __linux__ + {"regdir" ,"directory" ,EISDIR ,0 }, #else - { -"regdir" ,"directory" , dir_setup,-1 ,EPERM }, + {"regdir" ,"directory" ,EPERM ,0 }, #endif - { -NULL ,NULL , no_setup,-1 ,0 } }; -/*********************************************************************** -* Main -***********************************************************************/ -int main (int ac,char **av) +static void verify_unlink (struct test_case_t *tc) { -int lc; -char *fname; -char *desc; -int ind; - -/*************************************************************** -* parse standard options -***************************************************************/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/*************************************************************** -* perform global setup for test -***************************************************************/ -setup (); - -/*************************************************************** -* check looping state if -c option given -***************************************************************/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { - - fname = Test_cases[ind].pathname; - desc = Test_cases[ind].desc; - -/* -* Call unlink(2) -*/ -TEST (unlink (fname)); - -/* check return code */ -if (TEST_RETURN ==-1 ) { -if (Test_cases[ind].exp_ret ==-1 ) {/* neg test */ -if (TEST_ERRNO == - Test_cases[ind].exp_errno) -tst_resm (TPASS , -"unlink(<%s>) Failed, errno=%d" , - desc, -TEST_ERRNO ); -else -tst_resm (TFAIL , -"unlink(<%s>) Failed, errno=%d, expected errno:%d" , - desc, -TEST_ERRNO , - Test_cases - [ind].exp_errno); - }else { -tst_resm (TFAIL , -"unlink(<%s>) Failed, errno=%d" , - desc,TEST_ERRNO ); - } - }else { -if (Test_cases[ind].exp_ret ==-1 ) { -tst_resm (TFAIL , -"unlink(<%s>) returned %ld, expected -1, errno:%d" , - desc,TEST_RETURN , - Test_cases[ind].exp_errno); - }else { -tst_resm (TPASS , -"unlink(<%s>) returned %ld" , - desc,TEST_RETURN ); - } - Test_cases[ind].setupfunc (1 ); - } - } - - } - -cleanup (); -tst_exit (); -} - -/*************************************************************** -* setup() - performs all ONE TIME setup for this test. -***************************************************************/ -void setup (void ) -{ -int ind; -int postest =0 ; - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -tst_tmpdir (); - -if (geteuid () ==0 ) { - postest++; +TEST (unlink (tc->name)); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"unlink(<%s>) succeeded unexpectedly" , + tc->desc); +return ; } -for (ind =0 ; Test_cases[ind].desc !=NULL ; ind++) { -if (Test_cases[ind].exp_errno ==EACCES && postest) - Test_cases[ind].exp_ret =0 ;/* set as a pos test */ - Test_cases[ind].setupfunc (0 ); +if (TEST_ERRNO == tc->exp_errno) { +tst_res (TPASS |TTERRNO ,"unlink(<%s>) failed as expected" , + tc->desc); + }else { +tst_res (TFAIL |TTERRNO ,"unlink(<%s>) failed, expected errno:%s" , + tc->desc,tst_strerrno (tc->exp_errno)); } - -} - -/*************************************************************** -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -***************************************************************/ -void cleanup (void ) -{ -chmod ("unwrite_dir" ,0777 ); -chmod ("unsearch_dir" ,0777 ); - -tst_rmdir (); - } -/****************************************************************** -* -******************************************************************/ -int unwrite_dir_setup (int flag) +static void do_unlink (unsigned int n) { -int fd; - -if (!flag) {/* initial setup */ -SAFE_MKDIR (cleanup,"unwrite_dir" ,0777 ); - -if ((fd =creat ("unwrite_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unwrite_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); - -SAFE_CHMOD (cleanup,"unwrite_dir" ,0555 ); - }else {/* resetup */ -SAFE_CHMOD (cleanup,"unwrite_dir" ,0777 ); - -if ((fd =creat ("unwrite_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unwrite_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); +struct test_case_t *cases = &tcases[n]; +pid_t pid; + +if (cases->exp_user) { + pid =SAFE_FORK (); +if (!pid) { +SAFE_SETUID (pw->pw_uid); +verify_unlink (cases); +exit (0 ); } -close (fd); -SAFE_CHMOD (cleanup,"unwrite_dir" ,0555 ); +SAFE_WAITPID (pid,NULL ,0 ); + }else { +verify_unlink (cases); } -return 0 ; } -/****************************************************************** -* -******************************************************************/ -int unsearch_dir_setup (int flag) +static void setup (void ) {int fd; -if (!flag) {/* initial setup */ -SAFE_MKDIR (cleanup,"unsearch_dir" ,0777 ); - -if ((fd =creat ("unsearch_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unsearch_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); - -SAFE_CHMOD (cleanup,"unsearch_dir" ,0666 ); - }else {/* resetup */ -SAFE_CHMOD (cleanup,"unsearch_dir" ,0777 ); +SAFE_MKDIR ("unwrite_dir" ,0777 ); + fd =SAFE_CREAT ("unwrite_dir/file" ,0777 ); +SAFE_CLOSE (fd); +SAFE_CHMOD ("unwrite_dir" ,0555 ); -if ((fd =creat ("unsearch_dir/file" ,0777 )) ==-1 ) { -tst_brkm (TBROK , cleanup, -"creat(unsearch_dir/file, 0777) failed, errno:%d %s" , - errno,strerror (errno)); - } -close (fd); +SAFE_MKDIR ("unsearch_dir" ,0777 ); + fd =SAFE_CREAT ("unsearch_dir/file" ,0777 ); +SAFE_CLOSE (fd); +SAFE_CHMOD ("unsearch_dir" ,0666 ); -SAFE_CHMOD (cleanup,"unsearch_dir" ,0666 ); - } -return 0 ; -} +SAFE_MKDIR ("regdir" ,0777 ); -/****************************************************************** -* -******************************************************************/ -int dir_setup (int flag) -{ -SAFE_MKDIR (cleanup,"regdir" ,0777 ); -return 0 ; + pw =SAFE_GETPWNAM ("nobody" ); } -/****************************************************************** -* -******************************************************************/ -int no_setup (int flag) -{ -return 0 ; -} +static struct tst_test test = { + .needs_root =1 , + .forks_child =1 , + .needs_tmpdir =1 , + .setup = setup, + .tcnt =ARRAY_SIZE (tcases), + .test = do_unlink, +};
Signature · 1 line
1.8.3.1
PATCH v2 1/5 syscalls/mremap03: Do not pass MAP_FAILED into mremap()
In reply to Xiao YangHi!
Applied, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]