shithub: plan9front

Download patch

ref: 74912993de657a9885d4c1f95ebf64b0c7d5083f
parent: f9ae02033295468dc427b742d098b65537287b06
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jun 5 22: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	Sat Jun  5 19:58:24 2021
+++ b/sys/src/cmd/git/save.c	Sat Jun  5 22:07:57 2021
@@ -345,18 +345,25 @@
 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;
 	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)