From: Sage Weil Date: Fri, 28 Apr 2017 03:02:25 +0000 (-0400) Subject: librados: fix rados_pool_list when buf is null X-Git-Tag: v12.0.3~172^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=97c5f7f6588860a2e2b6c5652e79f9354c3855b3;p=ceph.git librados: fix rados_pool_list when buf is null This was the original intent, but buf==NULL wasn't documented and only half-way implemented. Signed-off-by: Sage Weil --- diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index fde863ad70e7..401d7d4453f0 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -649,6 +649,8 @@ CEPH_RADOS_API int rados_wait_for_latest_osdmap(rados_t cluster); * If len is too short to fit all the pool name entries we need, we will fill * as much as we can. * + * Buf may be null to determine the buffer size needed to list all pools. + * * @param cluster cluster handle * @param buf output buffer * @param len output buffer length diff --git a/src/librados/librados.cc b/src/librados/librados.cc index 8883fd9c07db..271ec3859e0a 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -3068,10 +3068,12 @@ extern "C" int rados_pool_list(rados_t cluster, char *buf, size_t len) break; const char* pool = i->second.c_str(); tracepoint(librados, rados_pool_list_pool, pool); - strncat(b, pool, rl); + if (b) { + strncat(b, pool, rl); + b += rl; + } needed += rl; len -= rl; - b += rl; } for (; i != p_end; ++i) { int rl = i->second.length() + 1; diff --git a/src/test/librados/pool.cc b/src/test/librados/pool.cc index 2c01ee91b03e..5764fa875880 100644 --- a/src/test/librados/pool.cc +++ b/src/test/librados/pool.cc @@ -15,6 +15,9 @@ TEST(LibRadosPools, PoolList) { ASSERT_EQ("", create_one_pool(pool_name, &cluster)); ASSERT_LT(rados_pool_list(cluster, buf, POOL_LIST_BUF_SZ), POOL_LIST_BUF_SZ); + // we can pass a null buffer too. + ASSERT_LT(rados_pool_list(cluster, NULL, POOL_LIST_BUF_SZ), POOL_LIST_BUF_SZ); + bool found_pool = false; while (buf[0] != '\0') { if ((found_pool == false) && (strcmp(buf, pool_name.c_str()) == 0)) {