summaryrefslogtreecommitdiff
blob: f1d7f7d4c0fc56c8019f2c991e6589197085bcb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Fix bug in realpath implementation bundled with pmount which caused it to
likely fail on paths with several symlinks.

The issue was first noticed by failure in tests:
Gentoo-Bug: https://bugs.gentoo.org/741810
--- pmount-0.9.99-alpha/src/realpath.c.orig	2024-01-21 09:19:55.776224329 +0300
+++ pmount-0.9.99-alpha/src/realpath.c	2024-01-21 09:30:46.751233027 +0300
@@ -128,6 +128,7 @@
 		} else {
 #ifdef resolve_symlinks		/* Richard Gooch dislikes sl resolution */
 			int m;
+			char *old_buf;
 
 			/* Note: readlink doesn't add the null byte. */
 			link_path[n] = '\0';
@@ -141,12 +142,13 @@
 
 			/* Insert symlink contents into path. */
 			m = strlen(path);
-			if (buf)
-				free(buf);
+			old_buf = buf; /* path might point to buf at this point */
 			buf = xmalloc(m + n + 1);
 			memcpy(buf, link_path, n);
 			memcpy(buf + n, path, m + 1);
 			path = buf;
+			if (old_buf)
+				free(old_buf);
 #endif
 		}
 		*npath++ = '/';