From 8ee3860fbec0449fccf20bd41aac01e1429bccca Mon Sep 17 00:00:00 2001 From: jilles Date: Tue, 18 Oct 2011 22:51:40 +0000 Subject: Fix some memory errors in *at() regression tests. --- tools/regression/doat/doat.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'tools/regression/doat') diff --git a/tools/regression/doat/doat.c b/tools/regression/doat/doat.c index f5ac795..d71648d 100644 --- a/tools/regression/doat/doat.c +++ b/tools/regression/doat/doat.c @@ -103,8 +103,9 @@ setup(void) { int i, error; struct stat sb; + size_t len; - tests = calloc(NUM_OF_TESTS, sizeof(struct test)); + tests = calloc(NUM_OF_TESTS + 1, sizeof(struct test)); if (tests == NULL) { perror(""); exit(0); @@ -116,14 +117,16 @@ setup(void) exit(0); } - absolute_path = realloc(absolute_path, strlen(absolute_path) + 5); + len = strlen(absolute_path); + absolute_path = realloc(absolute_path, + len + 1 + strlen(relative_path) + 1); if (absolute_path == NULL) { perror("realloc"); exit(0); } - absolute_path[strlen(absolute_path)] = '/'; - strcpy(absolute_path + strlen(absolute_path), relative_path); + absolute_path[len] = '/'; + strcpy(absolute_path + len + 1, relative_path); absolute_file = malloc(strlen(absolute_path) + 1 + strlen(file)); bzero(absolute_file, strlen(absolute_path) + 1 + strlen(file)); @@ -145,7 +148,7 @@ setup(void) relative_file[strlen(relative_file)] = '/'; strcpy(relative_file + strlen(relative_path), file); - error = mkdir(relative_path, 666); + error = mkdir(relative_path, 0700); dir_exist = (errno == EEXIST); if (error && errno != EEXIST) { perror("tmp"); @@ -154,7 +157,7 @@ setup(void) error = stat("tmp/foo", &sb); file_exist = (errno != ENOENT); - i = open("tmp/foo", O_RDONLY | O_CREAT); + i = open("tmp/foo", O_RDONLY | O_CREAT, 0666); if (i == -1) { perror("foo"); exit(0); -- cgit v1.1