Re: Problem with szone_free and corrupted free memory block
- From: Gilles Kohl <gilles_delete_this@xxxxxxxxxxxxxx>
- Date: Fri, 22 May 2009 00:49:23 +0200
On Thu, 21 May 2009 13:36:16 -0700 (PDT), Lothar Behrens
<lothar.behrens@xxxxxxxxxxxx> wrote:
Hi,
I wonder about an error that I do not got on my Windows platform, but
I got it on Mac OS X (10.5.2/PPC).
The following code is used several times to rewrite database ALTER
TABLE rules to triggers and it crashed at the end of the code:
[...]
Now I have solved the problem by finding a discrepancy in variables
used in strlen calls to malloc and the sprintf function.
That solved it still crashed. The next thing I tried was to add an
extra size different to 1 (100). Then it worked.
Is there something wrong in that code (except the missing checks of
strings be NULL before passing to strlen)?
If my count is correct, you've got 11 %s placeholders in your
template, but only 10 corresponding char * in your call to sprintf:
table->name,fk->col,table->name,fk->fcol,fk->ftab,fk->fcol,fk->col,fk->col,fk->ftab,fk->fcol
That means that depending on what is on the stack at the time sprintf
is called, you will or won't get a memory overwrite or access
violation.
I guess the way you are currently doing this is just too error-prone -
my suggestion would be to drop the sprintf style altogether, and move
to something with readable placeholders, e.g.
CREATE TRIGGER \"fk_{Table}_{Column}_ins\" BEFORE INSERT ON {Table}
(etc., you get the idea)
You'll need to create your own "ReplaceTemplateParameters"
function (and be careful with computing memory requirements), but this
will have several advantages:
- readable templates
- ability to change template without changing code
- ability to read template from file or resource
- ability to harden code against SQL injection
Regards,
Gilles.
.
- References:
- Problem with szone_free and corrupted free memory block
- From: Lothar Behrens
- Problem with szone_free and corrupted free memory block
- Prev by Date: Problem with szone_free and corrupted free memory block
- Next by Date: Google Icon Vase Speaker - Black
- Previous by thread: Problem with szone_free and corrupted free memory block
- Next by thread: Google Icon Vase Speaker - Black
- Index(es):
Relevant Pages
|