Merge branch 'fix-fixed-size-asserts' into 'master'

Fix bounds check of struct members of fixed size

See merge request alexl/variant-schema-compiler!8
This commit is contained in:
Alexander Larsson
2020-08-13 08:16:01 +00:00
2 changed files with 8 additions and 2 deletions

View File

@@ -25,6 +25,12 @@ handle (char *filename)
g_autofree char *s = ot_tree_meta_print (tree, TRUE);
g_print ("%s: %s\n", filename, s);
}
else if (g_str_has_suffix (filename, ".dirmeta"))
{
OtDirMetaRef dir = ot_dir_meta_from_data (contents, size);
g_autofree char *s = ot_dir_meta_print (dir, TRUE);
g_print ("%s: %s\n", filename, s);
}
else if (g_str_has_suffix (filename, "summary"))
{
OtSummaryRef summary = ot_summary_from_data (contents, size);

View File

@@ -1434,7 +1434,7 @@ class Field:
if self.type.is_basic():
if self.type.is_fixed():
if not self.struct.is_fixed():
C(" g_assert (offset + {fixed_size} < v.size);");
C(" g_assert (offset + {fixed_size} <= v.size);");
val = genC("({ctype})G_STRUCT_MEMBER({readctype}, v.base, offset)")
if "bigendian" in self.attributes:
val = "%s_FROM_BE(%s)" % (self.type.get_ctype().upper(), val)
@@ -1457,7 +1457,7 @@ class Field:
else:
if self.type.is_fixed():
if not self.struct.is_fixed():
C(" g_assert (offset + {fixed_size} < v.size);");
C(" g_assert (offset + {fixed_size} <= v.size);");
C(" return ({TypeNameRef}) {{ G_STRUCT_MEMBER_P(v.base, offset), {fixed_size} }};")
else:
C(" gsize start = offset;");