Issue with Setting Up Sparse

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



My name is Edgar Khachatryan, and I am a student currently working on a project that involves static analysis using Sparse. I have encountered an issue where running Sparse with the command "sparse file.c" does not detect simple memory issues such as memory leaks, double frees, or use-after-free errors in a single file.

I have attempted to install Sparse versions 0.6.3 and 0.6.4 on different Ubuntu releases (20.04, 22.04, and 24.04) with LLVM versions 11 and 12. However, none of these combinations have worked as expected.

Following the installation instructions provided in the documentation, I ran "make" and "make install" in the Sparse directory, but I was unable to find further details regarding dependencies or required versions for proper setup and functioning. As a result, I am reaching out to ask for clarification on the following:

1) Are there specific dependencies or versions of libraries (e.g., libxml, sqlite3, gtk3, etc.) that need to be installed to ensure Sparse functions correctly?
2) Is there any additional documentation available beyond what was provided? It would be very helpful to have more detailed instructions or guidelines for setting up Sparse in different environments.

I also have the command-line output text that details the issues I’ve encountered and The C source file I used as input. I would be happy to share it with you if it would help resolve the problem.

Thank you in advance for your time and assistance. I look forward to your response and any guidance you can provide to help resolve this issue.

Best regards,
Edgar Khachatryan,
Russian-Armenian University, Yerevan, Armenia
#include <stdio.h>
#include <stdlib.h>

void memory_leak() {
    int *ptr = (int *)malloc(sizeof(int) * 10);  // Memory allocated but never freed
    if (!ptr) {
        printf("Memory allocation failed\n");
        return;
    }
    ptr[0] = 42;  // Some usage
}

void double_free() {
    int *ptr = (int *)malloc(sizeof(int) * 10);
    if (!ptr) {
        printf("Memory allocation failed\n");
        return;
    }
    free(ptr);  // First free
    free(ptr);  // Double free (undefined behavior)
}

void use_after_free() {
    int *ptr = (int *)malloc(sizeof(int) * 10);
    if (!ptr) {
        printf("Memory allocation failed\n");
        return;
    }
    free(ptr);    // Freeing memory
    ptr[0] = 42;  // Use after free (undefined behavior)
}

int main() {
    memory_leak();
    double_free();
    use_after_free();
    return 0;
}

Attachment: cmd_out
Description: Binary data


[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux