[PATCH] D46274: [Support] Harden JSON against invalid UTF-8.
Ben Hamilton via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 9 09:06:03 PDT 2018
benhamilton accepted this revision.
benhamilton added a comment.
This revision is now accepted and ready to land.
Thanks!
================
Comment at: include/llvm/Support/JSON.h:302
+ Value(std::string V) : Type(T_String) {
+ if (!LLVM_LIKELY(isUTF8(V))) {
+ assert(false && "Invalid UTF-8 in value used as JSON");
----------------
Seems like flipping the check is clearer:
```
if (LLVM_UNLIKELY(!isUTF8(V)) {
```
================
Comment at: include/llvm/Support/JSON.h:314
+ create<llvm::StringRef>(V);
+ if (!LLVM_LIKELY(isUTF8(V))) {
+ assert(false && "Invalid UTF-8 in value used as JSON");
----------------
Ditto on LLVM_UNLIKELY.
================
Comment at: include/llvm/Support/JSON.h:491
+ ObjectKey(std::string S) : Owned(new std::string(std::move(S))) {
+ if (!LLVM_LIKELY(isUTF8(*Owned))) {
+ assert(false && "Invalid UTF-8 in value used as JSON");
----------------
Ditto ditto.
================
Comment at: include/llvm/Support/JSON.h:498
+ ObjectKey(llvm::StringRef S) : Data(S) {
+ if (!LLVM_LIKELY(isUTF8(Data))) {
+ assert(false && "Invalid UTF-8 in value used as JSON");
----------------
Ditto ditto ditto.
Repository:
rL LLVM
https://reviews.llvm.org/D46274
More information about the llvm-commits
mailing list