Incorrect order of network connection operations
Socket is not correctly established due to bad order of connection steps or missing steps
Description
This defect occurs when you perform operations on a network connection at the wrong point of the connection lifecycle.
Risk
Sending or receiving data to an incorrectly connected socket can cause unexpected behavior or disclosure of sensitive information.
If you do not connect your socket correctly or change the connection by mistake, you can send sensitive data to an unexpected port. You can also get unexpected data from an incorrect socket.
Fix
During socket connection and communication, check the return of each call and the length of the data.
Before reading, writing, sending, or receiving information, create sockets in this order:
For a connection-oriented server socket (
SOCK_STREAM
orSOCK_SEQPACKET
):socket(...); bind(...); listen(...); accept(...);
For a connectionless server socket (
SOCK_DGRAM
):socket(...); bind(...);
For a client socket (connection-oriented or connectionless):
socket(...); connect(...);
Examples
Result Information
Group: Security |
Language: C | C++ |
Default: Off |
Command-Line Syntax: BAD_NETWORK_CONNECT_ORDER |
Impact: Medium |
Version History
Introduced in R2015b
See Also
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)