CWE-828 Variant Incomplete

Signal Handler with Functionality that is not Asynchronous-Safe

This weakness occurs when a program's signal handler contains code that is not asynchronous-safe. This means the handler can be interrupted or can corrupt shared data, leading to unpredictable…

Definition

What is CWE-828?

This weakness occurs when a program's signal handler contains code that is not asynchronous-safe. This means the handler can be interrupted or can corrupt shared data, leading to unpredictable program behavior.
Signal handlers interrupt your program's normal flow to process events. If these handlers use global variables, call non-reentrant functions like malloc(), or modify shared state, they can corrupt memory or program logic when interrupted. This corruption often creates race conditions, making your application vulnerable to crashes (denial of service) or, in some cases, allowing an attacker to execute arbitrary code. A common pitfall is writing handlers that assume they run only once, but signals can fire repeatedly or share the same handler. If your main code and the signal handler both access the same data, an incoming signal can leave that data in a broken, inconsistent state. Since very few functions are truly reentrant, you must carefully design handlers to use only asynchronous-safe operations to maintain system stability.
Real-world impact

Real-world CVEs caused by CWE-828

  • Signal handler uses functions that ultimately call the unsafe syslog/malloc/s*printf, leading to denial of service via multiple login attempts

  • Chain: Signal handler contains too much functionality (CWE-828), introducing a race condition (CWE-362) that leads to a double free (CWE-415).

  • unsafe calls to library functions from signal handler

  • SIGURG can be used to remotely interrupt signal handler; other variants exist.

  • SIGCHLD signal to FTP server can cause crash under heavy load while executing non-reentrant functions like malloc/free.

  • SIGCHLD not blocked in a daemon loop while counter is modified, causing counter to get out of sync.

How attackers exploit it

Step-by-step attacker path

  1. 1

    This code registers the same signal handler function with two different signals (CWE-831). If those signals are sent to the process, the handler creates a log message (specified in the first argument to the program) and exits.

  2. 2

    The handler function uses global state (globalVar and logMessage), and it can be called by both the SIGHUP and SIGTERM signals. An attack scenario might follow these lines:

  3. 3

    - The program begins execution, initializes logMessage, and registers the signal handlers for SIGHUP and SIGTERM. - The program begins its "normal" functionality, which is simplified as sleep(), but could be any functionality that consumes some time. - The attacker sends SIGHUP, which invokes handler (call this "SIGHUP-handler"). - SIGHUP-handler begins to execute, calling syslog(). - syslog() calls malloc(), which is non-reentrant. malloc() begins to modify metadata to manage the heap. - The attacker then sends SIGTERM. - SIGHUP-handler is interrupted, but syslog's malloc call is still executing and has not finished modifying its metadata. - The SIGTERM handler is invoked. - SIGTERM-handler records the log message using syslog(), then frees the logMessage variable.

  4. 4

    At this point, the state of the heap is uncertain, because malloc is still modifying the metadata for the heap; the metadata might be in an inconsistent state. The SIGTERM-handler call to free() is assuming that the metadata is inconsistent, possibly causing it to write data to the wrong location while managing the heap. The result is memory corruption, which could lead to a crash or even code execution, depending on the circumstances under which the code is running.

  5. 5

    Note that this is an adaptation of a classic example as originally presented by Michal Zalewski [REF-360]; the original example was shown to be exploitable for code execution.

Vulnerable code example

Vulnerable C

This code registers the same signal handler function with two different signals (CWE-831). If those signals are sent to the process, the handler creates a log message (specified in the first argument to the program) and exits.

Vulnerable C
char *logMessage;
  void handler (int sigNum) {
  		syslog(LOG_NOTICE, "%s\n", logMessage);
  		free(logMessage);
```
/* artificially increase the size of the timing window to make demonstration of this weakness easier. */* 
  		
  		sleep(10);
  		exit(0);}
  
  int main (int argc, char* argv[]) {
  ```
  		logMessage = strdup(argv[1]);
```
/* Register signal handlers. */* 
  		
  		signal(SIGHUP, handler);
  		signal(SIGTERM, handler);
  		
  		 */* artificially increase the size of the timing window to make demonstration of this weakness easier. */* 
  		
  		sleep(10);}
Secure code example

Secure pseudo

Secure pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
  const safe = validateAndEscape(input);
  return executeWithGuards(safe);
}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Prevention checklist

How to prevent CWE-828

  • Implementation / Architecture and Design Eliminate the usage of non-reentrant functionality inside of signal handlers. This includes replacing all non-reentrant library calls with reentrant calls. Note: This will not always be possible and may require large portions of the product to be rewritten or even redesigned. Sometimes reentrant-safe library alternatives will not be available. Sometimes non-reentrant interaction between the state of the system and the signal handler will be required by design.
  • Implementation Where non-reentrant functionality must be leveraged within a signal handler, be sure to block or mask signals appropriately. This includes blocking other signals within the signal handler itself that may also leverage the functionality. It also includes blocking all signals reliant upon the functionality when it is being accessed or modified by the normal behaviors of the product.
Detection signals

How to detect CWE-828

SAST High

Run static analysis (SAST) on the codebase looking for the unsafe pattern in the data flow.

DAST Moderate

Run dynamic application security testing against the live endpoint.

Runtime Moderate

Watch runtime logs for unusual exception traces, malformed input, or authorization bypass attempts.

Code review Moderate

Code review: flag any new code that handles input from this surface without using the validated framework helpers.

Plexicus auto-fix

Plexicus auto-detects CWE-828 and opens a fix PR in under 60 seconds.

Codex Remedium scans every commit, identifies this exact weakness, and ships a reviewer-ready pull request with the patch. No tickets. No hand-offs.

Frequently asked questions

Frequently asked questions

What is CWE-828?

This weakness occurs when a program's signal handler contains code that is not asynchronous-safe. This means the handler can be interrupted or can corrupt shared data, leading to unpredictable program behavior.

How serious is CWE-828?

MITRE has not published a likelihood-of-exploit rating for this weakness. Treat it as medium-impact until your threat model proves otherwise.

What languages or platforms are affected by CWE-828?

MITRE has not specified affected platforms for this CWE — it can apply across most application stacks.

How can I prevent CWE-828?

Eliminate the usage of non-reentrant functionality inside of signal handlers. This includes replacing all non-reentrant library calls with reentrant calls. Note: This will not always be possible and may require large portions of the product to be rewritten or even redesigned. Sometimes reentrant-safe library alternatives will not be available. Sometimes non-reentrant interaction between the state of the system and the signal handler will be required by design. Where non-reentrant functionality…

How does Plexicus detect and fix CWE-828?

Plexicus's SAST engine matches the data-flow signature for CWE-828 on every commit. When a match is found, our Codex Remedium agent opens a fix PR with the corrected code, tests, and a one-line summary for the reviewer.

Where can I learn more about CWE-828?

MITRE publishes the canonical definition at https://cwe.mitre.org/data/definitions/828.html. You can also reference OWASP and NIST documentation for adjacent guidance.

Ready when you are

Don't Let Security
Weigh You Down.

Stop choosing between AI velocity and security debt. Plexicus is the only platform that runs Vibe Coding Security and ASPM in parallel — one workflow, every codebase.