Skip to content

Instantly share code, notes, and snippets.

@jiachen247
Created April 24, 2022 10:51
Show Gist options
  • Save jiachen247/82c6d50270347107b56e459e89eca628 to your computer and use it in GitHub Desktop.
Save jiachen247/82c6d50270347107b56e459e89eca628 to your computer and use it in GitHub Desktop.
#include "HeaderFile.h"
void clangGood () {
// simple use after free
char *buf;
buf = (char*) malloc (50 * sizeof(char));
strcpy(buf, "Hello world!!");
free(buf);
char *c = buf; /*ERROR:Invalid memory access to already freed area*/
}
int echo(flag) {
int ret;
if (flag ==0)
ret = 0;
else
ret=1;
return ret;
}
void clangBad () {
// memleak due to path sens (interproc in conditional)
double *dptr= (double*) malloc(5*sizeof(double));
if (echo(1) == 1) {
free(dptr);
}
}
int *returnNullPointer (void)
{
return (NULL);
}
int inferGood() {
// null deference across interproc calls
int *p = returnNullPointer();
return *p;
}
void inferBad() {
// simple memleak
double *dptr= (double*) malloc(5*sizeof(double));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment