[asterisk-dev] cdr_odbc.c is broken in trunk
Nick Gorham
nick at lurcher.org
Thu Jan 10 09:48:33 CST 2008
Tilghman Lesher wrote:
>On Thursday 10 January 2008 08:06:20 Nick Gorham wrote:
>
>
>>Michiel van Baak wrote:
>>
>>
>>>On 11:18, Thu 10 Jan 08, Nick Gorham wrote:
>>>
>>>
>>>>Hi,
>>>>
>>>>The change to use prepare_cb() in odbc_log became broken in r88182.
>>>>
>>>>The code calls SQLBindParameter on a local variable (timestr) but as it
>>>>now doesn't call SQLExecute in the same function when it finally gets to
>>>>SQLExecute that variable is out of scope.
>>>>
>>>>
>
>Out of scope, perhaps, but not out of memory. It's stored on the local stack,
>which is not deallocated until after the function returns. The address thus
>remains valid.
>
>
Using what I think you are suggesting is good coding, the following
shows, that how the memory can be overwritten.
#include <stdio.h>
char *saved_ptr;
void do_something_else( void )
{
char another_big_buffer[ 1024 ]; /* this time its there to ensure
we know ehere we are writing
* instead of just
some random location
*/
char other_txt[ 20 ];
strcpy( other_txt, "BANG!!!!" );
}
void set_the_memory( void )
{
char big_buffer[ 1024 ]; /* only there to make sure that the
printf in the
* calling code doesn't itself overrite
the buffer
*/
char txt[ 20 ];
strcpy( txt, "hello world" );
saved_ptr = txt;
}
void expect_the_memory_to_remain( void )
{
printf( "the memory contains '%s'\n", saved_ptr );
}
main()
{
set_the_memory();
do_something_else();
expect_the_memory_to_remain();
}
--
Nick Gorham
More information about the asterisk-dev
mailing list