]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: use strict_strtobool for parsing bools
authorPatrick Donnelly <pdonnell@ibm.com>
Tue, 15 Apr 2025 16:18:07 +0000 (12:18 -0400)
committerPatrick Donnelly <pdonnell@ibm.com>
Wed, 16 Apr 2025 14:01:42 +0000 (10:01 -0400)
This allows false/true as a value.

Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
src/mds/Server.cc

index 4c68e0b06c923b6e17e94266dfd5442282c70b77..e78b43a82ffe30e10f3277d3b17a77af844add2f 100644 (file)
@@ -6346,11 +6346,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<bool>(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;
     }
@@ -6408,7 +6407,13 @@ void Server::handle_client_setvxattr(const MDRequestRef& mdr, CInode *cur)
        }
         value = "0";
       }
-      val = boost::lexical_cast<bool>(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);
@@ -6557,7 +6562,13 @@ void Server::handle_client_setvxattr(const MDRequestRef& mdr, CInode *cur)
        }
         value = "0";
       }
-      val = boost::lexical_cast<bool>(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);
@@ -6625,11 +6636,10 @@ void Server::handle_client_setvxattr(const MDRequestRef& mdr, CInode *cur)
       return;
     }
 
-    bool val;
-    try {
-      val = boost::lexical_cast<bool>(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;
     }