Skip to content

Instantly share code, notes, and snippets.

@barafael
Created October 8, 2020 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barafael/dee3c9918807bb1d1732903030ae4db8 to your computer and use it in GitHub Desktop.
Save barafael/dee3c9918807bb1d1732903030ae4db8 to your computer and use it in GitHub Desktop.
Vulnerability hidden by type conversion
#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