Files
sdk/runtime/vm/libfuzzer/dart_libfuzzer.cc
T
Lorenz Nickel 79e478e50e Fixed some links
**I fixed some links and some other minor flaws.**

I also found the following outdated links, which I didn't fix:

- [This link](https://github.com/dart-lang/pool/tree/zone.strong) in [this file](https://github.com/dart-lang/sdk/blob/master/docs/newsletter/20170728.md) (didn't fix because don't know new location and this is some sort of archive so the link should probably stay the original)
- [This link](https://www.dartlang.org/tools/analyzer) in [this file](https://github.com/dart-lang/sdk/blob/master/pkg/analyzer_cli/lib/src/options.dart) (didn't fix since the link is still working, it just gets redirected and the link is part of the programm, I don't want to break anything by changing it, all other links are in comments)
- [This link](https://github.com/domokit/mojo/issues/728) in [this file](https://github.com/dart-lang/sdk/blob/master/build/config/compiler/BUILD.gn) (didn't fix since probably has no new location and is part of TODO, which I don't want to change)

While doing all this I also noticed that [these tests](https://github.com/dart-lang/sdk/tree/master/tests/compiler/dart2js_extra) contain a lot of other inconsistencies in their comments and the location of the import-statements (I only fixed one which was not link-related), could be target of another PR.

Closes #36927
https://github.com/dart-lang/sdk/pull/36927

GitOrigin-RevId: 71d05d0b52d8ec5b92d077a070e066d1fdd4bbfa
Change-Id: Ide4b2424fccad8ae2e06c788efd4443dc0de997b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/102222
Reviewed-by: Michael Thomsen <mit@google.com>
Commit-Queue: Michael Thomsen <mit@google.com>
2019-07-01 16:21:41 +00:00

96 lines
2.8 KiB
C++

// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include <stddef.h>
#include <stdint.h>
#include "bin/dartutils.h"
#include "platform/text_buffer.h"
#include "platform/unicode.h"
#include "platform/utils.h"
#include "vm/json_writer.h"
// Defines target function.
static int target = 0;
// Target function that stresses some unicode methods.
// Found: http://dartbug.com/36235
static int TestUnicode(const uint8_t* Data, size_t Size) {
dart::Utf8::Type type = dart::Utf8::kLatin1;
dart::Utf8::CodeUnitCount(Data, Size, &type);
dart::Utf8::IsValid(Data, Size);
int32_t dst = 0;
dart::Utf8::Decode(Data, Size, &dst);
uint16_t dst16[1024];
dart::Utf8::DecodeToUTF16(Data, Size, dst16, 1024);
int32_t dst32[1024];
dart::Utf8::DecodeToUTF32(Data, Size, dst32, 1024);
dart::Utf8::ReportInvalidByte(Data, Size, 1024);
return 0;
}
// Target function that stresses various utilities.
// Found: http://dartbug.com/36818
static int TestUtilities(const uint8_t* Data, size_t Size) {
dart::Utils::StringHash(reinterpret_cast<const char*>(Data), Size);
dart::bin::DartUtils::SniffForMagicNumber(Data, Size);
// Text buffer.
dart::TextBuffer buffer(1);
for (size_t i = 0; i < Size; i++) {
buffer.AddChar(Data[i]);
}
if (static_cast<size_t>(buffer.length()) != Size) return 1;
buffer.AddRaw(Data, Size);
if (static_cast<size_t>(buffer.length()) != 2 * Size) return 1;
free(buffer.Steal());
buffer.AddRaw(Data, Size);
if (static_cast<size_t>(buffer.length()) != Size) return 1;
// Json writer.
dart::JSONWriter writer(1);
writer.OpenObject("object");
writer.AppendSerializedObject(Data, Size);
writer.CloseObject();
for (size_t i = 0; i < Size; i++) {
writer.PrintValue(static_cast<intptr_t>(Data[i]));
}
writer.PrintValueBase64(Data, Size);
return 0;
}
// Dart VM specific initialization.
static int InitDartVM() {
// TODO(ajcbik): one-time setup of Dart VM.
return 0;
}
// Libfuzzer one time initialization.
extern "C" int LLVMFuzzerInitialize(int* argc_in, char*** argv_in) {
// Parse --t=<target> from command line.
int argc = *argc_in;
char** argv = *argv_in;
while (--argc > 0) {
char* ptr = *++argv;
if (*ptr++ == '-' && *ptr++ == '-' && *ptr++ == 't' && *ptr++ == '=') {
target = atoi(ptr);
}
}
// Initialize Dart VM.
return InitDartVM();
}
// Libfuzzer target functions:
// 0 : unicode
// 1 : utilies
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {
switch (target) {
case 0:
return TestUnicode(Data, Size);
case 1:
return TestUtilities(Data, Size);
default:
fprintf(stderr, "dart_libfuzzer: invalid target --t=%d\n", target);
return 1;
}
}