# HG changeset patch # User Matt Mackall # Date 1191887232 18000 # Node ID a3ba7ef98c94392e2e7daefa92c23f1ef3be3ff4 # Parent 9b5d626be8ba0fca474e98b5429a5e75867ef22a osutil: eliminate alloca call - make full_path a PATH_MAX + epsilon local buffer - use strncpy and strncat diff --git a/mercurial/osutil.c b/mercurial/osutil.c --- a/mercurial/osutil.c +++ b/mercurial/osutil.c @@ -118,7 +118,7 @@ static PyObject *listdir(PyObject *self, 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 @@ static PyObject *listdir(PyObject *self, 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 @@ static PyObject *listdir(PyObject *self, 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;