File 0001-cifs-utils-avoid-using-mktemp-when-updating-mtab.patch of Package cifs-utils.41102

From f6fddc4c809ada7107d8c162e288b32a64559883 Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@microsoft.com>
Date: Mon, 20 Jan 2025 18:34:38 -0600
Subject: [PATCH] cifs-utils: avoid using mktemp when updating mtab

Fix build warning: cifs-utils/mount.cifs.c:1726:
    warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'

Use of mktemp() has been deprecated (e.g. due to security issues with
symlink races), and instead mkstemp is often recommended.  Change
the use of mktemp to mkstemp in del_mtab in cifs-utils

Tested-by: Meetakshi Setiya <msetiya@microsoft.com>
Reviewed-by: Meetakshi Setiya <msetiya@microsoft.com>
Reviewed-by: Shyam Prasad N <sprasad@microsoft.com>
Fixes: f46dd7661cfb ("mount.cifs: Properly update mtab during remount")
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com>
---
 mount.cifs.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/mount.cifs.c b/mount.cifs.c
index e46693e..7605130 100644
--- a/mount.cifs.c
+++ b/mount.cifs.c
@@ -41,6 +41,7 @@
 #include <mntent.h>
 #include <fcntl.h>
 #include <limits.h>
+#include <stdbool.h>
 #include <paths.h>
 #include <libgen.h>
 #include <time.h>
@@ -1688,7 +1689,7 @@ add_mtab_exit:
 static int
 del_mtab(char *mountpoint)
 {
-	int len, tmprc, rc = 0;
+	int len, tmprc, rc = 0, tmpfd;
 	FILE *mnttmp, *mntmtab;
 	struct mntent *mountent;
 	char *mtabfile, *mtabdir, *mtabtmpfile = NULL;
@@ -1723,8 +1724,9 @@ del_mtab(char *mountpoint)
 		goto del_mtab_exit;
 	}
 
-	mtabtmpfile = mktemp(mtabtmpfile);
-	if (!mtabtmpfile) {
+	// Use mkstemp instead of mktemp
+	tmpfd = mkstemp(mtabtmpfile);
+	if (tmpfd == -1) {
 		fprintf(stderr, "del_mtab: cannot setup tmp file destination\n");
 		rc = EX_FILEIO;
 		goto del_mtab_exit;
@@ -1734,13 +1736,15 @@ del_mtab(char *mountpoint)
 	if (!mntmtab) {
 		fprintf(stderr, "del_mtab: could not update mount table\n");
 		rc = EX_FILEIO;
+		close(tmpfd);
 		goto del_mtab_exit;
 	}
 
-	mnttmp = setmntent(mtabtmpfile, "w");
+	mnttmp = fdopen(tmpfd, "w");
 	if (!mnttmp) {
 		fprintf(stderr, "del_mtab: could not update mount table\n");
 		endmntent(mntmtab);
+		close(tmpfd);
 		rc = EX_FILEIO;
 		goto del_mtab_exit;
 	}
-- 
2.50.1

openSUSE Build Service is sponsored by