Skip to content

Commit

Permalink
writer: fix a type conversion error
Browse files Browse the repository at this point in the history
Problem: The code converts 32-bit unsigned int
into a 64-bit integer for Jasson packing.
As a result, it reads 4 more random bytes around
the "needs" variable.
Depending on the memory layout, this nondeterministically
writes out a completely incorrect integer value
for the size field of a resource vertex.

Add an explict type casting so that the compiler
promotes 32-bit integer into 64-bit integer
before it is being read by Jansson.
  • Loading branch information
dongahn committed Jun 5, 2020
1 parent 95f40bf commit c138cf7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion resource/writers/match_writers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ json_t *jgf_match_writers_t::emit_vtx_base (const f_resource_graph_t &g,
"rank", g[u].rank,
"exclusive", (exclusive)? 1 : 0,
"unit", g[u].unit.c_str (),
"size", needs))) {
"size", static_cast<int64_t> (needs)))) {
errno = ENOMEM;
}
return o;
Expand Down

0 comments on commit c138cf7

Please sign in to comment.