From: Patrick Donnelly Date: Tue, 15 Apr 2025 16:18:07 +0000 (-0400) Subject: mds: use strict_strtobool for parsing bools X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d8419fe9a0ffb30d2f66ef4ff4ca9ba5e3bda766;p=ceph.git mds: use strict_strtobool for parsing bools This allows false/true as a value. Signed-off-by: Patrick Donnelly (cherry picked from commit 58e5c9453400b9163179f44933f41fe3d68f4f2e) --- diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 23cf5a9f39c0..874b8c45d1d0 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -6248,11 +6248,10 @@ void Server::handle_client_setvxattr(const MDRequestRef& mdr, CInode *cur) client_t exclude_ct = mdr->get_client(); mdcache->broadcast_quota_to_client(cur, exclude_ct, true); } else if (name == "ceph.quiesce.block"sv) { - bool val; - try { - val = boost::lexical_cast(value); - } catch (boost::bad_lexical_cast const&) { - dout(10) << "bad vxattr value, unable to parse bool for " << name << dendl; + std::string errstr; + bool val = strict_strtob(value, &errstr); + if (!errstr.empty()) { + dout(10) << "bad vxattr value, unable to parse bool for " << name << ": " << errstr << dendl; respond_to_request(mdr, -EINVAL); return; } @@ -6310,7 +6309,13 @@ void Server::handle_client_setvxattr(const MDRequestRef& mdr, CInode *cur) } value = "0"; } - val = boost::lexical_cast(value); + std::string errstr; + val = strict_strtob(value, &errstr); + if (!errstr.empty()) { + dout(10) << "bad vxattr value, unable to parse bool for " << name << ": " << errstr << dendl; + respond_to_request(mdr, -EINVAL); + return; + } } catch (boost::bad_lexical_cast const&) { dout(10) << "bad vxattr value, unable to parse bool for " << name << dendl; respond_to_request(mdr, -EINVAL); @@ -6459,7 +6464,13 @@ void Server::handle_client_setvxattr(const MDRequestRef& mdr, CInode *cur) } value = "0"; } - val = boost::lexical_cast(value); + std::string errstr; + val = strict_strtob(value, &errstr); + if (!errstr.empty()) { + dout(10) << "bad vxattr value, unable to parse bool for " << name << ": " << errstr << dendl; + respond_to_request(mdr, -EINVAL); + return; + } } catch (boost::bad_lexical_cast const&) { dout(10) << "bad vxattr value, unable to parse bool for " << name << dendl; respond_to_request(mdr, -EINVAL); @@ -6527,11 +6538,10 @@ void Server::handle_client_setvxattr(const MDRequestRef& mdr, CInode *cur) return; } - bool val; - try { - val = boost::lexical_cast(value); - } catch (boost::bad_lexical_cast const&) { - dout(10) << "bad vxattr value, unable to parse bool for " << name << dendl; + std::string errstr; + bool val = strict_strtob(value, &errstr); + if (!errstr.empty()) { + dout(10) << "bad vxattr value, unable to parse bool for " << name << ": " << errstr << dendl; respond_to_request(mdr, -EINVAL); return; }