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.SOCKETS

This warning is reported when an application is using sockets.

Vulnerability and risk

Socket usage should be avoided in many cases. For example, the EJB standard contains the following guidelines: An enterprise bean must not attempt to listen on a socket, accept connections on a socket, or use socket for multicast. Other applications (applets, servlets, and so on) might have serious security problems if sockets are used.

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

Use framework method calls instead of using sockets directly.

Example 1

17 public class SV_SOCKETS_Sample_1 extends Applet {
18     static final int PORT = 7776;
19     public void init() {
20         super.init();
21         try {
22             final ServerSocket serv = new ServerSocket(PORT);
23             Runnable rr = new Runnable() {
24                 public void run() {
25                     try {
26                         while (true) {
27                             Socket sock = serv.accept();
28                             BufferedReader r = new BufferedReader(
29                                     new InputStreamReader(sock
30                                             .getInputStream()));
31                             PrintWriter w = new PrintWriter(sock
32                                     .getOutputStream(), false); // no autoFlush
33                             w.write("Hello");
34                             w.flush();
35                             r.close();
36                             w.close();
37                             sock.close();
38                         }
39                     } catch (IOException e) {
40                         e.printStackTrace();
41                     }
42                 }
43             };
44             new Thread(rr).start();
45         } catch (IOException e1) {
46             e1.printStackTrace();
47         }
48     }
49     //...
50     public void paint(Graphics g) {
51     }
52 }

SV.SOCKETS is reported for line 22: Using sockets directly should be avoided in many cases (e.g. in Applets, EJBs). This might cause security problems