diff options
author | Ilya Dryomov <idryomov@gmail.com> | 2021-08-28 11:05:28 +0200 |
---|---|---|
committer | Ilya Dryomov <idryomov@gmail.com> | 2021-08-28 11:05:28 +0200 |
commit | 8841029b0a4705825ba394541240b3cb4eb2cf5c (patch) | |
tree | 72bae8175cd2f3d3fdf47b9fd2d760e94d4d9b11 /src/krbd.cc | |
parent | Merge pull request #42926 from zdover23/wip-doc-2021-08-26-nomad-cleanup-cher... (diff) | |
download | ceph-8841029b0a4705825ba394541240b3cb4eb2cf5c.tar.xz ceph-8841029b0a4705825ba394541240b3cb4eb2cf5c.zip |
krbd: escape udev_enumerate_add_match_sysattr values
libudev uses fnmatch(3) for matching attributes, meaning that shell
glob pattern matching is employed instead of literal string matching.
Escape glob metacharacters to suppress pattern matching.
Fixes: https://tracker.ceph.com/issues/52425
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Diffstat (limited to 'src/krbd.cc')
-rw-r--r-- | src/krbd.cc | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/krbd.cc b/src/krbd.cc index bb5c54a0e18..5ccb9764656 100644 --- a/src/krbd.cc +++ b/src/krbd.cc @@ -16,6 +16,7 @@ #include <memory> #include <optional> #include <poll.h> +#include <regex> #include <sstream> #include <stdio.h> #include <stdlib.h> @@ -614,6 +615,13 @@ retry: return 0; } +// wrap any of * ? [ between square brackets +static std::string escape_glob(const std::string& s) +{ + std::regex glob_meta("([*?[])"); + return std::regex_replace(s, glob_meta, "[$1]"); +} + static int __enumerate_devices(struct udev *udev, const krbd_spec& spec, bool match_nspace, udev_enumerate_uptr *penm) { @@ -630,13 +638,13 @@ retry: return r; r = udev_enumerate_add_match_sysattr(enm.get(), "pool", - spec.pool_name.c_str()); + escape_glob(spec.pool_name).c_str()); if (r < 0) return r; if (match_nspace) { r = udev_enumerate_add_match_sysattr(enm.get(), "pool_ns", - spec.nspace_name.c_str()); + escape_glob(spec.nspace_name).c_str()); } else { /* * Match _only_ devices that don't have pool_ns attribute. @@ -648,12 +656,12 @@ retry: return r; r = udev_enumerate_add_match_sysattr(enm.get(), "name", - spec.image_name.c_str()); + escape_glob(spec.image_name).c_str()); if (r < 0) return r; r = udev_enumerate_add_match_sysattr(enm.get(), "current_snap", - spec.snap_name.c_str()); + escape_glob(spec.snap_name).c_str()); if (r < 0) return r; |