Package Upload
[framework/uifw/eet.git] / src / lib / eet_data.c
index 56b9ee0..bd6bbd9 100644 (file)
 #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
  *
@@ -1958,6 +1946,37 @@ eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
    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)
@@ -2126,7 +2145,7 @@ eet_data_write_cipher(Eet_File            *ef,
                       const char          *name,
                       const char          *cipher_key,
                       const void          *data,
-                      int                  compress)
+                      int                  comp)
 {
    Eet_Dictionary *ed;
    void *data_enc;
@@ -2139,7 +2158,7 @@ eet_data_write_cipher(Eet_File            *ef,
    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;
 }
@@ -2149,9 +2168,9 @@ eet_data_write(Eet_File            *ef,
                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
@@ -3108,7 +3127,7 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
                                             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:"))
@@ -3126,7 +3145,7 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
                                             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:"))
@@ -3144,7 +3163,7 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
                                             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:"))
@@ -3162,7 +3181,7 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
                                             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:"))
@@ -3679,7 +3698,7 @@ eet_data_get_array(Eet_Free_Context     *context,
    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;
 
@@ -4398,7 +4417,7 @@ eet_data_put_array(Eet_Dictionary      *ed,
      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;
 
@@ -4682,7 +4701,7 @@ eet_data_undump_cipher(Eet_File   *ef,
                        const char *cipher_key,
                        const char *text,
                        int         textlen,
-                       int         compress)
+                       int         comp)
 {
    Eet_Dictionary *ed;
    void *data_enc;
@@ -4695,7 +4714,7 @@ eet_data_undump_cipher(Eet_File   *ef,
    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;
 }
@@ -4705,9 +4724,9 @@ eet_data_undump(Eet_File   *ef,
                 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 *
@@ -4856,7 +4875,7 @@ eet_data_node_write_cipher(Eet_File   *ef,
                            const char *name,
                            const char *cipher_key,
                            Eet_Node   *node,
-                           int         compress)
+                           int         comp)
 {
    Eet_Dictionary *ed;
    void *data_enc;
@@ -4869,7 +4888,7 @@ eet_data_node_write_cipher(Eet_File   *ef,
    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;
 }
@@ -4996,4 +5015,3 @@ eet_data_xattr_cipher_set(const char          *filename,
 
    return ret;
 }
-