]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
libcephfs: fix ceph_get_osd_crush_location 132/head
authorNoah Watkins <noahwatkins@gmail.com>
Thu, 21 Mar 2013 22:30:41 +0000 (15:30 -0700)
committerNoah Watkins <noahwatkins@gmail.com>
Thu, 21 Mar 2013 22:32:39 +0000 (15:32 -0700)
(a) Allow NULL buffer when length is zero to get the target buffer
length. (b) fix edge case where buffer length is the exact size
required.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
src/libcephfs.cc
src/test/libcephfs/test.cc

index 74cd8b70417b519c0e613a7292b801db691ba7ec..d43b3dbbe64ab4a7a4c6254b88b8fb139edb9f85 100644 (file)
@@ -822,7 +822,7 @@ extern "C" int ceph_get_osd_crush_location(struct ceph_mount_info *cmount,
   if (!cmount->is_mounted())
     return -ENOTCONN;
 
-  if (!path)
+  if (!path && len)
     return -EINVAL;
 
   vector<pair<string, string> > loc;
@@ -837,7 +837,7 @@ extern "C" int ceph_get_osd_crush_location(struct ceph_mount_info *cmount,
     string& type = it->first;
     string& name = it->second;
     needed += type.size() + name.size() + 2;
-    if (needed < len) {
+    if (needed <= len) {
       strcpy(path + cur, type.c_str());
       cur += type.size() + 1;
       strcpy(path + cur, name.c_str());
index 74d4db36275443b982d0255672a5afe9d78298ac..267f0f5aad4445eada558f13953257ee1c5190ea 100644 (file)
@@ -990,7 +990,7 @@ TEST(LibCephFS, GetOsdCrushLocation) {
   ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0);
   ASSERT_EQ(ceph_mount(cmount, NULL), 0);
 
-  ASSERT_EQ(ceph_get_osd_crush_location(cmount, 0, NULL, 0), -EINVAL);
+  ASSERT_EQ(ceph_get_osd_crush_location(cmount, 0, NULL, 1), -EINVAL);
 
   char path[256];
   ASSERT_EQ(ceph_get_osd_crush_location(cmount, 9999999, path, 0), -ENOENT);