diff options
author | Mohamed Awnallah <mohamedmohey2352@gmail.com> | 2023-03-01 17:59:33 +0100 |
---|---|---|
committer | Mohamed Awnallah <mohamedmohey2352@gmail.com> | 2023-05-19 10:53:20 +0200 |
commit | b8cb558cc35d9fb5c47372a79c6249207a964245 (patch) | |
tree | 190ebee7895ceb8edbb99d6c33b2dfbb6313c1c3 /src/rgw/rgw_env.cc | |
parent | Merge pull request #49299 from weirdwiz/status-update (diff) | |
download | ceph-b8cb558cc35d9fb5c47372a79c6249207a964245.tar.xz ceph-b8cb558cc35d9fb5c47372a79c6249207a964245.zip |
rgw: Fix potential null pointer dereferences where `RGWEnv::get()` is called
Here are the changes I've made:
- Added `RGWEnv::get_optional` with the similar implementation to the `RGWHTTPArgs::get_optional`
- Replaced `RGWEnv::get` in the RGW code where null pointer derefence happens with `RGWEnv::get_optional` as long as it accepts `std::string`
- Otherwise if calling function of `RGWEnv::get` accepts `char*` I leave it as it is
- Added null pointer checks to avoid the null pointer dereference
This commit addresses the following Coverity CIDs:
- "1510310"
- "1510928"
- "1511097"
- "1511555"
- "1511760"
- "1511951"
- "1512003"
- "1512138"
- "1512398"
Fixes: https://tracker.ceph.com/issues/57347
Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
Diffstat (limited to 'src/rgw/rgw_env.cc')
-rw-r--r-- | src/rgw/rgw_env.cc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/rgw/rgw_env.cc b/src/rgw/rgw_env.cc index bb45ee8d36a..d528f0e6d47 100644 --- a/src/rgw/rgw_env.cc +++ b/src/rgw/rgw_env.cc @@ -52,11 +52,26 @@ const char *rgw_conf_get(const map<string, string, ltstr_nocase>& conf_map, cons return iter->second.c_str(); } +boost::optional<const std::string&> rgw_conf_get_optional(const map<string, string, ltstr_nocase>& conf_map, const std::string& name) +{ + auto iter = conf_map.find(name); + if (iter == conf_map.end()) + return boost::none; + + return boost::optional<const std::string&>(iter->second); +} + const char *RGWEnv::get(const char *name, const char *def_val) const { return rgw_conf_get(env_map, name, def_val); } +boost::optional<const std::string&> +RGWEnv::get_optional(const std::string& name) const +{ + return rgw_conf_get_optional(env_map, name); +} + int rgw_conf_get_int(const map<string, string, ltstr_nocase>& conf_map, const char *name, int def_val) { auto iter = conf_map.find(name); |