Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined behavior #6

Open
Loki-Astari opened this issue Jun 30, 2020 · 0 comments
Open

Undefined behavior #6

Loki-Astari opened this issue Jun 30, 2020 · 0 comments

Comments

@Loki-Astari
Copy link

Loki-Astari commented Jun 30, 2020

ujson/ujson/ujson.hpp

Lines 514 to 517 in 2b17263

inline value::value(value &&rhs) noexcept {
std::memcpy(m_storage, rhs.m_storage, storage_size);
new (rhs.m_storage)null_impl_t{};
}

The use of memcpy() in the value constructors is undefined behavior. You are assuming that these objects don't have internal references (or in the case of std::shared_ptr external references). C++ objects can not simply be copied by using memcpy they should be copied using the copy of move constructor.

Issues are:

inline value::value(value &&rhs) noexcept
inline value &value::operator=(string const &s)
inline value &value::operator=(string &&s)
inline value &value::operator=(array const &a)
inline value &value::operator=(array &&a)
inline value &value::operator=(object const &o)
inline value &value::operator=(object &&o)
inline value &value::operator=(value &&rhs) noexcept
inline void value::swap(value &other) noexcept

The following json files when read into value object will cause a crash (caused by bad call to free()).

Note: This builds and works fine on my apple (OS-X 10.15.5)
But fails on Linux (Ubuntu 18.04)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant