Versions Compared

Key

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

...

A function that is registered as an exit handler by atexit() must exit by returning, and not in any other manner.:

Code Block
bgColor#ccccFF
langc
#include <stdio.h>
#include <stdlib.h>

void exit1(void) {
  /* ...cleanup code... */
  return;
}

void exit2(void) {
  if (/* condition */) {
    /* ...more cleanup code... */
  }
  return;
}

int main(void) {
  if (atexit(exit1) != 0) {
    /* Handle error */
  }
  if (atexit(exit2) != 0) {
    /* Handle error */
  }
  /* ...program code... */
  exit(0);
}

...

Tool

Version

Checker

Description

Compass/ROSE

 

 

Can detect violations of this rule. In particular, it ensures that all functions registered with atexit() do not call functions such as exit().

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

...