Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

NULL Pointer Dereference in cJSON_GetErrorPtr When cJSON_Parse Receives NULL Input

オープン
#1,035 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 12 日以内に返信

@rishi-ragavan がすでに取り組んでいます。

2026年8月21日 から。

  • #1066 @rishi-ragavan による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
64/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
c
領域
security

調査の方向性

cJSON.c の cJSON_GetErrorPtr(94–96 行目)と cJSON_ParseWithLengthOpts(1153–1156 行目付近)から調査を始め、NULL 入力時の失敗経路と、文書化されているエラー報告パターンを追跡します。報告された入力に対するリグレッションテストのカバレッジを追加し、既存のテストまたはファジングのセットアップで、エラー報告が NULL デリファレンスにつながらなくなったことを確認します。

索引モデルが issue の本文から書いたものです。

説明

NULL Pointer Dereference in cJSON_GetErrorPtr When cJSON_Parse Receives NULL Input
Summary

A NULL pointer dereference vulnerability exists in function cJSON_GetErrorPtr at cJSON.c:94–96. When cJSON_Parse(NULL) is called, the function correctly returns NULL to indicate parse failure, but cJSON_GetErrorPtr() subsequently returns NULL instead of a valid error pointer. A caller following the documented error-reporting pattern will crash with a segmentation fault when dereferencing this NULL pointer.

Version

v1.7.19

Description

The root cause is in cJSON_ParseWithLengthOpts at cJSON.c:1156. When value == NULL, the code jumps to fail before setting global_error from the input buffer. The static variable global_error remains at its zero-initialized state {NULL, 0} (set at line 1153).cJSON_GetErrorPtr (line 94–96) computes:return (const char*) (global_error.json + global_error.position);// NULL + 0 = NULL

Steps to reproduce
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "cJSON.h"

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
    char *json_str = (char *)malloc(size + 1);
    if (json_str == NULL) return 0;
    memcpy(json_str, data, size);
    json_str[size] = '\0';

    cJSON *result = cJSON_ParseWithLength(json_str, size);

    if (result != NULL) {
        volatile char crash = *cJSON_GetErrorPtr();
        (void)crash;

        cJSON_Delete(result);
    }

    free(json_str);
    return 0;
}
Reproduction Steps
$ https://github.com/DaveGamble/cJSON; cd cJSON.
$ clang-14 -I.. -g -fsanitize=fuzzer,address -o vuln3  vuln3.c  path/to/cjson/cJSON.c  path/to/cjson/cJSON_Utils.c -lm
$ ./vuln3  poc-3
==115411==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x5fe79b9bd996 bp 0x7ffccf5df2a0 sp 0x7ffccf5df160 T0)
==115411==The signal is caused by a READ memory access.
==115411==Hint: address points to the zero page.
    #0 0x5fe79b9bd996 in LLVMFuzzerTestOneInput /home/ubuntu/Project/TRACE/database/cJSON/drivers/vuln3_null_geterrorptr_fuzz.c:55:31
    #1 0x5fe79b8e6393 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/home/ubuntu/Project/TRACE/database/cJSON/drivers/vuln3_null_geterrorptr_fuzz+0x43393) (BuildId: 568bd0701503a6453788ada1dc42cb912068d8d3)
    #2 0x5fe79b8d010f in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) (/home/ubuntu/Project/TRACE/database/cJSON/drivers/vuln3_null_geterrorptr_fuzz+0x2d10f) (BuildId: 568bd0701503a6453788ada1dc42cb912068d8d3)
    #3 0x5fe79b8d5e66 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) (/home/ubuntu/Project/TRACE/database/cJSON/drivers/vuln3_null_geterrorptr_fuzz+0x32e66) (BuildId: 568bd0701503a6453788ada1dc42cb912068d8d3)
    #4 0x5fe79b8ffc82 in main (/home/ubuntu/Project/TRACE/database/cJSON/drivers/vuln3_null_geterrorptr_fuzz+0x5cc82) (BuildId: 568bd0701503a6453788ada1dc42cb912068d8d3)
    #5 0x7766a9629d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #6 0x7766a9629e3f in __libc_start_main csu/../csu/libc-start.c:392:3
    #7 0x5fe79b8ca9d4 in _start (/home/ubuntu/Project/TRACE/database/cJSON/drivers/vuln3_null_geterrorptr_fuzz+0x279d4) (BuildId: 568bd0701503a6453788ada1dc42cb912068d8d3)
POC

https://github.com/sdnuhfiu/poc-yanzheng/poc-3

Impact

Potentially causing DoS

主要言語
C
スター
13k
フォーク
3.5k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

DaveGamble/cJSON のほかの issue

DaveGamble/cJSON の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。