GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — A segmentation fault in cJSON_SetValuestring · Issue #839 · DaveGamble/cJSON

A segmentation fault in cJSON_SetValuestring #839

New issue
Copy link
New issue
Copy link
Closed
#840
Closed
A segmentation fault in cJSON_SetValuestring#839
#840
Copy link

Description

@Up-wind
Up-wind
opened on Mar 25, 2024
Issue body actions

Hi,

when fuzzing cJSON library, I found a segmentation fault happened in cJSON_SetValuestring.

If the valuestring passed to cJSON_SetValuestring is NULL, a null pointer dereference will happen in the following statements:

CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
{
    ···
    if (object->valuestring == NULL)
    {
        return NULL;
    }
    if (strlen(valuestring) <= strlen(object->valuestring)) // null pointer dereference happens here
    {
        strcpy(object->valuestring, valuestring);
        return object->valuestring;
    }

The PoC is as follows:

    cJSON *item = cJSON_CreateString("apple");
    cJSON_SetValuestring(item, NULL);

The null pointer dereference happens here can potentially cause denial of service (DOS). Maybe we can check it before strlen(), just like object->valuestring did.

Affected Version

commit 87d8f0961a01bf09bef98ff89bae9fdec42181ee (HEAD -> master, tag: v1.7.17, origin/master, origin/HEAD)
Author: Alanscut <[email protected]>
Date:   Tue Dec 26 10:07:05 2023 +0800

Activity

  1. Alanscut
    closed this as completedin #840on Apr 26, 2024
  2. Alanscut commented on Apr 26, 2024

    @Alanscut
    Alanscut
    on Apr 26, 2024
    Collaborator
    More actions

    Hi @Up-wind
    Thanks for your job.

    IMHO security issues should be discussed in private. Besides this, it will be appreciated to request a CVE after a version containing a fix is released, in which way downstream users can upgrade at the first time when CVE is published.

    To achieve this. I will update the GH security pages later.

  3. Up-wind commented on Apr 26, 2024

    @Up-wind
    Up-wind
    on Apr 26, 2024
    ContributorAuthor
    More actions

    Hi @Alanscut
    Thank you for teaching me an important lesson.

    I apologize for my reckless of discussing a security issue in public and requesting a CVE before a fixed version is released. I hope that this issue will not affect any downstream projects.

    I actually quite agree with what you said, but I was just new to this. I’ve seen someone did this before, so I naively thought that it was a proper way to request a CVE.

    Sorry again. I will obey the security rules next time.

    Reacted by Alan Wang
  4. Alanscut
    added 4 commits that reference this issue on Apr 28, 2024

    fix: fix NULL valuestring error

    This issue will close once commit a193d24 is merged into the 'master' branch.
    a193d24

    fix: fix NULL valuestring error

    This issue will close once commit 5807763 is merged into the 'master' branch.
    5807763

    fix: fix NULL valuestring error

    This issue will close once commit 3e20e45 is merged into the 'master' branch.
    3e20e45

    fix: fix NULL valuestring error

    This issue will close once commit e327f1c is merged into the 'master' branch.
    e327f1c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.