Skip to content

NULL Pointer in ntl_to_buf() #769

@Leeziao

Description

@Leeziao

The NULL Pointer vulnerability happens in ntl_to_buf(), cee-utils/ntl.c
How the vulnerabilitiy happens:

  1. ntl_to_buf() is invoked with buf is NULL, the first element of p is NULL
  2. The NULL variable buf gets dereferenced at *buf = '\0';

Steps to reproduce:

  1. Compile following file (poc.c)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ntl.h"

size_t serialize_element(char *buf, size_t size, void *element) {
    if (!element) {
        const char *null_str = "null";
        if (buf) snprintf(buf, size, "%s", null_str);
        return strlen(null_str);
    }

    int *val = (int*)element;
    return snprintf(buf, size, "%d", *val);
}

int main(void) {
    ntl_t p = ntl_calloc(3, sizeof(int));

    struct ntl_str_delimiter delim = {
        .start_delimiter = '[',
        .element_delimiter = ", ",
        .last_element_delimiter = "",
        .end_delimiter = ']',
        .null_ntl = "[]"
    };

    char *result = NULL;
    ntl_to_abuf(&result, p, &delim, serialize_element);
}
  1. Compile and Run
$ gcc poc.c -o poc -L. -lreddit
$ ./poc
zsh: segmentation fault (core dumped)  ./poc

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