Skip to contentSkip to conversation

btrfs-progs: Fix pointer math in __ino_to_path_fd

PATCH Mark Fasheh 1 participant 1 message Feb 14, 2013 Btrfs file system

lore
Share & tools
lore
#0 lore raw

We are casting an array of u64 values into a char ** array so when we dereference this array (as a char **) on a 32 bit system we're then re-casting that back to a 32 bit value. This causes problems when we try to print those strings.

---
 cmds-inspect.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
cmds-inspect.c +7 -4
index 25b83d2..371bd34 100644
@@ -61,12 +61,15 @@ static int __ino_to_path_fd(u64 inum, int fd, int verbose, const char *prepend)
 			fspath->elem_cnt, fspath->elem_missed);
 
 	for (i = 0; i < fspath->elem_cnt; ++i) {
-		char **str = (char **)fspath->val;
-		str[i] += (unsigned long)fspath->val;
+		u64 ptr;
+		char *str;
+		ptr = (u64)(unsigned long)fspath->val;
+		ptr += fspath->val[i];
+		str = (char *)(unsigned long)ptr;
 		if (prepend)
-			printf("%s/%s\n", prepend, str[i]);
+			printf("%s/%s\n", prepend, str);
 		else
-			printf("%s\n", str[i]);
+			printf("%s\n", str);
 	}
 
 out:
Signature · 1 line
1.7.10.4