Make msan treat mjData buffer as uninitialized in mj_resetData.

Indiscriminate memset into d->buffer and m->buffer previously caused msan to not detect uninitialized reads.

Also fix tests with uninitialized read bugs that are detected by msan after this change.

PiperOrigin-RevId: 451508224
Change-Id: I1f4b080a8ef765c34ba7a0adc2c686419f6e5516
This commit is contained in:
Saran Tunyasuvunakool
2022-05-27 16:33:38 -07:00
committed by Copybara-Service
parent ef9fa9dfe4
commit 185b79f664
5 changed files with 108 additions and 38 deletions
-3
View File
@@ -307,9 +307,6 @@ TEST_F(EllipsoidFluidTest, GeomsEquivalentToBodies) {
const mjtNum tol = 1e-14; // tolerance for floating point numbers
EXPECT_EQ(m1->nv, m2->nv);
for (int i = 0; i < m1->nv; i++) {
EXPECT_NEAR(d2->qfrc_passive[i], d1->qfrc_passive[i], tol);
}
mj_forward(m2, d2);
mj_forward(m1, d1);
+18 -8
View File
@@ -70,12 +70,17 @@ TEST_F(EngineIoTest, MakeDataFromPartialModel) {
ASSERT_THAT(data_from_partial, NotNull());
EXPECT_EQ(data_from_partial->nbuffer, data_from_model->nbuffer);
int nbuffer = data_from_partial->nbuffer;
// If there are no mocap bodies and qpos0 is all zero, mjData should be the
// same whether it was made from the full model or the partial model.
EXPECT_EQ(
std::memcmp(data_from_partial->buffer, data_from_model->buffer, nbuffer),
0) << "mjData content differs";
{
MJDATA_POINTERS_PREAMBLE((&partial_model))
#define X(type, name, nr, nc) \
EXPECT_EQ(std::memcmp(data_from_partial->name, data_from_model->name, \
sizeof(type)*(partial_model.nr)*(nc)), \
0) << "mjData::" #name " differs";
MJDATA_POINTERS
#undef X
}
mj_deleteData(data_from_model);
mj_deleteData(data_from_partial);
@@ -158,10 +163,15 @@ TEST_F(EngineIoTest, CopyDataWithPartialModel) {
EXPECT_EQ(copy->nbuffer, data->nbuffer);
EXPECT_EQ(copy->qpos[0], 1);
int nbuffer = copy->nbuffer;
EXPECT_EQ(
std::memcmp(copy->buffer, data->buffer, nbuffer),
0) << "mjData content differs";
{
MJDATA_POINTERS_PREAMBLE((&partial_model))
#define X(type, name, nr, nc) \
EXPECT_EQ(std::memcmp(copy->name, data->name, \
sizeof(type)*(partial_model.nr)*(nc)), \
0) << "mjData::" #name " differs";
MJDATA_POINTERS
#undef X
}
mj_deleteData(data);
mj_deleteData(copy);