Skip to content

Commit

Permalink
librados: invalid free() in rados_getxattrs_next()
Browse files Browse the repository at this point in the history
Invalid free() can cause corruption when getting an object
attribute with empty value.

Check the validity of the pointer before free(). Also move
the free() call at the start of rados_getxattrs_next() to
avoid memory leak.

Fixes: http://tracker.ceph.com/issues/22042
Signed-off-by: Gu Zhongyan <guzhongyan@360.cn>
  • Loading branch information
guzhongyan committed Feb 2, 2018
1 parent d9637b7 commit 03f5879
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/librados/librados.cc
Expand Up @@ -4281,14 +4281,17 @@ extern "C" int rados_getxattrs_next(rados_xattrs_iter_t iter,
{
tracepoint(librados, rados_getxattrs_next_enter, iter);
librados::RadosXattrsIter *it = static_cast<librados::RadosXattrsIter*>(iter);
if(it->val) {
free(it->val);
it->val = NULL;
}
if (it->i == it->attrset.end()) {
*name = NULL;
*val = NULL;
*len = 0;
tracepoint(librados, rados_getxattrs_next_exit, 0, NULL, NULL, 0);
return 0;
}
free(it->val);
const std::string &s(it->i->first);
*name = s.c_str();
bufferlist &bl(it->i->second);
Expand Down

0 comments on commit 03f5879

Please sign in to comment.