]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: check invalid input in do_xattr_cmp_u64()
authorKefu Chai <kchai@redhat.com>
Tue, 29 Jun 2021 06:43:57 +0000 (14:43 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 29 Jun 2021 06:54:08 +0000 (14:54 +0800)
we should return -EINVAL if the string does not represent a decimal
integer.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/osd/pg_backend.cc

index 4ad9ac2fd921eacbdfeb300b566031bdb90f56ee..4fd9cf994a914d27754c614f6e63e8d1f9a6be0d 100644 (file)
@@ -862,7 +862,11 @@ static int do_xattr_cmp_u64(int op, uint64_t lhs, bufferlist& rhs_xattr)
   uint64_t rhs;
 
   if (rhs_xattr.length() > 0) {
-    std::from_chars(rhs_xattr.c_str(), rhs_xattr.c_str() + rhs_xattr.length(), rhs);
+    const char* first = rhs_xattr.c_str();
+    if (auto [p, ec] = std::from_chars(first, first + rhs_xattr.length(), rhs);
+       ec != std::errc()) {
+      return -EINVAL;
+    }
   } else {
     rhs = 0;
   }