mapbox / mapbox/variant

Possible data corruption when assigning variant to itself

Open
#164 4 comments 1 reaction 1 assignee View on GitHub

@artemp is already working on this.

Since Jan 11, 2018.

Dominant language
C++
Stars
384
Forks
96
PR merge metrics
No merged PRs in 30d

Description

Hi, Thanks to you variant implementation!
But i see, that there are issue in member
```
VARIANT_INLINE variant& operator=(variant const& other)
{
copy_assign(other);
return *this;
}
```

Now there are no check for `&other ==this` and `copy_assign` can destroy variant member data's before actual copy to itself
```
VARIANT_INLINE void copy_assign(variant const& rhs)
{
helper_type::destroy(type_index, &data);
type_index = detail::invalid_value;
helper_type::copy(rhs.type_index, &rhs.data, &data);
type_index = rhs.type_index;
}
```

So, in result `helper_type::copy(rhs.type_index, &rhs.data, &data);` can operate with invalid data

Best Regards

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.