From 7ba207e781c7af3945d3a718651b87425685131e Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 17 Jun 2013 13:02:15 +0200 Subject: libmount: be robust for empty target/source strings * lib/canonicalize.c: don't interpret empty strings as relative paths * libmount: more robust libmnt_table find function and debug messages References: https://bugzilla.novell.com/show_bug.cgi?id=825150 Signed-off-by: Karel Zak Signed-off-by: Karel Zak --- lib/canonicalize.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/canonicalize.c') diff --git a/lib/canonicalize.c b/lib/canonicalize.c index 727806e1e..548e29b75 100644 --- a/lib/canonicalize.c +++ b/lib/canonicalize.c @@ -151,6 +151,9 @@ canonicalize_dm_name(const char *ptname) size_t sz; char path[256], name[256], *res = NULL; + if (!ptname || !*ptname) + return NULL; + snprintf(path, sizeof(path), "/sys/block/%s/dm/name", ptname); if (!(f = fopen(path, "r" UL_CLOEXECSTR))) return NULL; @@ -173,7 +176,7 @@ canonicalize_path(const char *path) char canonical[PATH_MAX+2]; char *p; - if (path == NULL) + if (!path || !*path) return NULL; if (!myrealpath(path, canonical, PATH_MAX+1)) @@ -199,7 +202,7 @@ canonicalize_path_restricted(const char *path) uid_t euid; gid_t egid; - if (path == NULL) + if (!path || !*path) return NULL; euid = geteuid(); -- cgit v1.2.3-55-g7522