Commit 58908ed09b094dbcf8c976c0a726b76f0ff2cae5

Stefan Sperling 2019-03-11T16:25:39

fix path construction with empty subdir in open_ref()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/lib/reference.c b/lib/reference.c
index 18fca1a..3d68a01 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -322,10 +322,12 @@ open_ref(struct got_reference **ref, const char *path_refs, const char *subdir,
 			return got_error_from_errno();
 		absname = (char *)name;
 	} else {
-		if (asprintf(&path, "%s/%s/%s", path_refs, subdir, name) == -1)
+		if (asprintf(&path, "%s/%s%s%s", path_refs, subdir,
+		    subdir[0] ? "/" : "", name) == -1)
 			return got_error_from_errno();
 
-		if (asprintf(&absname, "refs/%s/%s", subdir, name) == -1) {
+		if (asprintf(&absname, "refs/%s%s%s",
+		    subdir, subdir[0] ? "/" : "", name) == -1) {
 			err = got_error_from_errno();
 			goto done;
 		}