#include "Eet.h"
#include "Eet_private.h"
-#ifdef _WIN32
-# define FMT_CHAR "%c"
-# define FMT_UCHAR "%c"
-# define FMT_LONG_LONG "%I64i"
-# define FMT_ULONG_LONG "%I64u"
-#else
-# define FMT_CHAR "%hhi"
-# define FMT_UCHAR "%hhu"
-# define FMT_LONG_LONG "%lli"
-# define FMT_ULONG_LONG "%llu"
-#endif
-
/*
* routines for doing data -> struct and struct -> data conversion
*
Eet_Data_Element *ede;
Eet_Data_Element *tmp;
+ /* Sanity check to avoid crash later at runtime */
+ if (type < EET_T_UNKNOW ||
+ type >= EET_T_LAST)
+ {
+ CRIT("Preventing later bug due to unknow type: %i", type);
+ return ;
+ }
+ if (offset < 0)
+ {
+ CRIT("Preventing later buffer underrun : offset = %i", offset);
+ return ;
+ }
+ if (offset > edd->size)
+ {
+ CRIT("Preventing later buffer overrun : offset = %i in a structure of %i bytes", offset, edd->size);
+ return ;
+ }
+ if (group_type == EET_G_UNKNOWN && type != EET_T_UNKNOW)
+ {
+ if (offset + eet_basic_codec[type - 1].size > edd->size)
+ {
+ CRIT("Preventing later buffer overrun : offset = %i, size = %i in a structure of %i bytes", offset, eet_basic_codec[type - 1].size, edd->size);
+ return ;
+ }
+ }
+ else if ((offset + sizeof (void*)) > (unsigned int) edd->size)
+ {
+ CRIT("Preventing later buffer overrun : offset = %i, estimated size = %i in a structure of %i bytes", offset, sizeof (void*), edd->size);
+ return ;
+ }
+
/* UNION, VARIANT type would not work with simple type, we need a way to map the type. */
if ((group_type == EET_G_UNION
|| group_type == EET_G_VARIANT)
const char *name,
const char *cipher_key,
const void *data,
- int compress)
+ int comp)
{
Eet_Dictionary *ed;
void *data_enc;
if (!data_enc)
return 0;
- val = eet_write_cipher(ef, name, data_enc, size, compress, cipher_key);
+ val = eet_write_cipher(ef, name, data_enc, size, comp, cipher_key);
free(data_enc);
return val;
}
Eet_Data_Descriptor *edd,
const char *name,
const void *data,
- int compress)
+ int comp)
{
- return eet_data_write_cipher(ef, edd, name, NULL, data, compress);
+ return eet_data_write_cipher(ef, edd, name, NULL, data, comp);
}
static void
if (!strcmp(tok3, "char:"))
{
n->type = EET_T_CHAR;
- sscanf(tok4, FMT_CHAR,
+ sscanf(tok4, "%hhi",
&(n->data.value.c));
}
else if (!strcmp(tok3, "short:"))
else if (!strcmp(tok3, "long_long:"))
{
n->type = EET_T_LONG_LONG;
- sscanf(tok4, FMT_LONG_LONG,
+ sscanf(tok4, "%lli",
&(n->data.value.l));
}
else if (!strcmp(tok3, "float:"))
else if (!strcmp(tok3, "uchar:"))
{
n->type = EET_T_UCHAR;
- sscanf(tok4, FMT_UCHAR,
+ sscanf(tok4, "%hhu",
&(n->data.value.uc));
}
else if (!strcmp(tok3, "ushort:"))
else if (!strcmp(tok3, "ulong_long:"))
{
n->type = EET_T_ULONG_LONG;
- sscanf(tok4, FMT_ULONG_LONG,
+ sscanf(tok4, "%llu",
&(n->data.value.ul));
}
else if (!strcmp(tok3, "string:"))
if (ede)
{
if (IS_POINTER_TYPE(type))
- subsize = eet_basic_codec[ede->type].size;
+ subsize = eet_basic_codec[ede->type - 1].size;
else
subsize = ede->subtype->size;
eet_data_encode(ed, ds, data, ede->name, size, ede->type, ede->group_type);
if (IS_POINTER_TYPE(ede->type))
- subsize = eet_basic_codec[ede->type].size;
+ subsize = eet_basic_codec[ede->type - 1].size;
else
subsize = ede->subtype->size;
const char *cipher_key,
const char *text,
int textlen,
- int compress)
+ int comp)
{
Eet_Dictionary *ed;
void *data_enc;
if (!data_enc)
return 0;
- val = eet_write_cipher(ef, name, data_enc, size, compress, cipher_key);
+ val = eet_write_cipher(ef, name, data_enc, size, comp, cipher_key);
free(data_enc);
return val;
}
const char *name,
const char *text,
int textlen,
- int compress)
+ int comp)
{
- return eet_data_undump_cipher(ef, name, NULL, text, textlen, compress);
+ return eet_data_undump_cipher(ef, name, NULL, text, textlen, comp);
}
EAPI void *
const char *name,
const char *cipher_key,
Eet_Node *node,
- int compress)
+ int comp)
{
Eet_Dictionary *ed;
void *data_enc;
if (!data_enc)
return 0;
- val = eet_write_cipher(ef, name, data_enc, size, compress, cipher_key);
+ val = eet_write_cipher(ef, name, data_enc, size, comp, cipher_key);
free(data_enc);
return val;
}
return ret;
}
-