473,396 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

double free

I read a document about c++ programming and memory allocation, and
I came across a new term I've never heard before, double free.
I tried googling for it but I found no explanation, can someone
tell me what it is? Is it a vulnerability that can be exploited by
malicious code?
Apr 27 '06 #1
9 9927
edware wrote:
I read a document about c++ programming and memory allocation, and
I came across a new term I've never heard before, double free.
I tried googling for it but I found no explanation, can someone
tell me what it is? Is it a vulnerability that can be exploited by
malicious code?


I think what is referred here is the situation like the following:

void *p = malloc(100); // get me 100 bytes, just for fun...
free(p); // throw them out, everything's fine
free(p); // AGAIN???? NO-O-O-O-O-O-O-O-O-O (undefined behaviour)

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 27 '06 #2
edware wrote:
I read a document about c++ programming and memory allocation, and
I came across a new term I've never heard before, double free.
I tried googling for it but I found no explanation, can someone
tell me what it is? Is it a vulnerability that can be exploited by
malicious code?


Can you quote the context in the document?

The only guess possible is it means calling free() twice on the same
pointer, which is a no-no.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Apr 27 '06 #3
Phlip wrote:
edware wrote:
I read a document about c++ programming and memory allocation, and
I came across a new term I've never heard before, double free.
I tried googling for it but I found no explanation, can someone
tell me what it is? Is it a vulnerability that can be exploited by
malicious code?


Can you quote the context in the document?

The only guess possible is it means calling free() twice on the same
pointer, which is a no-no.

http://cprogramming.com/tutorial/secure.html
Its under Double Free Attack.

Maybe should have posted to comp.lang.c instead since
its malloc and free, but I didn't think of that
since I was reading the C++ tutorial.
Apr 27 '06 #4
edware wrote:
[..]
Maybe should have posted to comp.lang.c instead since
its malloc and free, but I didn't think of that
since I was reading the C++ tutorial.


It's fine. C Standard Library (at least as defined in the C
Language Standard circa 1990) is part of C++ Standard Library.
You may ask questions about it here as well.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 27 '06 #5
edware wrote:
http://cprogramming.com/tutorial/secure.html
Its under Double Free Attack.

Maybe should have posted to comp.lang.c instead since
its malloc and free, but I didn't think of that
since I was reading the C++ tutorial.


That newsgroup might have more experience with undefined behavior after a
bad free().

In general, the "double free" they describe is simply undefined behavior.
Any undefined behavior could cause anything to happen; anything from the
program appearing to work correctly, to the nearest toilet exploding, to a
program becoming vulnerable to attack.

At the second free(), the heap manager will not notice the block it's
freeing is already free. (That's a serious optimization, because it prevents
the heap manager from walking the entire free list.) The manager will read
and write the variables in the block that indicate its size and status, and
will attempt to join the block with the ones around it.

If a specific program had this bug, an attacker could conceivably submit
program code inside a string (the standard attack route). Then at double
free time the heap manager might jump into this string instead of its own
code.

The C++ fix is a style called RAII. Look that up.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Apr 27 '06 #6
Victor Bazarov wrote:
edware wrote:
[..]
Maybe should have posted to comp.lang.c instead since
its malloc and free, but I didn't think of that
since I was reading the C++ tutorial.


It's fine. C Standard Library (at least as defined in the C
Language Standard circa 1990) is part of C++ Standard Library.
You may ask questions about it here as well.


And you also get the same problems with delete (but then of corurse
called "double deletion").

Apr 27 '06 #7

Victor Bazarov skrev:
edware wrote:
[..]
Maybe should have posted to comp.lang.c instead since
its malloc and free, but I didn't think of that
since I was reading the C++ tutorial.
It's fine. C Standard Library (at least as defined in the C
Language Standard circa 1990) is part of C++ Standard Library.
You may ask questions about it here as well.


I disagree. Questions about code that is C should normally be asked in
comp.lang.c. Still - it is not the greatest of sins. And once asked it
is okay to answer.

/Peter
V


Apr 27 '06 #8
peter koch wrote:
Victor Bazarov skrev:
edware wrote:
[..]
Maybe should have posted to comp.lang.c instead since
its malloc and free, but I didn't think of that
since I was reading the C++ tutorial.
It's fine. C Standard Library (at least as defined in the C
Language Standard circa 1990) is part of C++ Standard Library.
You may ask questions about it here as well.


I disagree. Questions about code that is C


Who can tell that the code is C if it's in a C++ tutorial? Can you
tell whether

int main(void) { return 0; }

is C or C++? And what do you disagree with, actually?
should normally be asked in
comp.lang.c. Still - it is not the greatest of sins. And once asked it
is okay to answer.


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 27 '06 #9
peter koch wrote:
I disagree. Questions about code that is C should normally be asked in
comp.lang.c. Still - it is not the greatest of sins. And once asked it
is okay to answer.


I don't know if anyone has pointed this out recently, but the most useful
recourse here is enlightened self-interest.

If a poster will get a better answer on another newsgroup, even if an
Authority says their question is On Topic here, bounce them. It's for their
own good.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Apr 27 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: weaselboy1976 | last post by:
Hello Does anyone know of a good website that actually describes and demonstrates WHY freeing a pointer more than once is a problem. I'm specifically interested in what the ill effects are. ...
17
by: kj | last post by:
How can one test if a pointer has been "freed" (i.e. with free())? My naive assumption was that such a pointer would equal NULL, but not so. Thanks, kj -- NOTE: In my address everything...
7
by: slashdotcommacolon | last post by:
Hello, I'm working on the exercises from k&r, exercise 5-13 is to implement a simple replacement for the unix tail command. The brief says it should be able to cope no matter how unreasonable the...
8
by: Rakesh | last post by:
Hi - What is wrong this implementation? I get a core dump at the free() statement? Thanks Rakesh #include <ext/hash_map> #include <iostream.h> #include <ext/hash_set>
76
by: dbansal | last post by:
Hi group, I have a question to ask you all. I have allocated some chunk of memory using ptr=(int*)malloc(). now I am trying to free that memory using free((void*)ptr). My question is does free()...
5
by: sriramsreenivasan | last post by:
I am a beginner in c i have written a linked list program and it shows a error after two successions please help me to find the error and to solveit #include<stdio.h> #include<stdlib.h>...
4
by: loudking | last post by:
Hi, all Here is part of my code. ======================================== void *record; /* treat record */ if (record) {
3
by: dreiko466 | last post by:
(sorry about my english...) I am a newbie in C (3 month expierience) I have wrote a simple test programm in VS2005, what i do wrong?Please... In this programm i create a double linked list.Then ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.