]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
dokan: handle std::stoul exceptions 51281/head
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Fri, 28 Apr 2023 07:44:18 +0000 (07:44 +0000)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Fri, 28 Apr 2023 09:27:06 +0000 (09:27 +0000)
We're using std::stoul to parse cli args, however we aren't
catching the exceptions.

This change will handle the exceptions and log the according
error message. For consistency, we'll use the std conversion
functions throughout ceph-dokan.

Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
src/dokan/options.cc

index 4c968e13af5d6c0fe45d5fa7275ba6f46a5f4a11..1ed90ef9d34dfaa763c28217b6bdc55f80a8e603 100644 (file)
@@ -122,10 +122,21 @@ int parse_args(
       cfg->win_vol_name = to_wstring(win_vol_name);
     } else if (ceph_argparse_witharg(args, i, &win_vol_serial,
                                      "--win-vol-serial", (char *)NULL)) {
-      cfg->win_vol_serial = std::stoul(win_vol_serial);
+      try {
+        cfg->win_vol_serial = std::stoul(win_vol_serial);
+      } catch (std::logic_error&) {
+        *err_msg << "ceph-dokan: invalid volume serial number: " << win_vol_serial;
+        return -EINVAL;
+      }
     } else if (ceph_argparse_witharg(args, i, &max_path_len,
                                      "--max-path-len", (char*)NULL)) {
-      unsigned long max_path_length = std::stoul(max_path_len);
+      unsigned long max_path_length = 0;
+      try {
+        max_path_length = std::stoul(max_path_len);
+      } catch (std::logic_error&) {
+        *err_msg << "ceph-dokan: invalid maximum path length: " << max_path_len;
+        return -EINVAL;
+      }
 
       if (max_path_length > 32767) {
         *err_msg << "ceph-dokan: maximum path length should not "
@@ -141,18 +152,31 @@ int parse_args(
 
       cfg->max_path_len = max_path_length;
     } else if (ceph_argparse_witharg(args, i, &file_mode, "--file-mode", (char *)NULL)) {
-      mode_t mode = strtol(file_mode.c_str(), NULL, 8);
+      mode_t mode;
+      try {
+        mode = std::stol(file_mode, nullptr, 8);
+      } catch (std::logic_error&) {
+        *err_msg << "ceph-dokan: invalid file access mode: " << file_mode;
+        return -EINVAL;
+      }
+
       if (!std::regex_match(file_mode, std::regex("^[0-7]{3}$"))
           || mode < 01 || mode > 0777) {
-        *err_msg << "ceph-dokan: invalid file access mode";
+        *err_msg << "ceph-dokan: invalid file access mode: " << file_mode;
         return -EINVAL;
       }
       cfg->file_mode = mode;
     } else if (ceph_argparse_witharg(args, i, &dir_mode, "--dir-mode", (char *)NULL)) {
-      mode_t mode = strtol(dir_mode.c_str(), NULL, 8);
+      mode_t mode;
+      try {
+        mode = std::stol(dir_mode, nullptr, 8);
+      } catch (std::logic_error&) {
+        *err_msg << "ceph-dokan: invalid directory access mode: " << dir_mode;
+        return -EINVAL;
+      }
       if (!std::regex_match(dir_mode, std::regex("^[0-7]{3}$"))
           || mode < 01 || mode > 0777) {
-        *err_msg << "ceph-dokan: invalid directory access mode";
+        *err_msg << "ceph-dokan: invalid directory access mode: " << dir_mode;
         return -EINVAL;
       }
       cfg->dir_mode = mode;