Escape backslashes in crypto test data. embed_test_data.go assumes that it's working with 8KB chunks. However, if the input file contains a '\' then the Go code thinks that it counts as a byte, but the C compiler will probably merge it with the following char and thus that string will be slightly too short. ASAN will detect the out-of-bounds read when 8192 bytes are copied from the string. Change-Id: If40ccfd39ea013bd6935fcc313cfe188fe985f67 Reviewed-on: https://boringssl-review.googlesource.com/30444 Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: David Benjamin <davidben@google.com> CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/util/embed_test_data.go b/util/embed_test_data.go index a083848..5376fdd 100644 --- a/util/embed_test_data.go +++ b/util/embed_test_data.go
@@ -44,6 +44,8 @@ buf.WriteString(`\v`) case '"': buf.WriteString(`\"`) + case '\\': + buf.WriteString(`\\`) default: // printable ascii code [32, 126] if 32 <= b && b <= 126 { @@ -100,19 +102,21 @@ for i, arg := range os.Args[1:] { data, err := ioutil.ReadFile(arg) if err != nil { - fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", data, err) + fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", arg, err) os.Exit(1) } + fmt.Printf("static const size_t kLen%d = %d;\n\n", i, len(data)) + fmt.Printf("static const char *kData%d[] = {\n", i) - for i := 0; i < len(data); i += chunkSize { + for len(data) > 0 { chunk := chunkSize - if chunk > len(data)-i { - chunk = len(data) - i + if chunk > len(data) { + chunk = len(data) } - fmt.Printf(" %s,\n", quote(data[i:i+chunk])) + fmt.Printf(" %s,\n", quote(data[:chunk])) + data = data[chunk:] } fmt.Printf("};\n") - fmt.Printf("static const size_t kLen%d = %d;\n\n", i, len(data)) } fmt.Printf(`static std::string AssembleString(const char **data, size_t len) {