From 76985007fd9d524bd7800a21bc4ab4fe63cb208c Mon Sep 17 00:00:00 2001 From: Noah Watkins Date: Thu, 21 Mar 2013 15:30:41 -0700 Subject: [PATCH] libcephfs: fix ceph_get_osd_crush_location (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 --- src/libcephfs.cc | 4 ++-- src/test/libcephfs/test.cc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 74cd8b70417..d43b3dbbe64 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -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 > 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()); diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index 74d4db36275..267f0f5aad4 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -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); -- 2.47.3