diff options
author | Abhishek Singh <abhishekkumarsingh.cse@gmail.com> | 2013-04-16 19:17:16 +0530 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-05-02 20:12:41 +0200 |
commit | 25255e4d0e1517a5d443e8fee22e91862e255702 (patch) | |
tree | 2d418e5b0683d496695989b8cdd7e893d281ebc8 | |
parent | 9a0255c508ede92423a1f8a02c6c38328482c55f (diff) | |
download | sssd-25255e4d0e1517a5d443e8fee22e91862e255702.tar.gz sssd-25255e4d0e1517a5d443e8fee22e91862e255702.tar.bz2 sssd-25255e4d0e1517a5d443e8fee22e91862e255702.zip |
Fix segmentation fault in test_io.
tests_set_cwd is used and relativepath calculation method is changed and is made general based on
basedir.
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | src/tests/cmocka/test_io.c | 23 |
2 files changed, 21 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am index 958a56a1..d01ec759 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1249,7 +1249,8 @@ test_find_uid_LDADD = \ test_io_SOURCES = \ src/tests/cmocka/test_io.c \ - src/util/io.c + src/util/io.c \ + src/tests/common.c test_io_CFLAGS = \ $(AM_CFLAGS) test_io_LDADD = \ diff --git a/src/tests/cmocka/test_io.c b/src/tests/cmocka/test_io.c index 4d21b2e2..266f2ce9 100644 --- a/src/tests/cmocka/test_io.c +++ b/src/tests/cmocka/test_io.c @@ -24,6 +24,7 @@ #include <stdio.h> #include <fcntl.h> +#include <errno.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> @@ -32,10 +33,12 @@ #include <cmocka.h> #include <dirent.h> #include <unistd.h> +#include <libgen.h> #include "limits.h" #include "util/io.h" #include "util/util.h" +#include "tests/common.h" #define FILE_PATH TEST_DIR"/test_io.XXXXXX" #define NON_EX_PATH "non-existent-path" @@ -49,8 +52,11 @@ static char *get_filepath(char path[]) ret = mkstemp(path); if (ret == -1) { - fprintf(stderr, "mkstemp failed\n"); + int err = errno; + fprintf(stderr, "mkstemp failed with path:'%s' [%s]\n", + path, strerror(err)); } + assert_false(ret == -1); return path; } @@ -58,9 +64,13 @@ static char *get_filepath(char path[]) void setup_dirp(void **state) { DIR *dirp = opendir(TEST_DIR); - if (dirp != NULL){ - *state = (void *)dirp; + if (dirp == NULL) { + int err = errno; + fprintf(stderr, "Could not open directory:'%s' [%s]\n", + TEST_DIR, strerror(err)); } + assert_non_null(dirp); + *state = (void *)dirp; } void teardown_dirp(void **state) @@ -111,11 +121,15 @@ void test_sss_openat_cloexec_success(void **state) int dir_fd; int flags = O_RDWR; char path[PATH_MAX] = {'\0'}; + char *basec; const char *relativepath; - relativepath = strchr(get_filepath(path), 't'); dir_fd = dirfd((DIR *)*state); + basec = strdup(get_filepath(path)); + assert_non_null(basec); + relativepath = basename(basec); fd = sss_openat_cloexec(dir_fd, relativepath, flags, &ret); + free(basec); assert_true(fd != -1); ret_flag = fcntl(fd, F_GETFD, 0); @@ -153,5 +167,6 @@ int main(void) teardown_dirp) }; + tests_set_cwd(); return run_tests(tests); } |