* BUG: Fix a possible memory corruption in blob management.


git-svn-id: svn://localhost/gambas/trunk@5739 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2013-07-19 18:12:19 +00:00
parent e9dd24404c
commit 588cc035be

View file

@ -809,6 +809,27 @@ GB_DESC CResultDesc[] =
/** Blob *******************************************************************/
static bool _convert_blob(CBLOB *_object, GB_TYPE type, GB_VALUE *conv)
{
if (BLOB)
{
switch (type)
{
case GB_T_STRING:
case GB_T_CSTRING:
conv->_string.value.addr = BLOB->data;
conv->_string.value.start = 0;
conv->_string.value.len = BLOB->length;
return FALSE;
default:
return TRUE;
}
}
else
return TRUE;
}
/*static int check_blob(CBLOB *_object)
{
return check_result(BLOB->result) || (BLOB->result->pos != BLOB->pos);
@ -827,9 +848,13 @@ static CBLOB *make_blob(CRESULT *result, int field)
//BLOB->pos = result->pos;
BLOB->data = NULL;
BLOB->length = 0;
BLOB->constant = TRUE;
if (result->handle && result->pos >= 0)
{
result->driver->Result.Blob(result->handle, result->pos, field, BLOB);
set_blob(BLOB, BLOB->data, BLOB->length);
}
//fprintf(stderr, "make_blob: [%d] %d (%d) -> %p\n", result->pos, field, BLOB->length, BLOB);
@ -841,12 +866,12 @@ static void set_blob(CBLOB *_object, char *data, int length)
{
//fprintf(stderr, "set_blob: %p %ld\n", BLOB, length);
if (!BLOB->constant)
if (!BLOB->constant && BLOB->data)
GB.FreeString((char **)&BLOB->data);
if (data && length)
{
*((char **)&BLOB->data) = GB.NewString(data, length);
BLOB->data = GB.NewString(data, length);
BLOB->constant = FALSE;
}
@ -907,6 +932,7 @@ GB_DESC CBlobDesc[] =
//GB_PROPERTY_READ("Result", "Result", CBLOB_result),
GB_PROPERTY("Data", "s", CBLOB_data),
GB_PROPERTY_READ("Length", "i", CBLOB_length),
GB_INTERFACE("_convert", &_convert_blob),
//GB_METHOD("_unknown", "v", CBLOB_unknown, "v"),
GB_END_DECLARE