Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This compliant solution performs the recv() call with the parameter oMSG_nonblockDONTWAIT, which causes the call to fail if no messages are available on the socket:

Code Block
bgColor#ccccff
langc
void thread_foo(void *ptr) {
  uint32_t num;
  int result;

  /* sock is a connected TCP socket */

  if ((result = recv(sock, (void *)&num, sizeof(uint32_t), OMSG_NONBLOCKDONTWAIT)) < 0) {
    /* Handle Error */
  }

  if ((result = pthread_mutex_lock(&mutex)) != 0) {
    /* Handle Error */
  }

  /* ... */

  if ((result = pthread_mutex_unlock(&mutex)) != 0) {
    /* Handle Error */
  }
}

...

Blocking or lengthy operations performed within synchronized regions could result in a deadlocked or an unresponsive system.

Rule

Severity

Likelihood

Detectable

Remediation CostRepairable

Priority

Level

POS52-C

Low

Probable

No

NoHigh

P2

L3

Automated Detection

ToolVersionCheckerDescription
CodeSonar
Include Page
CodeSonar_V
CodeSonar_V
CONCURRENCY.STARVE.BLOCKINGBlocking in Critical Section
Helix QAC

Include Page
Helix QAC_V
Helix QAC_V

DF4966, DF4967
Klocwork
Include Page
Klocwork_V
Klocwork_V
CONC.SLEEP
Parasoft C/C++test
Include Page
Parasoft_V
Parasoft_V

CERT_C-POS52-a

Do not use blocking functions while holding a lock

Polyspace Bug Finder

Include Page
Polyspace Bug Finder_V
Polyspace Bug Finder_V

CERT C: Rule POS52-CChecks for blocking operation while holding lock (rule
partially
fully covered)
PRQA QA-C
Security Reviewer - Static Reviewer

Include Page

PRQA QA-C_vPRQA QA-C_v4966, 4967

Security Reviewer - Static Reviewer_V
Security Reviewer - Static Reviewer_V

RTOS_20Fully implemented

Related Guidelines

Key here (explains table format and definitions)

...