alpine 3.9
tmpfile weakness #67


Weakness Breakdown


A temporary file weakness occurs when a temporary file that is created and used by a high-privilege process is accidentally shared with a low-privilege process, on account of it being temporary and generated after all security controls have been applied. This allows the low-privilege process to read data from the high-privilege process (information leakage), or worse, influence the high-privilege process by modifying the shared temporary file.

Warning code(s):

Temporary file race condition.

File Name:



The highlighted line of code below is the trigger point of this particular Alpine 3.9 tmpfile weakness.

main(argc, argv)
	int	argc;
	char	**argv;
	FILE	*tmpfd;
	char	makeMacro[ BUFSIZ ];
	char	makefileMacro[ BUFSIZ ];

	program = argv[0];
	SetOpts(argc, argv);

	Imakefile = FindImakefile(Imakefile);
	if (Makefile) {
                tmpMakefile = Makefile;
                if ((tmpfd = fopen(tmpMakefile, "w+")) == NULL)
                   LogFatal("Cannot create temporary file %s.", tmpMakefile);
	} else {
	        int fd;
		tmpMakefile = Strdup(tmpMakefile);
		if (mktemp(tmpMakefile) == NULL ||
		    (tmpfd = fopen(tmpMakefile, "w+")) == NULL) {
		   LogFatal("Cannot create temporary file %s.", tmpMakefile);
	        fd = mkstemp(tmpMakefile);
	        if (fd == -1 || (tmpfd = fdopen(fd, "w+")) == NULL) {
		   if (fd != -1) {
		      unlink(tmpMakefile); close(fd);
		   LogFatal("Cannot create temporary file %s.", tmpMakefile);
	AddMakeArg( tmpMakefile );
	sprintf(makeMacro, "MAKE=%s", program);
	AddMakeArg( makeMacro );
	sprintf(makefileMacro, "MAKEFILE=%s", Imakefile);
	AddMakeArg( makefileMacro );

	cleanedImakefile = CleanCppInput(Imakefile);
	cppit(cleanedImakefile, Template, ImakefileC, tmpfd, tmpMakefile);

	if (show) {
		if (Makefile == NULL) 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.