svn commit: r231786 - stable/9/tools/regression/doat

Jilles Tjoelker jilles at FreeBSD.org
Wed Feb 15 22:07:10 UTC 2012


Author: jilles
Date: Wed Feb 15 22:07:09 2012
New Revision: 231786
URL: http://svn.freebsd.org/changeset/base/231786

Log:
  MFC r226523: Fix some memory errors in *at() regression tests.

Modified:
  stable/9/tools/regression/doat/doat.c
Directory Properties:
  stable/9/tools/regression/doat/   (props changed)

Modified: stable/9/tools/regression/doat/doat.c
==============================================================================
--- stable/9/tools/regression/doat/doat.c	Wed Feb 15 21:55:48 2012	(r231785)
+++ stable/9/tools/regression/doat/doat.c	Wed Feb 15 22:07:09 2012	(r231786)
@@ -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);


More information about the svn-src-stable-9 mailing list