aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2019-04-11 14:57:34 +0000
committerPavel Labath <pavel@labath.sk>2019-04-11 14:57:34 +0000
commitd7e12574c61c2fed887963dff543bdb30258c416 (patch)
treec8e667d85f99954bdbd6a82a2f225e321aa96cc5 /llvm/lib/Support/YAMLTraits.cpp
parent[X86][AVX] Add X86ISD::VPERMV3 demandedelts test (diff)
downloadllvm-project-d7e12574c61c2fed887963dff543bdb30258c416.tar.gz
llvm-project-d7e12574c61c2fed887963dff543bdb30258c416.tar.bz2
llvm-project-d7e12574c61c2fed887963dff543bdb30258c416.zip
YAMLIO: Fix serialization of strings with embedded nuls
Summary: A bug/typo in Output::scalarString caused us to round-trip a StringRef through a const char *. This meant that any strings with embedded nuls were unintentionally cut short at the first such character. (It also could have caused accidental buffer overruns, but it seems that all StringRefs coming into this functions were formed from null-terminated strings.) This patch fixes the bug and adds an appropriate test. Reviewers: sammccall, jhenderson Subscribers: kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60505 llvm-svn: 358176
Diffstat (limited to 'llvm/lib/Support/YAMLTraits.cpp')
-rw-r--r--llvm/lib/Support/YAMLTraits.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index 4b5bf6ad30d3..e7932fe4239c 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/lib/Support/YAMLTraits.cpp
@@ -660,11 +660,6 @@ void Output::scalarString(StringRef &S, QuotingType MustQuote) {
return;
}
- unsigned i = 0;
- unsigned j = 0;
- unsigned End = S.size();
- const char *Base = S.data();
-
const char *const Quote = MustQuote == QuotingType::Single ? "'" : "\"";
output(Quote); // Starting quote.
@@ -672,11 +667,16 @@ void Output::scalarString(StringRef &S, QuotingType MustQuote) {
// present, and will be escaped using a variety of unicode-scalar and special short-form
// escapes. This is handled in yaml::escape.
if (MustQuote == QuotingType::Double) {
- output(yaml::escape(Base, /* EscapePrintable= */ false));
+ output(yaml::escape(S, /* EscapePrintable= */ false));
outputUpToEndOfLine(Quote);
return;
}
+ unsigned i = 0;
+ unsigned j = 0;
+ unsigned End = S.size();
+ const char *Base = S.data();
+
// When using single-quoted strings, any single quote ' must be doubled to be escaped.
while (j < End) {
if (S[j] == '\'') { // Escape quotes.