-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Description
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)
Operating system(s) tested
Linux Mint
Metadata
Metadata
Assignees
Labels
No labels