mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Zero-initialize bool-typed coro local variables
Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=6470
This commit is contained in:
1 parent
fbdc648b1a
commit
11ad47af86
5 files changed
+57
-7
No files matched your search
@@ -229,7 +229,11 @@ func (g *gen) writeFuncImplBodyResume(b *buffer) error {
|
||||
b.printf("uint32_t coro_susp_point = self->private_impl.%s%s[0].coro_susp_point;\n",
|
||||
cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
b.printf("if (coro_susp_point) {\n")
|
||||
if err := g.writeResumeSuspend(b, g.currFunk.astFunc.Body(), false); err != nil {
|
||||
if err := g.writeResumeSuspend(b, g.currFunk.astFunc.Body(), false, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes("} else {\n")
|
||||
if err := g.writeResumeSuspend(b, g.currFunk.astFunc.Body(), false, true); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes("}\n")
|
||||
@@ -267,7 +271,7 @@ func (g *gen) writeFuncImplBodySuspend(b *buffer) error {
|
||||
|
||||
b.printf("self->private_impl.%s%s[0].coro_susp_point = coro_susp_point;\n",
|
||||
cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
if err := g.writeResumeSuspend(b, g.currFunk.astFunc.Body(), true); err != nil {
|
||||
if err := g.writeResumeSuspend(b, g.currFunk.astFunc.Body(), true, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes("\n")
|
||||
|
||||
@@ -296,11 +296,11 @@ func (g *gen) visitVars(b *buffer, block []*a.Node, depth uint32, f func(*gen, *
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool) error {
|
||||
func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool, initBoolTypedVars bool) error {
|
||||
local := fmt.Sprintf("%s%s", vPrefix, n.Name().Str(g.tm))
|
||||
|
||||
if typ := n.XType(); typ.HasPointers() {
|
||||
if suspend {
|
||||
if suspend || initBoolTypedVars {
|
||||
return nil
|
||||
}
|
||||
rhs := ""
|
||||
@@ -323,8 +323,35 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool) error {
|
||||
|
||||
} else {
|
||||
lhs := local
|
||||
rhs := ""
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
rhs := fmt.Sprintf("self->private_impl.%s%s[0].%s", cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm), lhs)
|
||||
if !initBoolTypedVars {
|
||||
rhs = fmt.Sprintf("self->private_impl.%s%s[0].%s", cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm), lhs)
|
||||
} else if typ.QID() != (t.QID{0, t.IDBool}) {
|
||||
return nil
|
||||
} else if typ.Decorator() != 0 {
|
||||
goto fail
|
||||
} else {
|
||||
// Explicitly initialize the bool-typed local variable to false.
|
||||
//
|
||||
// Otherwise, the variable (in C) can hold an uninitialized value.
|
||||
// In terms of registers and memory (which work in integers, not
|
||||
// bools), that uninitialized value could be something like 255,
|
||||
// not 0 or 1.
|
||||
//
|
||||
// In the Wuffs language, a variable "foo" cannot be used before
|
||||
// initialization, but that's not easily seen by running C language
|
||||
// tools on Wuffs' generated C code. In C, that uninitialized v_foo
|
||||
// local variable could be suspended to and then resumed from the
|
||||
// f_foo coroutine state.
|
||||
//
|
||||
// This generated code explicitly initializes bool typed variables,
|
||||
// in order to avoid ubsan (undefined behavior sanitizer) warnings.
|
||||
//
|
||||
// In general, we don't zero-initialize all of the v_etc local
|
||||
// variables due to the negative performance impact.
|
||||
rhs = "false"
|
||||
}
|
||||
if suspend {
|
||||
lhs, rhs = rhs, lhs
|
||||
}
|
||||
@@ -350,13 +377,14 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool) error {
|
||||
}
|
||||
}
|
||||
|
||||
fail:
|
||||
return fmt.Errorf("cannot resume or suspend a local variable %q of type %q",
|
||||
n.Name().Str(g.tm), n.XType().Str(g.tm))
|
||||
}
|
||||
|
||||
func (g *gen) writeResumeSuspend(b *buffer, block []*a.Node, suspend bool) error {
|
||||
func (g *gen) writeResumeSuspend(b *buffer, block []*a.Node, suspend bool, initBoolTypedVars bool) error {
|
||||
return g.visitVars(b, block, 0, func(g *gen, b *buffer, n *a.Var) error {
|
||||
return g.writeResumeSuspend1(b, n, suspend)
|
||||
return g.writeResumeSuspend1(b, n, suspend, initBoolTypedVars)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -914,6 +914,7 @@ wuffs_deflate__status wuffs_deflate__decoder__decode(
|
||||
v_written = ((wuffs_base__slice_u8){});
|
||||
v_n_copied = self->private_impl.c_decode[0].v_n_copied;
|
||||
v_already_full = self->private_impl.c_decode[0].v_already_full;
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -1051,6 +1052,7 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_blocks(
|
||||
if (coro_susp_point) {
|
||||
v_final = self->private_impl.c_decode_blocks[0].v_final;
|
||||
v_type = self->private_impl.c_decode_blocks[0].v_type;
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -1257,6 +1259,7 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_uncompressed(
|
||||
if (coro_susp_point) {
|
||||
v_length = self->private_impl.c_decode_uncompressed[0].v_length;
|
||||
v_n_copied = self->private_impl.c_decode_uncompressed[0].v_n_copied;
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -1381,6 +1384,7 @@ static wuffs_deflate__status wuffs_deflate__decoder__init_fixed_huffman(
|
||||
self->private_impl.c_init_fixed_huffman[0].coro_susp_point;
|
||||
if (coro_susp_point) {
|
||||
v_i = self->private_impl.c_init_fixed_huffman[0].v_i;
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -1483,6 +1487,7 @@ static wuffs_deflate__status wuffs_deflate__decoder__init_dynamic_huffman(
|
||||
self->private_impl.c_init_dynamic_huffman[0].v_n_extra_bits;
|
||||
v_rep_symbol = self->private_impl.c_init_dynamic_huffman[0].v_rep_symbol;
|
||||
v_rep_count = self->private_impl.c_init_dynamic_huffman[0].v_rep_count;
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -2432,6 +2437,7 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_n_copied = self->private_impl.c_decode_huffman_slow[0].v_n_copied;
|
||||
v_hlen = self->private_impl.c_decode_huffman_slow[0].v_hlen;
|
||||
v_hdist = self->private_impl.c_decode_huffman_slow[0].v_hdist;
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
@@ -906,6 +906,7 @@ wuffs_gif__status wuffs_gif__decoder__decode_config(
|
||||
uint32_t coro_susp_point =
|
||||
self->private_impl.c_decode_config[0].coro_susp_point;
|
||||
if (coro_susp_point) {
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -1057,6 +1058,7 @@ wuffs_gif__status wuffs_gif__decoder__decode_frame(wuffs_gif__decoder* self,
|
||||
uint32_t coro_susp_point =
|
||||
self->private_impl.c_decode_frame[0].coro_susp_point;
|
||||
if (coro_susp_point) {
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -1196,6 +1198,7 @@ static wuffs_gif__status wuffs_gif__decoder__decode_header(
|
||||
if (coro_susp_point) {
|
||||
memcpy(v_c, self->private_impl.c_decode_header[0].v_c, sizeof(v_c));
|
||||
v_i = self->private_impl.c_decode_header[0].v_i;
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -1286,6 +1289,7 @@ static wuffs_gif__status wuffs_gif__decoder__decode_lsd(
|
||||
memcpy(v_c, self->private_impl.c_decode_lsd[0].v_c, sizeof(v_c));
|
||||
v_i = self->private_impl.c_decode_lsd[0].v_i;
|
||||
v_gct_size = self->private_impl.c_decode_lsd[0].v_gct_size;
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -1406,6 +1410,7 @@ static wuffs_gif__status wuffs_gif__decoder__decode_extension(
|
||||
self->private_impl.c_decode_extension[0].coro_susp_point;
|
||||
if (coro_susp_point) {
|
||||
v_label = self->private_impl.c_decode_extension[0].v_label;
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -1523,6 +1528,7 @@ static wuffs_gif__status wuffs_gif__decoder__skip_blocks(
|
||||
self->private_impl.c_skip_blocks[0].coro_susp_point;
|
||||
if (coro_susp_point) {
|
||||
v_block_size = self->private_impl.c_skip_blocks[0].v_block_size;
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -1620,6 +1626,9 @@ static wuffs_gif__status wuffs_gif__decoder__decode_ae(
|
||||
v_block_size = self->private_impl.c_decode_ae[0].v_block_size;
|
||||
v_not_animexts = self->private_impl.c_decode_ae[0].v_not_animexts;
|
||||
v_not_netscape = self->private_impl.c_decode_ae[0].v_not_netscape;
|
||||
} else {
|
||||
v_not_animexts = false;
|
||||
v_not_netscape = false;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -1848,6 +1857,7 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id(
|
||||
v_block_size = self->private_impl.c_decode_id[0].v_block_size;
|
||||
v_r = ((wuffs_base__reader1){});
|
||||
v_z = self->private_impl.c_decode_id[0].v_z;
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -2202,6 +2212,7 @@ static wuffs_gif__status wuffs_gif__lzw_decoder__decode(
|
||||
v_c = self->private_impl.c_decode[0].v_c;
|
||||
v_expansion = ((wuffs_base__slice_u8){});
|
||||
v_n_copied = self->private_impl.c_decode[0].v_n_copied;
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
@@ -1013,6 +1013,7 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
|
||||
v_x = self->private_impl.c_decode[0].v_x;
|
||||
v_checksum = self->private_impl.c_decode[0].v_checksum;
|
||||
v_z = self->private_impl.c_decode[0].v_z;
|
||||
} else {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
Reference in new issue
Block a user