Skip to content

[ASan][JSON] Unpoison memory before its reuse #79065

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

Merged
merged 6 commits into from
Jan 23, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion llvm/include/llvm/Support/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
#define LLVM_SUPPORT_JSON_H

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -482,6 +483,13 @@ class Value {
friend class Object;

template <typename T, typename... U> void create(U &&... V) {
#if LLVM_ADDRESS_SANITIZER_BUILD
// Unpoisoning to prevent overwriting poisoned object (e.g., annotated short
// string). Objects that have had their memory poisoned may cause an ASan
// error if their memory is reused without calling their destructor.
// Unpoisoning the memory prevents this error from occurring.
__asan_unpoison_memory_region(&Union, sizeof(T));
#endif
new (reinterpret_cast<T *>(&Union)) T(std::forward<U>(V)...);
}
template <typename T> T &as() const {
Expand Down