Skip to content

Commit

Permalink
Fix incorrect pointer reference in marshal_signalmap_out().
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Rule (VM/EMT3) <[email protected]>
  • Loading branch information
timrulebosch committed Nov 7, 2024
1 parent daa117f commit 5b2a3f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dse/clib/data/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,10 @@ void marshal_signalmap_out(MarshalSignalMap* map)
src_binary[src_idx] = NULL;
}
src_binary_len[src_idx] = 0;
if (sig_binary_len[sig_idx] && sig_binary_len[sig_idx]) {
if (sig_binary[sig_idx] && sig_binary_len[sig_idx]) {
src_binary[src_idx] = malloc(sig_binary_len[sig_idx]);
src_binary_len[src_idx] = sig_binary_len[sig_idx];
memcpy(src_binary[src_idx], sig_binary[src_idx],
memcpy(src_binary[src_idx], sig_binary[sig_idx],
sig_binary_len[sig_idx]);
}
log_trace(" signal[%d]->source[%d]: (%p:%d)->(%p:%d)", sig_idx,
Expand Down
26 changes: 22 additions & 4 deletions tests/data/test_marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,20 @@ void test_marshal__signalmap_binary_out(void** state)
strdup("bar") },
.binary.expected.binary_len = { 4, 6, 4 },
},
{
// One signal is NULL but len is set (incorrectly).
.name = "foo",
.count = 2,
.signal_idx = { 0, 1 },
.source_idx = { 0, 1 },
.binary.signal.binary = { NULL, strdup("bar") },
.binary.signal.binary_len = { 4, 4 },
.binary.signal.binary_buffer_size = { 4, 4 },
.binary.source.binary = { NULL, NULL },
.binary.source.binary_len = { 0, 0 },
.binary.expected.binary = { NULL, strdup("bar") },
.binary.expected.binary_len = { 0, 4 },
},
};

/* Check every test case. */
Expand Down Expand Up @@ -957,10 +971,14 @@ void test_marshal__signalmap_binary_out(void** state)
for (size_t j = 0; j < msm[0].count; j++) {
assert_int_equal(tc[i].binary.expected.binary_len[j],
msm[0].source.binary_len[j]);
assert_ptr_not_equal(tc[i].binary.signal.binary[j],
tc[i].binary.source.binary[j]);
assert_memory_equal(tc[i].binary.expected.binary[j],
msm[0].source.binary[j], tc[i].binary.expected.binary_len[j]);
if (tc[i].binary.expected.binary[j]) {
assert_ptr_not_equal(tc[i].binary.signal.binary[j],
tc[i].binary.source.binary[j]);
assert_memory_equal(tc[i].binary.expected.binary[j],
msm[0].source.binary[j], tc[i].binary.expected.binary_len[j]);
} else {
assert_null(tc[i].binary.signal.binary[j]);
}
}

/* Cleanup. */
Expand Down

0 comments on commit 5b2a3f1

Please sign in to comment.