summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2012-05-11 14:53:07 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-05-11 21:31:27 (GMT)
commit1528d247e53bcf33db5b004a25a7d9b8c75c90e4 (patch)
treece2a6c2da798287f3763fa70e35d77debecdc9e3 /dir.c
parentbef369219ae90097d187a8a12a82ab75f7f16638 (diff)
downloadgit-1528d247e53bcf33db5b004a25a7d9b8c75c90e4.zip
git-1528d247e53bcf33db5b004a25a7d9b8c75c90e4.tar.gz
git-1528d247e53bcf33db5b004a25a7d9b8c75c90e4.tar.bz2
dir: respect string length argument of read_directory_recursive()
A directory name is passed to read_directory_recursive() as a length-limited string, through the parameters base and baselen. Suprisingly, base must be a NUL-terminated string as well, as it is passed to opendir(), ignoring baselen. Fix this by postponing the call to opendir() until the length-limted string is added to a strbuf, which provides a NUL in the right place. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/dir.c b/dir.c
index c6a98cc..d5444fb 100644
--- a/dir.c
+++ b/dir.c
@@ -960,16 +960,17 @@ static int read_directory_recursive(struct dir_struct *dir,
int check_only,
const struct path_simplify *simplify)
{
- DIR *fdir = opendir(*base ? base : ".");
+ DIR *fdir;
int contents = 0;
struct dirent *de;
struct strbuf path = STRBUF_INIT;
- if (!fdir)
- return 0;
-
strbuf_add(&path, base, baselen);
+ fdir = opendir(path.len ? path.buf : ".");
+ if (!fdir)
+ goto out;
+
while ((de = readdir(fdir)) != NULL) {
switch (treat_path(dir, de, &path, baselen, simplify)) {
case path_recurse:
@@ -984,12 +985,11 @@ static int read_directory_recursive(struct dir_struct *dir,
}
contents++;
if (check_only)
- goto exit_early;
- else
- dir_add_name(dir, path.buf, path.len);
+ break;
+ dir_add_name(dir, path.buf, path.len);
}
-exit_early:
closedir(fdir);
+ out:
strbuf_release(&path);
return contents;