From: František Dvořák Date: Wed, 16 Oct 2013 11:03:24 +0000 (+0200) Subject: Fix readLink() and namepsace local disk prefix, using class buffer instead of local... X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=8ed6cdf7d3dca56623325def8c7ed5625aef5aae;p=dmlite-plugins-vfs-old.git Fix readLink() and namepsace local disk prefix, using class buffer instead of local buffer in the stack. --- 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]; }; };