[PATCH] address compiler warning for extensions/trace.c

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

 



Hello Qiao,

With more recent versions of gcc, extensions/trace.c generates this warning:

  $ make extensions
  ...
  gcc -Wall -g -shared -rdynamic -o trace.so trace.c -fPIC -DX86_64 -DLZO -DSNAPPY -DGDB_7_6
  /tmp/ccSOIphT.o: In function 'ftrace_show':
  /root/crash.git/extensions/trace.c:1560: warning: the use of 'mktemp' is dangerous, better use 'mkstemp'
  ...
  $

I've attached an untested patch that replaces the mktemp() call with mkstemp().
I believe the only behavioral difference is that mkstemp() will create the file
automatically with permissions 600 and open flags of O_EXCL, whereas it is 
currently being opened with permissions 644 and flags (O_WRONLY | O_CREAT | O_TRUNC).

Can you either ACK the patch, or address the warning as you would prefer? 

Thanks,
  Dave
diff --git a/extensions/trace.c b/extensions/trace.c
index 8639fb2..9f81568 100644
--- a/extensions/trace.c
+++ b/extensions/trace.c
@@ -1533,7 +1533,6 @@ static void ftrace_show(int argc, char *argv[])
 	FILE *file;
 	size_t ret;
 	size_t nitems __attribute__ ((__unused__));
-	char *unused __attribute__ ((__unused__));
 
 	/* check trace-cmd */
 	if (env_trace_cmd)
@@ -1557,8 +1556,9 @@ static void ftrace_show(int argc, char *argv[])
 	}
 
 	/* dump trace.dat to the temp file */
-	unused = mktemp(tmp);
-	fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+	fd = mkstemp(tmp);
+	if (fd < 0)
+		return;
 	if (trace_cmd_data_output(fd) < 0)
 		goto out;
 
--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux