[PATCH BlueZ 2/3] mesh: Fix file open error checking and permissions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 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




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux