Created
October 8, 2020 15:35
-
-
Save barafael/dee3c9918807bb1d1732903030ae4db8 to your computer and use it in GitHub Desktop.
Vulnerability hidden by type conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stddef.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdio.h> | |
typedef struct packet_st { | |
char *data; | |
size_t length; | |
} packet_t; | |
void receive_packet(packet_t *p) { | |
char *buffer_p = malloc(100); | |
/* write assembly code to buffer_p | |
... | |
*/ | |
p->data = buffer_p; | |
p->length = 0xFFFFFFFFFFFFFFFF; | |
} | |
int main(void) { | |
packet_t p = { | |
.data = NULL, | |
.length = 0, | |
}; | |
receive_packet(&p); | |
char buffer[64]; | |
int bytesToCopy = p.length; | |
if (bytesToCopy < 64) { | |
memcpy(buffer, p.data, bytesToCopy); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment