]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: fix parse_env nullptr deref 28159/head
authorPatrick Donnelly <pdonnell@redhat.com>
Thu, 16 May 2019 18:20:50 +0000 (11:20 -0700)
committerPatrick Donnelly <pdonnell@redhat.com>
Thu, 23 May 2019 06:28:45 +0000 (23:28 -0700)
Fixes: https://tracker.ceph.com/issues/39599
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/common/config.cc

index 48b71dad1e2c996adc58ea687091e43b80033bd1..5c4d21f83c72231baf10df5c58b0678801cd2636 100644 (file)
@@ -461,11 +461,11 @@ void md_config_t::parse_env(unsigned entity_type,
   if (!args_var) {
     args_var = "CEPH_ARGS";
   }
-  if (getenv("CEPH_KEYRING")) {
-    _set_val(values, tracker, getenv("CEPH_KEYRING"), *find_option("keyring"),
-            CONF_ENV, nullptr);
+  if (auto s = getenv("CEPH_KEYRING"); s) {
+    string err;
+    _set_val(values, tracker, s, *find_option("keyring"), CONF_ENV, &err);
   }
-  if (const char *dir = getenv("CEPH_LIB")) {
+  if (auto dir = getenv("CEPH_LIB"); dir) {
     for (auto name : { "erasure_code_dir", "plugin_dir", "osd_class_dir" }) {
     std::string err;
       const Option *o = find_option(name);
@@ -473,15 +473,15 @@ void md_config_t::parse_env(unsigned entity_type,
       _set_val(values, tracker, dir, *o, CONF_ENV, &err);
     }
   }
-  const char *pod_req = getenv("POD_MEMORY_REQUEST");
-  if (pod_req) {
+  if (auto pod_req = getenv("POD_MEMORY_REQUEST"); pod_req) {
+    string err;
     uint64_t v = atoll(pod_req);
     if (v) {
       switch (entity_type) {
       case CEPH_ENTITY_TYPE_OSD:
        _set_val(values, tracker, stringify(v),
                 *find_option("osd_memory_target"),
-                CONF_ENV, nullptr);
+                CONF_ENV, &err);
        break;
       }
     }
@@ -1291,6 +1291,7 @@ int md_config_t::_set_val(
   std::string *error_message)
 {
   Option::value_t new_value;
+  ceph_assert(error_message);
   int r = opt.parse_value(raw_val, &new_value, error_message);
   if (r < 0) {
     return r;