Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added return checks for mtx_lock() and mtx_unlock()

...

Code Block
bgColor#ccccff
langc
#include <threads.h>

int account_balance;
mtx_t flag;

/* Initialize flag */

voidint debit(unsigned int amount) {
  if (mtx_lock(&flag) == thrd_error) {
    return -1;  /* Indicate error */
  }
 account
  account_balance -= amount; /* Inside critical section */

  if (mtx_unlock(&flag) == thrd_error) {
    return -1;  /* Indicate error */
  }

  return 0;
}

Risk Assessment

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

CON02-C

Medium

Probable

Medium

P8

L2

...