Skip to content

Instantly share code, notes, and snippets.

@inaz2
Last active August 29, 2015 14:16
Show Gist options
  • Save inaz2/143e9814bde9dadcd26d to your computer and use it in GitHub Desktop.
Save inaz2/143e9814bde9dadcd26d to your computer and use it in GitHub Desktop.
a minimum test of uninitialized pointer use (CWE-824)
$ uname -a
Linux vm-ubuntu64 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.1 LTS
Release: 14.04
Codename: trusty
$ gcc uninitialized_pointer_use.c
$ ./a.out
p = 0x4141414141414141
Segmentation fault (core dumped)
#include <stdio.h>
#include <string.h>
void f()
{
char buf[80];
memset(buf, 'A', 80);
}
void g()
{
char buf[40];
void (*p)();
printf("p = %p\n", p);
p();
}
int main()
{
f();
g();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment