Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iter_load_loose_paths generates paths with empty segments #5920

Closed
boretrk opened this issue Jun 20, 2021 · 1 comment
Closed

iter_load_loose_paths generates paths with empty segments #5920

boretrk opened this issue Jun 20, 2021 · 1 comment

Comments

@boretrk
Copy link
Contributor

boretrk commented Jun 20, 2021

iter_load_loose_paths() appends a '/' on backend->commonpath in all cases.
setup_namespace() generates a commonpath without trailing '/' only if repo->namespace is set.

Reproduction steps

Print paths from p_open/p_creat/p_stat/p_lstat or apply the following diff:

diff --git a/src/posix.c b/src/posix.c
index bf764ae6b..15430be0c 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -109,6 +109,9 @@ int p_open(const char *path, volatile int flags, ...)
 {
 	mode_t mode = 0;
 
+	if(strstr(path, "//")!=NULL)
+		fprintf(stderr, "Empty path segment: %s\n", path);
+
 	if (flags & O_CREAT) {
 		va_list arg_list;
 
@@ -122,6 +125,8 @@ int p_open(const char *path, volatile int flags, ...)
 
 int p_creat(const char *path, mode_t mode)
 {
+	if(strstr(path, "//")!=NULL)
+		fprintf(stderr, "Empty path segment: %s\n", path);
 	return open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_CLOEXEC, mode);
 }
 
diff --git a/src/unix/posix.h b/src/unix/posix.h
index 7b3325e78..295ace0d9 100644
--- a/src/unix/posix.h
+++ b/src/unix/posix.h
@@ -22,8 +22,20 @@ typedef int GIT_SOCKET;
 
 #define p_lseek(f,n,w) lseek(f, n, w)
 #define p_fstat(f,b) fstat(f, b)
-#define p_lstat(p,b) lstat(p,b)
-#define p_stat(p,b) stat(p, b)
+
+GIT_INLINE(int) p_lstat(const char *path, struct stat *buf)
+{
+	if(strstr(path, "//")!=NULL)
+		fprintf(stderr, "Empty path segment: %s\n", path);
+	return lstat(path, buf);
+}
+
+GIT_INLINE(int) p_stat(const char *path, struct stat *buf)
+{
+	if(strstr(path, "//")!=NULL)
+		fprintf(stderr, "Empty path segment: %s\n", path);
+	return stat(path, buf);
+}
 
 #if defined(GIT_USE_STAT_MTIMESPEC)
 # define st_atime_nsec st_atimespec.tv_nsec
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 0a8f2bee0..a1c8299da 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -381,11 +381,15 @@ static int do_lstat(const char *path, struct stat *buf, bool posixly_correct)
 
 int p_lstat(const char *filename, struct stat *buf)
 {
+	if(strstr(path, "//")!=NULL)
+		fprintf(stderr, "Empty path segment: %s\n", path);
 	return do_lstat(filename, buf, false);
 }
 
 int p_lstat_posixly(const char *filename, struct stat *buf)
 {
+	if(strstr(path, "//")!=NULL)
+		fprintf(stderr, "Empty path segment: %s\n", path);
 	return do_lstat(filename, buf, true);
 }

Run git_reference_foreach() in a repository without namespaces (Or build/examples/lg2 for-each-ref)

Expected behavior

No paths with empty segments should be printed

Actual behavior

Paths with empty segments are printed

Version of libgit2 (release number or SHA1)

0d0150d

Operating system(s) tested

Linux Mint

@boretrk
Copy link
Contributor Author

boretrk commented Aug 26, 2021

Solved by #5950

@boretrk boretrk closed this as completed Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant