---
title: "CWE-1265: Unintended Reentrant Invocation of Non-reentrant Code Via Nested Calls"
url: https://radicalnotion.ai/cwe/cwe-1265
type: cwe
description: "The product invokes code that is believed to be reentrant, but the code performs a call that unintentionally produces a nested invocation of non-reentrant code."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-1265: Unintended Reentrant Invocation of Non-reentrant Code Via Nested Calls

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Draft
- **CVEs with this as primary weakness:** 4
- **Of those, in CISA KEV:** 0
- **New in 2026:** 3
- **CWE catalog version:** 4.21

## Description

The product invokes code that is believed to be reentrant, but the code performs a call that unintentionally produces a nested invocation of non-reentrant code.

In a complex product, a single function call may lead to many different possible code paths, some of which may involve deeply nested calls. It may be difficult to foresee all possible code paths that could emanate from a given function call, even if that call is assumed to be reentrant. In some systems, an external actor can manipulate inputs to the system and thereby achieve a wide range of possible control flows. This is frequently a concern in products that execute scripts from untrusted sources. Examples of such products are web browsers and PDF readers. A weakness is present when one of the possible code paths resulting from a function call alters program state that the original caller assumes to be unchanged during the call.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity | Unexpected State | Exploitation of this weakness can leave the application in an unexpected state and cause variables to be reassigned before the first invocation has completed. This may eventually result in memory corruption or unexpected code execution. |

## Potential mitigations

### Architecture and Design

When architecting a system that will execute untrusted code in response to events, consider executing the untrusted event handlers asynchronously (asynchronous message passing) as opposed to executing them synchronously at the time each event fires. The untrusted code should execute at the start of the next iteration of the thread's message loop. In this way, calls into non-reentrant code are strictly serialized, so that each operation completes fully before the next operation begins. Special attention must be paid to all places where type coercion may result in script execution. Performing all needed coercions at the very beginning of an operation can help reduce the chance of operations executing at unexpected junctures.

Effectiveness: High

### Implementation

Make sure the code (e.g., function or class) in question is reentrant by not leveraging non-local data, not modifying its own code, and not calling other non-reentrant code.

Effectiveness: High

## Demonstrative examples

### Example 1

The implementation of the Widget class in the following C++ code is an example of code that is not designed to be reentrant. If an invocation of a method of Widget inadvertently produces a second nested invocation of a method of Widget, then data member backgroundImage may unexpectedly change during execution of the outer call.

Bad code:

```c++
class Widget
{
    private:
        Image* backgroundImage;

    public:
        void click()
        {
            if (backgroundImage)
            {
                backgroundImage->click();
            }
        }

        void changeBackgroundImage(Image* newImage)
        {
            if (backgroundImage)
            {
                delete backgroundImage;
            }
            backgroundImage = newImage;
        }
}

class Image
{
    public:
        void click()
        {
            scriptEngine->fireOnImageClick();
            /* perform some operations using "this" pointer */
        }
}
```

Looking closer at this example, Widget::click() calls backgroundImage-\>click(), which in turn calls scriptEngine-\>fireOnImageClick(). The code within fireOnImageClick() invokes the appropriate script handler routine as defined by the document being rendered. In this scenario this script routine is supplied by an adversary and this malicious script makes a call to Widget::changeBackgroundImage(), deleting the Image object pointed to by backgroundImage. When control returns to Image::click, the function's backgroundImage "this" pointer (which is the former value of backgroundImage) is a dangling pointer. The root of this weakness is that while one operation on Widget (click) is in the midst of executing, a second operation on the Widget object may be invoked (in this case, the second invocation is a call to different method, namely changeBackgroundImage) that modifies the non-local variable.

### Example 2

This is another example of C++ code that is not designed to be reentrant.

Bad code:

```c++
class Request
{
    private:
        std::string uri;
        /* ... */

    public:
        void setup(ScriptObject* _uri)
        {
            this->uri = scriptEngine->coerceToString(_uri);
            /* ... */
        }

        void send(ScriptObject* _data)
        {
            Credentials credentials = GetCredentials(uri);
            std::string data = scriptEngine->coerceToString(_data);
            doSend(uri, credentials, data);
        }
}
```

The expected order of operations is a call to Request::setup(), followed by a call to Request::send(). Request::send() calls scriptEngine-\>coerceToString(\_data) to coerce a script-provided parameter into a string. This operation may produce script execution. For example, if the script language is ECMAScript, arbitrary script execution may result if \_data is an adversary-supplied ECMAScript object having a custom toString method. If the adversary's script makes a new call to Request::setup, then when control returns to Request::send, the field uri and the local variable credentials will no longer be consistent with one another. As a result, credentials for one resource will be shared improperly with a different resource. The root of this weakness is that while one operation on Request (send) is in the midst of executing, a second operation may be invoked (setup).

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2014-1772 | In this vulnerability, by registering a malicious onerror handler, an adversary can produce unexpected re-entrance of a CDOMRange object. \[REF-1098\] |
| CVE-2018-8174 | This CVE covers several vulnerable scenarios enabled by abuse of the Class\_Terminate feature in Microsoft VBScript. In one scenario, Class\_Terminate is used to produce an undesirable re-entrance of ScriptingDictionary during execution of that object's destructor. In another scenario, a vulnerable condition results from a recursive entrance of a property setter method. This recursive invocation produces a second, spurious call to the Release method of a reference-counted object, causing a UAF when that object is freed prematurely. This vulnerability pattern has been popularized as "Double Kill". \[REF-1099\] |

## Real CVEs with this weakness

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2023-25240 | SameSite Attribute vulnerability in pimCore | high | 8.8 | - | No | 2023-02-13 |
| CVE-2026-119141 | Wasmtime 46.0.0 before 48.0.6 and 49.0.0 before 49.0.3 Host Panic via realloc | medium | 6.9 | - | No | 2026-10-29 |
| CVE-2026-119136 | Wasmtime 42.0.0 before 48.0.6 and 49.0.0 before 49.0.3 Async-Entrypoint Enforcement Bypass | medium | 5.9 | - | No | 2026-10-29 |
| CVE-2026-98888 | arm64: kprobes: Allow reentering kprobes while single-stepping | medium | 5.5 | - | No | 2026-10-23 |

## Related attack patterns (CAPEC)

- [CAPEC-74](https://radicalnotion.ai/capec/capec-74): Manipulating State

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-662](https://radicalnotion.ai/cwe/cwe-662) | Improper Synchronization |
| Peer | [CWE-663](https://radicalnotion.ai/cwe/cwe-663) | Use of a Non-reentrant Function in a Concurrent Context |
| Can precede | [CWE-416](https://radicalnotion.ai/cwe/cwe-416) | Use After Free |

## Frequently asked questions

### What is CWE-1265?

The product invokes code that is believed to be reentrant, but the code performs a call that unintentionally produces a nested invocation of non-reentrant code.

### What CVEs are caused by CWE-1265?

4 recorded CVEs are attributed to CWE-1265, including CVE-2023-25240, CVE-2026-119141 and CVE-2026-119136.

### How do you prevent CWE-1265?

When architecting a system that will execute untrusted code in response to events, consider executing the untrusted event handlers asynchronously (asynchronous message passing) as opposed to executing them synchronously at the time each event fires. The untrusted code should execute at the start of the next iteration of the thread's message loop. In this way, calls into non-reentrant code are strictly serialized, so that each operation completes fully before the next operation begins. Special attention must be paid to all places where type coercion may result in script execution. Performing all needed coercions at the very beginning of an operation can help reduce the chance of operations executing at unexpected junctures.

### What are the consequences of CWE-1265?

Exploiting CWE-1265 can lead to: Unexpected State.

### Is CWE-1265 actively exploited?

4 recorded CVEs are caused by CWE-1265; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/1265.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-1265). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
