From 319787de4fbafd11d1223e4df66a2b524fa7a86c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Thu, 17 Oct 2013 19:48:01 +0200 Subject: [PATCH] Fix readLink() and namepsace local disk prefix, using class buffer instead of local buffer in the stack. --- src/VfsNs.cpp | 17 +++++++++++------ src/VfsNs.h | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/VfsNs.cpp b/src/VfsNs.cpp index ab06268..125b127 100644 --- a/src/VfsNs.cpp +++ b/src/VfsNs.cpp @@ -318,14 +318,19 @@ void VfsCatalog::symlink(const std::string& oldPath, const std::string& newPath) std::string VfsCatalog::readLink(const std::string& path) throw (DmException) { - char buf[PATH_MAX]; ExtendedStat meta = this->extendedStat(path, false); + char *buf; if (checkPermissions(this->secCtx_, meta.acl, meta.stat, S_IREAD) != 0) vfsThrow(EACCES, "not enough permissions for '%s' on '%s'", clientName.c_str(), path.c_str()); - memset(buf, 0, sizeof(buf)); - wrapCall(readlink(getLocalPath(path).c_str(), buf, sizeof(buf) - 1)); + memset(this->buffer, 0, sizeof this->buffer); + wrapCall(readlink(getLocalPath(path).c_str(), this->buffer, sizeof(this->buffer) - 1)); + + // strip namespace local disk prefix, if target path is absolute and equals to the prefix + if (strncmp(this->buffer, this->prefix_.c_str(), this->prefix_.size()) == 0) buf = this->buffer + this->prefix_.size(); + else buf = this->buffer; + return buf; } @@ -862,12 +867,12 @@ Extensible VfsCatalog::vfsGetXattrs(const std::string& path, const std::string& attrlist_t *list; attrlist_ent_t *entry; - list = (attrlist_t *)this->xattrBuffer; + list = (attrlist_t *)this->buffer; memset(&attr_cursor, 0, sizeof attr_cursor); do { - wrapCall(attr_list(lpath.c_str(), this->xattrBuffer, sizeof this->xattrBuffer, follow ? 0 : ATTR_DONTFOLLOW, &attr_cursor), "could not get list of extended attributes on '%s'", path.c_str()); + wrapCall(attr_list(lpath.c_str(), this->buffer, sizeof this->buffer, follow ? 0 : ATTR_DONTFOLLOW, &attr_cursor), "could not get list of extended attributes on '%s'", path.c_str()); for (int i = 0; i < list->al_count; i++) { - entry = ATTR_ENTRY(this->xattrBuffer, i); + entry = ATTR_ENTRY(this->buffer, i); // "selinux" is returned in the list, but failing to get the value if (strcmp(entry->a_name, "selinux") == 0) { //syslog(LOG_DEBUG, "%s: skipping attribute '%s'", __func__, entry->a_name); diff --git a/src/VfsNs.h b/src/VfsNs.h index 13d0c48..626103e 100644 --- a/src/VfsNs.h +++ b/src/VfsNs.h @@ -119,7 +119,7 @@ namespace dmlite { bool allowCurrent, allowWriteCurrent; std::string clientName; - char xattrBuffer[1024], xattrValue[1024]; + char buffer[PATH_MAX > 1024 ? PATH_MAX : 1024], xattrValue[1024]; }; }; -- 1.8.2.3