aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/openzfs/lib/libshare/os/linux/smb.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/contrib/openzfs/lib/libshare/os/linux/smb.c')
-rw-r--r--sys/contrib/openzfs/lib/libshare/os/linux/smb.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/sys/contrib/openzfs/lib/libshare/os/linux/smb.c b/sys/contrib/openzfs/lib/libshare/os/linux/smb.c
index 57965ebfaad1..40996ecc8f89 100644
--- a/sys/contrib/openzfs/lib/libshare/os/linux/smb.c
+++ b/sys/contrib/openzfs/lib/libshare/os/linux/smb.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -90,21 +91,32 @@ smb_retrieve_shares(void)
/* Go through the directory, looking for shares */
while ((directory = readdir(shares_dir))) {
+ int fd;
+
if (directory->d_name[0] == '.')
continue;
snprintf(file_path, sizeof (file_path),
"%s/%s", SHARE_DIR, directory->d_name);
- if (stat(file_path, &eStat) == -1) {
+ if ((fd = open(file_path, O_RDONLY | O_CLOEXEC)) == -1) {
+ rc = SA_SYSTEM_ERR;
+ goto out;
+ }
+
+ if (fstat(fd, &eStat) == -1) {
+ close(fd);
rc = SA_SYSTEM_ERR;
goto out;
}
- if (!S_ISREG(eStat.st_mode))
+ if (!S_ISREG(eStat.st_mode)) {
+ close(fd);
continue;
+ }
- if ((share_file_fp = fopen(file_path, "re")) == NULL) {
+ if ((share_file_fp = fdopen(fd, "r")) == NULL) {
+ close(fd);
rc = SA_SYSTEM_ERR;
goto out;
}