Exploit database

GH-86b7484f09bd144768ff5e0890c5c4a6

mhackiori/cve-2021-3156

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2021-3156

85 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files3
mhackiori/cve-2021-3156Revision 69a796754e46

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

Patch/overflow_simulation_patch.c

C · 1,362 bytes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(int argc, char** argv, char** envp){

    // Buffer where copy user input arguments with escaped characters
    char* user_args;

    // Copy the set of pointers for each command-line argument
    char** NewArgv= (char**) malloc((argc+1) * sizeof(char*));    
    if(NewArgv == NULL){
        puts("Error 1");
        exit(0);
    }
    for(int i=0; i <= argc; i++)
        NewArgv[i]= argv[i];

    char *to, *from, **av;
    size_t size, n;

    for (size = 0, av = NewArgv + 1; *av; av++)
        size += strlen(*av) +1;
    
    if (size == 0 || (user_args = (char*) malloc(size)) == NULL){
        puts("Error 2");
        exit(0);
    }
    
    int total_copied = 0;   // Added for the simulation

    for (to = user_args, av = NewArgv + 1; (from = *av); av++) {
        int actual_copied = 0;  // Part of patch
        while (actual_copied < strlen(*av)) {  // Part of patch
            if (from[0] == '\\' && !isspace((unsigned char)from[1]))
                from++;
            *to++ = *from++;
	        actual_copied++;    // Part of patch
        }
        *to++ = ' ';
	    total_copied+= actual_copied +1;    // Added for the simulation
    }
    *--to = '\0';
    
    for(int i= 0; i< total_copied; i++)
	    printf("user_args[%i]: %c\n", i, user_args[i]);
}