Use of Expired File Descriptor

Incomplete Base
Structure: Simple
Description

This vulnerability occurs when a program attempts to use a file descriptor after it has been closed, treating it as if it were still valid.

Extended Description

When a file descriptor is closed, the operating system marks it as available for reuse. If your code later uses that same descriptor value—thinking it still points to the original file or socket—it will actually be interacting with a completely different, newly opened resource. This can lead to data corruption, security breaches, or application crashes as you read from or write to an unintended target. To prevent this, developers should immediately set file descriptor variables to an invalid state (like -1) after closing them and implement robust state checks before use. Relying on the descriptor value alone is unsafe because the system recycles these identifiers, breaking the assumed link between the descriptor number and your intended resource.

Common Consequences 2
Scope: Confidentiality

Impact: Read Files or Directories

The program could read data from the wrong file.

Scope: Availability

Impact: DoS: Crash, Exit, or Restart

Accessing a file descriptor that has been closed can cause a crash.

Likelihood of Exploit

Medium

Applicable Platforms
Languages:
C : SometimesC++ : SometimesNot Language-Specific : Undetermined
Modes of Introduction
Implementation
Alternate Terms

Stale file descriptor

Taxonomy Mapping
  • CERT C Secure Coding