Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

heap-buffer-overflow in BerEncoder_encodeLength of /src/libiec61850/src/mms/asn1/ber_encoder.c #505

Closed
aT0ngMu opened this issue May 22, 2024 · 1 comment

Comments

@aT0ngMu
Copy link

aT0ngMu commented May 22, 2024

A heap-buffer-overflow has occurred when running program, this can reproduce on the latest commit.

version
v1.5

Verification steps
build_run.log
build_run.log

error message
error_message.log
error_message.log

reproduce code

#include <fuzzer/FuzzedDataProvider.h>
#include "mms_value.h"
#include <cstdlib>

extern "C" {
    int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
        FuzzedDataProvider stream(data, size);

        MmsValue* value = MmsValue_new(); // Use MmsValue_new to create a new MmsValue object
        int8_t int_value = stream.ConsumeIntegral<int8_t>(); // Consume an int8_t value from the fuzzer input
        _Bool flag = stream.ConsumeBool();

        MmsValue_setInt8(value, int_value); // Use MmsValue_setInt8 to set the integer value in the MmsValue object
        uint8_t* encoded_data = nullptr;
        int encoded_size = 0;

        // Call MmsValue_encodeMmsData with non-null input for encoded_data
        int result = MmsValue_encodeMmsData(value, &encoded_data, &encoded_size, flag);

        MmsValue_delete(value); // Delete the MmsValue object

        if (encoded_data != nullptr) {
            free(encoded_data); // Free the allocated memory for encoded_data
        }

        return 0;
    }
}
@mzillgith
Copy link
Contributor

I think there is a misunderstanding how the function works.
The buffer and bufPos parameters are not output parameters but they have to point to a buffer with enough space to encode the data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants