Hello Dave,
On 07/07/2015 11:20 PM, Dave Anderson wrote:
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).
It seems good to me.
Acked-by: Qiao Nuohan <qiaonuohan(a)cn.fujitsu.com>
Can you either ACK the patch, or address the warning as you would prefer?
Thanks,
Dave
use_mkstemp.patch
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);
"tmp" will be modified to the path of the temporary file, good.
+ if (fd < 0)
+ return;
if (trace_cmd_data_output(fd) < 0)
goto out;
--
Regards
Qiao Nuohan