<s>
Dangling	B-Error_Name
pointers	I-Error_Name
and	O
wild	B-Error_Name
pointers	I-Error_Name
in	O
computer	B-General_Concept
programming	I-General_Concept
are	O
pointers	O
that	O
do	O
not	O
point	O
to	O
a	O
valid	O
object	O
of	O
the	O
appropriate	O
type	O
.	O
</s>
<s>
These	O
are	O
special	O
cases	O
of	O
memory	B-Application
safety	I-Application
violations	O
.	O
</s>
<s>
More	O
generally	O
,	O
dangling	B-Error_Name
references	I-Error_Name
and	O
wild	B-Error_Name
references	I-Error_Name
are	O
references	O
that	O
do	O
not	O
resolve	O
to	O
a	O
valid	O
destination	O
.	O
</s>
<s>
Dangling	B-Error_Name
pointers	I-Error_Name
arise	O
during	O
object	O
destruction	O
,	O
when	O
an	O
object	O
that	O
has	O
an	O
incoming	O
reference	O
is	O
deleted	O
or	O
deallocated	O
,	O
without	O
modifying	O
the	O
value	O
of	O
the	O
pointer	O
,	O
so	O
that	O
the	O
pointer	O
still	O
points	O
to	O
the	O
memory	O
location	O
of	O
the	O
deallocated	O
memory	O
.	O
</s>
<s>
The	O
system	O
may	O
reallocate	O
the	O
previously	O
freed	O
memory	O
,	O
and	O
if	O
the	O
program	O
then	O
dereferences	O
the	O
(	O
now	O
)	O
dangling	B-Error_Name
pointer	I-Error_Name
,	O
unpredictable	B-Language
behavior	I-Language
may	O
result	O
,	O
as	O
the	O
memory	O
may	O
now	O
contain	O
completely	O
different	O
data	O
.	O
</s>
<s>
If	O
the	O
program	O
writes	O
to	O
memory	O
referenced	O
by	O
a	O
dangling	B-Error_Name
pointer	I-Error_Name
,	O
a	O
silent	O
corruption	O
of	O
unrelated	O
data	O
may	O
result	O
,	O
leading	O
to	O
subtle	O
bugs	B-Error_Name
that	O
can	O
be	O
extremely	O
difficult	O
to	O
find	O
.	O
</s>
<s>
If	O
the	O
memory	O
has	O
been	O
reallocated	O
to	O
another	O
process	O
,	O
then	O
attempting	O
to	O
dereference	O
the	O
dangling	B-Error_Name
pointer	I-Error_Name
can	O
cause	O
segmentation	B-Error_Name
faults	I-Error_Name
(	O
UNIX	O
,	O
Linux	O
)	O
or	O
general	B-Operating_System
protection	I-Operating_System
faults	I-Operating_System
(	O
Windows	O
)	O
.	O
</s>
<s>
In	O
object-oriented	B-Language
languages	I-Language
with	O
garbage	B-General_Concept
collection	I-General_Concept
,	O
dangling	B-Error_Name
references	I-Error_Name
are	O
prevented	O
by	O
only	O
destroying	O
objects	O
that	O
are	O
unreachable	O
,	O
meaning	O
they	O
do	O
not	O
have	O
any	O
incoming	O
pointers	O
;	O
this	O
is	O
ensured	O
either	O
by	O
tracing	O
or	O
reference	B-General_Concept
counting	I-General_Concept
.	O
</s>
<s>
However	O
,	O
a	O
finalizer	B-Application
may	O
create	O
new	O
references	O
to	O
an	O
object	O
,	O
requiring	O
object	B-General_Concept
resurrection	I-General_Concept
to	O
prevent	O
a	O
dangling	B-Error_Name
reference	I-Error_Name
.	O
</s>
<s>
Wild	B-Error_Name
pointers	I-Error_Name
arise	O
when	O
a	O
pointer	O
is	O
used	O
prior	O
to	O
initialization	O
to	O
some	O
known	O
state	O
,	O
which	O
is	O
possible	O
in	O
some	O
programming	O
languages	O
.	O
</s>
<s>
They	O
show	O
the	O
same	O
erratic	O
behavior	O
as	O
dangling	B-Error_Name
pointers	I-Error_Name
,	O
though	O
they	O
are	O
less	O
likely	O
to	O
stay	O
undetected	O
because	O
many	O
compilers	O
will	O
raise	O
a	O
warning	O
at	O
compile	O
time	O
if	O
declared	O
variables	O
are	O
accessed	O
before	O
being	O
initialized	O
.	O
</s>
<s>
In	O
many	O
languages	O
(	O
e.g.	O
,	O
the	O
C	B-Language
programming	I-Language
language	I-Language
)	O
deleting	O
an	O
object	O
from	O
memory	O
explicitly	O
or	O
by	O
destroying	O
the	O
stack	O
frame	O
on	O
return	O
does	O
not	O
alter	O
associated	O
pointers	O
.	O
</s>
<s>
Another	O
frequent	O
source	O
of	O
dangling	B-Error_Name
pointers	I-Error_Name
is	O
a	O
jumbled	O
combination	O
of	O
malloc( )	O
and	O
free( )	O
library	O
calls	O
:	O
a	O
pointer	O
becomes	O
dangling	O
when	O
the	O
block	O
of	O
memory	O
it	O
points	O
to	O
is	O
freed	O
.	O
</s>
<s>
If	O
a	O
pointer	O
to	O
num	O
must	O
be	O
returned	O
,	O
num	O
must	O
have	O
scope	O
beyond	O
the	O
function	O
—	O
it	O
might	O
be	O
declared	O
as	O
static	B-General_Concept
.	O
</s>
<s>
(	O
1945-1996	O
)	O
has	O
created	O
a	O
complete	O
object	O
management	O
system	O
which	O
is	O
free	O
of	O
dangling	B-Error_Name
reference	I-Error_Name
phenomenon	O
.	O
</s>
<s>
A	O
similar	O
approach	O
was	O
proposed	O
by	O
Fisher	O
and	O
LeBlanc	O
under	O
the	O
name	O
Locks-and-keys	B-Language
.	O
</s>
<s>
Wild	B-Error_Name
pointers	I-Error_Name
are	O
created	O
by	O
omitting	O
necessary	O
initialization	O
prior	O
to	O
first	O
use	O
.	O
</s>
<s>
Thus	O
,	O
strictly	O
speaking	O
,	O
every	O
pointer	O
in	O
programming	O
languages	O
which	O
do	O
not	O
enforce	O
initialization	O
begins	O
as	O
a	O
wild	B-Error_Name
pointer	I-Error_Name
.	O
</s>
<s>
Like	O
buffer-overflow	B-General_Concept
bugs	B-Error_Name
,	O
dangling/wild	O
pointer	O
bugs	B-Error_Name
frequently	O
become	O
security	O
holes	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
the	O
pointer	O
is	O
used	O
to	O
make	O
a	O
virtual	B-Application
function	I-Application
call	O
,	O
a	O
different	O
address	O
(	O
possibly	O
pointing	O
at	O
exploit	O
code	O
)	O
may	O
be	O
called	O
due	O
to	O
the	O
vtable	B-Language
pointer	O
being	O
overwritten	O
.	O
</s>
<s>
When	O
a	O
dangling	B-Error_Name
pointer	I-Error_Name
is	O
used	O
after	O
it	O
has	O
been	O
freed	O
without	O
allocating	O
a	O
new	O
chunk	O
of	O
memory	O
to	O
it	O
,	O
this	O
becomes	O
known	O
as	O
a	O
"	O
use	B-Error_Name
after	I-Error_Name
free	I-Error_Name
"	O
vulnerability	O
.	O
</s>
<s>
For	O
example	O
,	O
is	O
a	O
use-after-free	B-Error_Name
vulnerability	O
in	O
Microsoft	O
Internet	O
Explorer	O
6	O
through	O
11	O
being	O
used	O
by	O
zero-day	O
attacks	O
by	O
an	O
advanced	O
persistent	O
threat	O
.	O
</s>
<s>
In	O
C	B-Language
,	O
the	O
simplest	O
technique	O
is	O
to	O
implement	O
an	O
alternative	O
version	O
of	O
the	O
free( )	O
(	O
or	O
alike	O
)	O
function	O
which	O
guarantees	O
the	O
reset	O
of	O
the	O
pointer	O
.	O
</s>
<s>
Among	O
more	O
structured	O
solutions	O
,	O
a	O
popular	O
technique	O
to	O
avoid	O
dangling	B-Error_Name
pointers	I-Error_Name
in	O
C++	B-Language
is	O
to	O
use	O
smart	B-Language
pointers	I-Language
.	O
</s>
<s>
A	O
smart	B-Language
pointer	I-Language
typically	O
uses	O
reference	B-General_Concept
counting	I-General_Concept
to	O
reclaim	O
objects	O
.	O
</s>
<s>
Some	O
other	O
techniques	O
include	O
the	O
tombstones	B-Language
method	O
and	O
the	O
locks-and-keys	B-Language
method	O
.	O
</s>
<s>
Another	O
approach	O
is	O
to	O
use	O
the	O
Boehm	B-Language
garbage	I-Language
collector	I-Language
,	O
a	O
conservative	O
garbage	B-General_Concept
collector	I-General_Concept
that	O
replaces	O
standard	O
memory	O
allocation	O
functions	O
in	O
C	B-Language
and	O
C++	B-Language
with	O
a	O
garbage	B-General_Concept
collector	I-General_Concept
.	O
</s>
<s>
This	O
approach	O
completely	O
eliminates	O
dangling	B-Error_Name
pointer	I-Error_Name
errors	O
by	O
disabling	O
frees	O
,	O
and	O
reclaiming	O
objects	O
by	O
garbage	B-General_Concept
collection	I-General_Concept
.	O
</s>
<s>
In	O
languages	O
like	O
Java	O
,	O
dangling	B-Error_Name
pointers	I-Error_Name
cannot	O
occur	O
because	O
there	O
is	O
no	O
mechanism	O
to	O
explicitly	O
deallocate	O
memory	O
.	O
</s>
<s>
Rather	O
,	O
the	O
garbage	B-General_Concept
collector	I-General_Concept
may	O
deallocate	O
memory	O
,	O
but	O
only	O
when	O
the	O
object	O
is	O
no	O
longer	O
reachable	O
from	O
any	O
references	O
.	O
</s>
<s>
In	O
the	O
language	O
Rust	B-Application
,	O
the	O
type	O
system	O
has	O
been	O
extended	O
to	O
include	O
also	O
the	O
variables	O
lifetimes	O
and	O
resource	B-Application
acquisition	I-Application
is	I-Application
initialization	I-Application
.	O
</s>
<s>
Unless	O
one	O
disables	O
the	O
features	O
of	O
the	O
language	O
,	O
dangling	B-Error_Name
pointers	I-Error_Name
will	O
be	O
caught	O
at	O
compile	O
time	O
and	O
reported	O
as	O
programming	B-Error_Name
errors	I-Error_Name
.	O
</s>
<s>
To	O
expose	O
dangling	B-Error_Name
pointer	I-Error_Name
errors	O
,	O
one	O
common	O
programming	O
technique	O
is	O
to	O
set	O
pointers	O
to	O
the	O
null	O
pointer	O
or	O
to	O
an	O
invalid	O
address	O
once	O
the	O
storage	O
they	O
point	O
to	O
has	O
been	O
released	O
.	O
</s>
<s>
When	O
the	O
null	O
pointer	O
is	O
dereferenced	O
(	O
in	O
most	O
languages	O
)	O
the	O
program	O
will	O
immediately	O
terminate	O
—	O
there	O
is	O
no	O
potential	O
for	O
data	O
corruption	O
or	O
unpredictable	B-Language
behavior	I-Language
.	O
</s>
<s>
Some	O
debuggers	O
will	O
automatically	O
overwrite	O
and	O
destroy	O
data	O
that	O
has	O
been	O
freed	O
,	O
usually	O
with	O
a	O
specific	O
pattern	O
,	O
such	O
as	O
0xDEADBEEF	O
(	O
Microsoft	O
's	O
Visual	O
C/C	O
++	O
debugger	O
,	O
for	O
example	O
,	O
uses	O
0xCC	O
,	O
0xCD	O
or	O
0xDD	O
depending	O
on	O
what	O
has	O
been	O
freed	O
)	O
.	O
</s>
<s>
Tools	O
such	O
as	O
Polyspace	O
,	O
TotalView	O
,	O
Valgrind	B-Application
,	O
Mudflap	O
,	O
AddressSanitizer	B-Application
,	O
or	O
tools	O
based	O
on	O
LLVM	B-Application
can	O
also	O
be	O
used	O
to	O
detect	O
uses	O
of	O
dangling	B-Error_Name
pointers	I-Error_Name
.	O
</s>
<s>
Other	O
tools	O
(	O
,	O
Insure++	B-General_Concept
,	O
and	O
)	O
instrument	O
the	O
source	O
code	O
to	O
collect	O
and	O
track	O
legitimate	O
values	O
for	O
pointers	O
(	O
"	O
metadata	O
"	O
)	O
and	O
check	O
each	O
pointer	O
access	O
against	O
the	O
metadata	O
for	O
validity	O
.	O
</s>
<s>
Another	O
strategy	O
,	O
when	O
suspecting	O
a	O
small	O
set	O
of	O
classes	O
,	O
is	O
to	O
temporarily	O
make	O
all	O
their	O
member	O
functions	O
virtual	B-Application
:	O
after	O
the	O
class	O
instance	O
has	O
been	O
destructed/freed	O
,	O
its	O
pointer	O
to	O
the	O
Virtual	B-Language
Method	I-Language
Table	I-Language
is	O
set	O
to	O
NULL	O
,	O
and	O
any	O
call	O
to	O
a	O
member	O
function	O
will	O
crash	O
the	O
program	O
and	O
it	O
will	O
show	O
the	O
guilty	O
code	O
in	O
the	O
debugger	O
.	O
</s>
