changeset 5422:a3ba7ef98c94

osutil: eliminate alloca call - make full_path a PATH_MAX + epsilon local buffer - use strncpy and strncat
author Matt Mackall <mpm@selenic.com>
date Mon, 08 Oct 2007 18:47:12 -0500
parents 9b5d626be8ba
children e5f238a8b0d2
files mercurial/osutil.c
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/osutil.c	Mon Oct 08 18:47:06 2007 -0500
+++ b/mercurial/osutil.c	Mon Oct 08 18:47:12 2007 -0500
@@ -118,7 +118,7 @@
 	PyObject *list = NULL;
 	PyObject *ctor_args = NULL;
 	int all_kinds = 1;
-	char *full_path;
+	char full_path[PATH_MAX + 10];
 	int path_len;
 	int do_stat;
 	char *path;
@@ -143,8 +143,7 @@
 	if (!list)
 		goto bail;
 
-	full_path = alloca(path_len + PATH_MAX + 2);
-	memcpy(full_path, path, path_len);
+	strncpy(full_path, path, PATH_MAX);
 	full_path[path_len] = '/';
 
 	for (ent = readdir(dir); ent; ent = readdir(dir)) {
@@ -229,7 +228,9 @@
 			if (kind != -1 && !do_stat)
 				continue;
 
-			strcpy(full_path + path_len + 1, name);
+			strncat(full_path + path_len + 1, name,
+				PATH_MAX - path_len);
+			full_path[PATH_MAX] = 0;
 
 			if (do_stat) {
 				struct listdir_stat *st;