shithub: ext4srv

Download patch

ref: 37345fce96f5df24f6fce02b876b37314ada0320
parent: d81e6dbca628a7a568aa662d442f49fe00ca6955
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Sep 9 18:50:11 EDT 2021

fix renaming

--- a/ext4srv.c	Thu Sep  9 18:26:59 2021
+++ b/ext4srv.c	Thu Sep  9 18:50:11 2021
@@ -604,7 +604,7 @@
 static void
 rwstat(Req *r)
 {
-	int res, isdir, wrperm, isowner;
+	int res, isdir, wrperm, isowner, n;
 	char *old, *new, *err, *s;
 	struct ext4_inode inode;
 	u32int uid, gid;
@@ -642,12 +642,18 @@
 
 	/* permission to rename */
 	if(r->d.name != nil && r->d.name[0] != 0){
-		if((s = strrchr(old, '/')) != nil)
-			*s = 0;
-		if((new = smprint("%M/%s%s%s", a->p, s ? old : "", s ? "/" : "", r->d.name)) == nil){
+		if((s = strrchr(old, '/')) == nil){
+			err = "botched name";
+			goto error;
+		}
+		n = s - old;
+		if((new = malloc(n + 1 + strlen(r->d.name) + 1)) == nil){
 			err = "memory";
 			goto error;
 		}
+		memmove(new, old, n);
+		new[n++] = '/';
+		strcpy(new+n, r->d.name);
 
 		/* check parent write permission */
 		o = *a;