Commit 3dcf3e7438f8c2aa3c8cb3855f0f52718d0c6c3b

Stefan Sperling 2020-01-28T11:00:34

rewind directory file pointer before re-opening the directory

diff --git a/lib/fileindex.c b/lib/fileindex.c
index f277b84..0b81c78 100644
--- a/lib/fileindex.c
+++ b/lib/fileindex.c
@@ -1062,9 +1062,17 @@ got_fileindex_diff_dir(struct got_fileindex *fileindex, int fd,
 	fd2 = dup(fd);
 	if (fd2 == -1)
 		return got_error_from_errno2("dup", path);
+	if (lseek(fd2, 0, SEEK_SET) == -1) {
+		err = got_error_from_errno2("lseek", path);
+		close(fd2);
+		return err;
+	}
 	dir = fdopendir(fd2);
-	if (dir == NULL)
-		return got_error_from_errno2("fdopendir", path);
+	if (dir == NULL) {
+		err = got_error_from_errno2("fdopendir", path);
+		close(fd2);
+		return err;
+	}
 	err = read_dirlist(&dirlist, dir, path);
 	if (err) {
 		closedir(dir);