Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

SV.DOS.TMPFILEDEL

This error occurs when a temporary file is scheduled to be deleted on exit but is not explicitly deleted. This error mostly presents a problem in a server or servlet context.

Vulnerability and risk

Temporary files should be deleted as soon as possible. If a file contains sensitive information, the longer it exists, the better chance an attacker has to gain access to its contents. Also, because directories typically have limits on the number of files allowed, it is possible to overflow the number of temporary files, leading to a denial-of-service (DoS) problem.

Klocwork security vulnerability (SV) checkers identify calls that create potentially dangerous data; these calls are considered unsafe sources. An unsafe source can be any data provided by the user, since the user could be an attacker or has the potential for introducing human error.

Mitigation and prevention

Temporary files should be deleted immediately after use.

Example 1

17     protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
18         String name = req.getParameter("userName");
19         File file = File.createTempFile("file", ".dat");
20         file.deleteOnExit();
21         fillWithUserData(name);
22         char[] data = readData(file);
23         resp.getWriter().print(data);
24     }

SV.DOS.TMPFILEDEL is reported for line 19: File 'file' scheduled for 'delete on exit', meaning that it will remain for the lifetime of the jvm (which can be very long in the case of a server or servlet). Server-side applications should remove files explicitly.

Extension

This checker can be extended through the Klocwork knowledge base. See Tuning Java analysis for more information.