shithub: riscv

Download patch

ref: 74912993de657a9885d4c1f95ebf64b0c7d5083f
parent: f9ae02033295468dc427b742d098b65537287b06
author: Ori Bernstein <[email protected]>
date: Sat Jun 5 18:07:57 EDT 2021

git/commit: allow passing absolute paths

we would treat paths as relative, and not
step past leading '/'s, leading to an infinte
loop.

--- a/sys/src/cmd/git/save.c
+++ b/sys/src/cmd/git/save.c
@@ -345,11 +345,17 @@
 main(int argc, char **argv)
 {
 	Hash th, ch, parents[Maxparents];
-	char *msg, *name, *email, *dstr;
-	int i, r, nparents;
+	char *msg, *name, *email, *dstr, cwd[1024];
+	int i, r, ncwd, nparents;
 	vlong date;
 	Object *t;
 
+	gitinit();
+	gitinit();
+	if(access(".git", AEXIST) != 0)
+		sysfatal("could not find git repo: %r");
+	if(getwd(cwd, sizeof(cwd)) == nil)
+		sysfatal("getcwd: %r");
 	msg = nil;
 	name = nil;
 	email = nil;
@@ -356,7 +362,8 @@
 	dstr = nil;
 	date = time(nil);
 	nparents = 0;
-	gitinit();
+	ncwd = strlen(cwd);
+
 	ARGBEGIN{
 	case 'm':	msg = EARGF(usage());	break;
 	case 'n':	name = EARGF(usage());	break;
@@ -385,12 +392,14 @@
 	}
 	if(msg == nil || name == nil)
 		usage();
-	for(i = 0; i < argc; i++)
+	for(i = 0; i < argc; i++){
 		cleanname(argv[i]);
+		if(*argv[i] == '/' && strncmp(argv[i], cwd, ncwd) == 0)
+			argv[i] += ncwd;
+		while(*argv[i] == '/')
+			argv[i]++;
+	}
 
-	gitinit();
-	if(access(".git", AEXIST) != 0)
-		sysfatal("could not find git repo: %r");
 	t = findroot();
 	r = treeify(t, argv, argv + argc, 0, &th);
 	if(r == -1)