Versions Compared

Key

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

...

Portably, signal handlers can only unconditionally get or set a flag of type volatile sig_atomic_t and return.:

Code Block
bgColor#ccccff
langc
#include <signal.h>
#include <stdlib.h>
#include <string.h>

enum { MAX_MSG_SIZE = 24 };
volatile sig_atomic_t e_flag = 0;

void handler(int signum) {
  e_flag = 1;
}

int main(void) {
  char *err_msg = (char *)malloc(MAX_MSG_SIZE);
  if (err_msg == NULL) {
    /* Handle error condition */
  }

  signal(SIGINT, handler);
  strcpy(err_msg, "No errors yet.");

  /* Main code loop */

  if (e_flag) {
    strcpy(err_msg, "SIGINT received.");
  }
  return 0;
}

...

Tool

Version

Checker

Description

LDRA tool suite

Include Page
LDRA_V
LDRA_V

87 D

Fully implemented.

Compass/ROSE

 

 

Can detect violations of this rule for single-file programs.

Related Vulnerabilities

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

...

[Dowd 2006]Chapter 13, "Synchronization and State"
[ISO/IEC 2003]"Signals and Interrupts"
[Open Group 2004]longjmp
[OpenBSD]signal() Man Page
[Zalewski 2001]"Delivering Signals for Fun and Profit"

 

...