From 7bfaa63839955b2f743f84f2d873fc13298f5777 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 15 Sep 2011 17:58:52 -0400 Subject: [PATCH] libselinux: src: matchpathcon: make sure resolved path starts with / Resolving paths from relative to absolute didn't always start with a /. Make sure they start with a /. Signed-off-by: Eric Paris --- libselinux/src/matchpathcon.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libselinux/src/matchpathcon.c b/libselinux/src/matchpathcon.c index c740c966..5914afa7 100644 --- a/libselinux/src/matchpathcon.c +++ b/libselinux/src/matchpathcon.c @@ -381,14 +381,17 @@ static int symlink_realpath(const char *name, char *resolved_path) } len = strlen(p); - if (len + strlen(last_component) + 1 > PATH_MAX) { + if (len + strlen(last_component) + 2 > PATH_MAX) { myprintf("symlink_realpath(%s) failed: Filename too long \n", name); + errno=ENAMETOOLONG; rc = -1; goto out; } resolved_path += len; + strcpy(resolved_path, "/"); + resolved_path += 1; strcpy(resolved_path, last_component); out: free(tmp_path);