Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2819770ybl; Thu, 29 Aug 2019 13:24:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwNINWpSDn9Dzs0IrtfQz0nSRVbyz560JZ0iaEBOH5SB4UueK86dmPUJNJBqqE5vM8csVIS X-Received: by 2002:a65:640d:: with SMTP id a13mr9872179pgv.256.1567110296238; Thu, 29 Aug 2019 13:24:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567110296; cv=none; d=google.com; s=arc-20160816; b=aNIjdY4P+H7jjt2siXfS/xqsOweQMyOpTVQPQh04b3RIK8QGkaY72ehadk+9TzkJDe qC0551LhHVwQypOUB4XQ2dL5+9fkQfIbFyopNwigXwNGm7VonU5nk7MSkpHt87QeCKWU yGr7vjmIsMs2CmfW9M60yFTnIk+Ko/afitquG2MVgwt3ieJAuBUsHxRbDI2u6m8sqvYJ QETFYgVgCb0m8QEchtQeBswO9IC3YHO95VbisjKOLUE4kc2aE1KYUyCs4vFvWU5KSzfb eiVOpaEoaUbKv2zOevnLAbUyg+n5wlpp+IgX3qBXNDyerZ0H7LIJmC+lgIu9AC6w1ClP KVsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=39k10Tsn8/su0ec1OdOh+kygm2ciF/5k7WAs6WcV1sY=; b=pzeTWf9k1JAqBlS+i25N7xoLoUiRPZ4svFwP6s4DhhIhzMNiuY7uMRNdA3j4ePjudY kGSHWdZkD8VnVmeM9Xz9S+UtKl7Bqj1Zd2G/LbgyQxUw42wJlbtbFBxv5aSTDCWFoe+Y MtocHB9IKHFwvR3+b9LMJ+ETrvr1k5YXx4w6zSLbYL5EaRElHmRrC3xoTO8upT1ivYLP MRXHq9LhDAHL5STPZu0rBpAMe6e9BUtlhP3HCA72oWWoq0o8GYZT7+7mESnShziFVt+5 FbcJYFz++fZubz/7y09T3i6OTO50wCCUIJCNdC0cdwxtGgGJZdpAvqGdNZQq1LDxZINt njAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q199si3538600pfq.112.2019.08.29.13.24.33; Thu, 29 Aug 2019 13:24:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727234AbfH2UWz (ORCPT + 99 others); Thu, 29 Aug 2019 16:22:55 -0400 Received: from mga06.intel.com ([134.134.136.31]:7849 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbfH2UWz (ORCPT ); Thu, 29 Aug 2019 16:22:55 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Aug 2019 13:22:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,444,1559545200"; d="scan'208";a="356567086" Received: from ingas-nuc1.sea.intel.com ([10.254.179.141]) by orsmga005.jf.intel.com with ESMTP; 29 Aug 2019 13:22:54 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ] mesh: Add closedir() of config directory after opendir() Date: Thu, 29 Aug 2019 13:22:45 -0700 Message-Id: <20190829202245.11308-1-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds missing closedir() call to accompany opendir() in mesh_config_load_nodes(). Also, fixes confusing mix of variable names. --- mesh/mesh-config-json.c | 46 +++++++++++++++++++++++------------------ mesh/mesh-config.h | 4 ++-- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c index 036ec9017..cafa2fdd7 100644 --- a/mesh/mesh-config-json.c +++ b/mesh/mesh-config-json.c @@ -61,7 +61,7 @@ struct write_info { mesh_config_status_func_t cb; }; -static const char *cfg_name = "/node.json"; +static const char *cfgnode_name = "/node.json"; static const char *bak_ext = ".bak"; static const char *tmp_ext = ".tmp"; @@ -1723,18 +1723,18 @@ static struct mesh_config *create_config(const char *cfg_path, return cfg; } -struct mesh_config *mesh_config_create(const char *cfg_dir, +struct mesh_config *mesh_config_create(const char *cfgdir_name, const uint8_t uuid[16], struct mesh_config_node *db_node) { char uuid_buf[33]; char name_buf[PATH_MAX]; struct mesh_config *cfg; - size_t max_len = strlen(cfg_name) + strlen(bak_ext); + size_t max_len = strlen(cfgnode_name) + strlen(bak_ext); if (!hex2str((uint8_t *) uuid, 16, uuid_buf, sizeof(uuid_buf))) return NULL; - snprintf(name_buf, PATH_MAX, "%s/%s", cfg_dir, uuid_buf); + snprintf(name_buf, PATH_MAX, "%s/%s", cfgdir_name, uuid_buf); if (strlen(name_buf) + max_len >= PATH_MAX) return NULL; @@ -1743,8 +1743,8 @@ struct mesh_config *mesh_config_create(const char *cfg_dir, if (mkdir(name_buf, 0755) != 0) return NULL; - snprintf(name_buf, PATH_MAX, "%s/%s%s", cfg_dir, uuid_buf, - cfg_name); + snprintf(name_buf, PATH_MAX, "%s/%s%s", cfgdir_name, uuid_buf, + cfgnode_name); l_debug("New node config %s", name_buf); cfg = create_config(name_buf, uuid, db_node); @@ -2042,7 +2042,7 @@ bool mesh_config_write_seq_number(struct mesh_config *cfg, uint32_t seq, if (!cache) { if (!write_int(cfg->jnode, "sequenceNumber", seq)) - return false; + return false; return mesh_config_save(cfg, true, NULL, NULL); } @@ -2238,23 +2238,24 @@ bool mesh_config_save(struct mesh_config *cfg, bool no_wait, return true; } -bool mesh_config_load_nodes(const char *cfg_dir, mesh_config_node_func_t cb, - void *user_data) +bool mesh_config_load_nodes(const char *cfgdir_name, mesh_config_node_func_t cb, + void *user_data) { - DIR *dir; + DIR *cfgdir; struct dirent *entry; - size_t path_len = strlen(cfg_dir) + strlen(cfg_name) + strlen(bak_ext); + size_t path_len = strlen(cfgdir_name) + strlen(cfgnode_name) + + strlen(bak_ext); - create_dir(cfg_dir); - dir = opendir(cfg_dir); - if (!dir) { + create_dir(cfgdir_name); + cfgdir = opendir(cfgdir_name); + if (!cfgdir) { l_error("Failed to open mesh node storage directory: %s", - cfg_dir); + cfgdir_name); return false; } - while ((entry = readdir(dir)) != NULL) { - char *dir, *fname, *bak; + while ((entry = readdir(cfgdir)) != NULL) { + char *dirname, *fname, *bak; uint8_t uuid[16]; size_t node_len; @@ -2263,14 +2264,15 @@ bool mesh_config_load_nodes(const char *cfg_dir, mesh_config_node_func_t cb, /* Check path length */ node_len = strlen(entry->d_name); + if (path_len + node_len + 1 >= PATH_MAX) continue; if (!str2hex(entry->d_name, node_len, uuid, sizeof(uuid))) continue; - dir = l_strdup_printf("%s/%s", cfg_dir, entry->d_name); - fname = l_strdup_printf("%s%s", dir, cfg_name); + dirname = l_strdup_printf("%s/%s", cfgdir_name, entry->d_name); + fname = l_strdup_printf("%s%s", dirname, cfgnode_name); if (!load_node(fname, uuid, cb, user_data)) { @@ -2281,12 +2283,16 @@ bool mesh_config_load_nodes(const char *cfg_dir, mesh_config_node_func_t cb, remove(fname); rename(bak, fname); } + l_free(bak); } + l_free(fname); - l_free(dir); + l_free(dirname); } + closedir(cfgdir); + return true; } diff --git a/mesh/mesh-config.h b/mesh/mesh-config.h index 4172e794b..cf1f8b299 100644 --- a/mesh/mesh-config.h +++ b/mesh/mesh-config.h @@ -110,13 +110,13 @@ typedef bool (*mesh_config_node_func_t)(struct mesh_config_node *node, struct mesh_config *cfg, void *user_data); -bool mesh_config_load_nodes(const char *cfg_dir, mesh_config_node_func_t cb, +bool mesh_config_load_nodes(const char *cfgdir_name, mesh_config_node_func_t cb, void *user_data); void mesh_config_release(struct mesh_config *cfg); void mesh_config_destroy(struct mesh_config *cfg); bool mesh_config_save(struct mesh_config *cfg, bool no_wait, mesh_config_status_func_t cb, void *user_data); -struct mesh_config *mesh_config_create(const char *cfg_path, +struct mesh_config *mesh_config_create(const char *cfgdir_name, const uint8_t uuid[16], struct mesh_config_node *node); -- 2.21.0