Skip to contentSkip to conversation

libselinux: fix pointer handling in realpath_not_final

PATCH Applied Vit Mojzis 2 participants 2 messages Oct 27, 2016 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

PATCH 1/1 libselinux: fix pointer handling in realpath_not_final

From: vmojzis <[email protected]>

Loop designed for stripping leading "//" was changing the only pointer referencing block of memory allocated by "strdup", resulting in "free()" failure. The loop had no effect because "realpath" is used later on.

---
 libselinux/src/matchpathcon.c | 6 ------
 1 file changed, 6 deletions(-)
libselinux/src/matchpathcon.c +0 -6
index 724eb65..58b4144 100644
@@ -389,12 +389,6 @@ int realpath_not_final(const char *name, char *resolved_path)
 		goto out;
 	}
 
-	/* strip leading // */
-	while (tmp_path[len] && tmp_path[len] == '/' &&
-	       tmp_path[len+1] && tmp_path[len+1] == '/') {
-		tmp_path++;
-		len++;
-	}
 	last_component = strrchr(tmp_path, '/');
 
 	if (last_component == tmp_path) {
Signature · 1 line
2.7.4
#1 lore raw
Quoted 10 lines · Vit Mojzis

From: vmojzis <[email protected]>

Loop designed for stripping leading "//" was changing the only pointer referencing block of memory allocated by "strdup", resulting in "free()" failure. The loop had no effect because "realpath" is used later on.

Thanks, applied.

This reminds me that we want to get rid of all matchpathcon users, moving them over to selabel_lookup and selinux_restorecon. Upstream setfiles no longer calls matchpathcon or realpath_not_final. Looks like the python wrappers for libselinux define their own restorecon() method that uses matchpathcon() and implements their own tree walk - that should be converted to use selinux_restorecon().

Quoted 22 lines
---
 libselinux/src/matchpathcon.c | 6 ------
 1 file changed, 6 deletions(-)
libselinux/src/matchpathcon.c +0 -6
index 724eb65..58b4144 100644
@@ -389,12 +389,6 @@ int realpath_not_final(const char *name, char *resolved_path)
 		goto out;
 	}
 
-	/* strip leading // */
-	while (tmp_path[len] && tmp_path[len] == '/' &&
-	       tmp_path[len+1] && tmp_path[len+1] == '/') {
-		tmp_path++;
-		len++;
-	}
 	last_component = strrchr(tmp_path, '/');
 
 	if (last_component == tmp_path) {