From: Brian Gix <brian.gix@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: inga.stotland@intel.com, brian.gix@intel.com,
michal.lowas-rzechonek@silvair.com
Subject: [PATCH BlueZ 2/3] mesh: Fix file open error checking and permissions
Date: Tue, 14 May 2019 13:15:24 -0700 [thread overview]
Message-ID: <20190514201525.16067-3-brian.gix@intel.com> (raw)
In-Reply-To: <20190514201525.16067-1-brian.gix@intel.com>
---
mesh/keyring.c | 8 +++++---
mesh/storage.c | 2 +-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/mesh/keyring.c b/mesh/keyring.c
index 59aa1eaf4..4b1460aa8 100644
--- a/mesh/keyring.c
+++ b/mesh/keyring.c
@@ -67,7 +67,7 @@ bool keyring_put_net_key(struct mesh_node *node, uint16_t net_idx,
net_idx);
l_debug("Put Net Key %s", key_file);
- fd = open(key_file, O_WRONLY | O_CREAT | O_TRUNC);
+ fd = open(key_file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd >= 0) {
if (write(fd, key, sizeof(*key)) == sizeof(*key))
result = true;
@@ -112,7 +112,8 @@ bool keyring_put_app_key(struct mesh_node *node, uint16_t app_idx,
}
lseek(fd, 0, SEEK_SET);
} else
- fd = open(key_file, O_WRONLY | O_CREAT | O_TRUNC);
+ fd = open(key_file, O_WRONLY | O_CREAT | O_TRUNC,
+ S_IRUSR | S_IWUSR);
if (fd >= 0) {
if (write(fd, key, sizeof(*key)) == sizeof(*key))
@@ -148,7 +149,8 @@ bool keyring_put_remote_dev_key(struct mesh_node *node, uint16_t unicast,
dev_key_dir, unicast + i);
l_debug("Put Dev Key %s", key_file);
- fd = open(key_file, O_WRONLY | O_CREAT | O_TRUNC);
+ fd = open(key_file, O_WRONLY | O_CREAT | O_TRUNC,
+ S_IRUSR | S_IWUSR);
if (fd >= 0) {
if (write(fd, dev_key, 16) != 16)
result = false;
diff --git a/mesh/storage.c b/mesh/storage.c
index f4e23bf49..8893b93cb 100644
--- a/mesh/storage.c
+++ b/mesh/storage.c
@@ -197,7 +197,7 @@ static bool parse_config(char *in_file, char *out_dir, const uint8_t uuid[16])
l_info("Loading configuration from %s", in_file);
fd = open(in_file, O_RDONLY);
- if (!fd)
+ if (fd < 0)
return false;
if (fstat(fd, &st) == -1) {
--
2.14.5
next prev parent reply other threads:[~2019-05-14 20:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-14 20:15 [PATCH BlueZ 0/3] mesh: add Keyring to CreateNetwork Brian Gix
2019-05-14 20:15 ` [PATCH BlueZ 1/3] mesh: Add "create" command to test app Brian Gix
2019-05-14 20:15 ` Brian Gix [this message]
2019-05-14 20:15 ` [PATCH BlueZ 3/3] mesh: Save generated Net and Dev keys in KeyRing Brian Gix
2019-05-15 16:46 ` [PATCH BlueZ 0/3] mesh: add Keyring to CreateNetwork Gix, Brian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190514201525.16067-3-brian.gix@intel.com \
--to=brian.gix@intel.com \
--cc=inga.stotland@intel.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=michal.lowas-rzechonek@silvair.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.