Mercurial > hg
annotate tests/test-fuzz-targets.t @ 42562:97ada9b8d51b stable 5.0.2
posix: always seek to EOF when opening a file in append mode
Python 3 already does this, so skip it there.
Consider the program:
#include <stdio.h>
int main() {
FILE *f = fopen("narf", "w");
fprintf(f, "narf\n");
fclose(f);
f = fopen("narf", "a");
printf("%ld\n", ftell(f));
fprintf(f, "troz\n");
printf("%ld\n", ftell(f));
return 0;
}
on macOS, FreeBSD, and Linux with glibc, this program prints
5
10
but on musl libc (Alpine Linux and probably others) this prints
0
10
By my reading of
https://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html
this is technically correct, specifically:
> Opening a file with append mode (a as the first character in the
> mode argument) shall cause all subsequent writes to the file to be
> forced to the then current end-of-file, regardless of intervening
> calls to fseek().
in other words, the file position doesn't really matter in append-mode
files, and we can't depend on it being at all meaningful unless we
perform a seek() before tell() after open(..., 'a'). Experimentally
after a .write() we can do a .tell() and it'll always be reasonable,
but I'm unclear from reading the specification if that's a smart thing
to rely on. This matches what we do on Windows and what Python 3 does
for free, so let's just be consistent. Thanks to Yuya for the idea.
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 08 Jul 2019 13:12:20 -0400 |
parents | d9fc51f77cc5 |
children | 39cab871e880 |
rev | line source |
---|---|
38236
a6347ae6168d
test-fuzz-targets: look for clang-6.0 binary as well
Yuya Nishihara <yuya@tcha.org>
parents:
38235
diff
changeset
|
1 #require test-repo |
a6347ae6168d
test-fuzz-targets: look for clang-6.0 binary as well
Yuya Nishihara <yuya@tcha.org>
parents:
38235
diff
changeset
|
2 |
35670
2b9e2415f5b5
contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
3 $ cd $TESTDIR/../contrib/fuzz |
38236
a6347ae6168d
test-fuzz-targets: look for clang-6.0 binary as well
Yuya Nishihara <yuya@tcha.org>
parents:
38235
diff
changeset
|
4 |
40726
6c01fad8de32
tests: sniff for /usr/local/bin/gmake and use it in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
38246
diff
changeset
|
5 which(1) could exit nonzero, but that's fine because we'll still end |
6c01fad8de32
tests: sniff for /usr/local/bin/gmake and use it in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
38246
diff
changeset
|
6 up without a valid executable, so we don't need to check $? here. |
6c01fad8de32
tests: sniff for /usr/local/bin/gmake and use it in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
38246
diff
changeset
|
7 |
6c01fad8de32
tests: sniff for /usr/local/bin/gmake and use it in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
38246
diff
changeset
|
8 $ if which gmake >/dev/null 2>&1; then |
6c01fad8de32
tests: sniff for /usr/local/bin/gmake and use it in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
38246
diff
changeset
|
9 > MAKE=gmake |
6c01fad8de32
tests: sniff for /usr/local/bin/gmake and use it in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
38246
diff
changeset
|
10 > else |
6c01fad8de32
tests: sniff for /usr/local/bin/gmake and use it in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
38246
diff
changeset
|
11 > MAKE=make |
6c01fad8de32
tests: sniff for /usr/local/bin/gmake and use it in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
38246
diff
changeset
|
12 > fi |
6c01fad8de32
tests: sniff for /usr/local/bin/gmake and use it in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
38246
diff
changeset
|
13 |
40727
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
14 $ havefuzz() { |
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
15 > cat > $TESTTMP/dummy.cc <<EOF |
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
16 > #include <stdlib.h> |
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
17 > #include <stdint.h> |
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
18 > int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { return 0; } |
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
19 > int main(int argc, char **argv) { |
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
20 > const char data[] = "asdf"; |
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
21 > return LLVMFuzzerTestOneInput((const uint8_t *)data, 4); |
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
22 > } |
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
23 > EOF |
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
24 > $CXX $TESTTMP/dummy.cc -o $TESTTMP/dummy \ |
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
25 > -fsanitize=fuzzer-no-link,address || return 1 |
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
26 > } |
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
27 |
38236
a6347ae6168d
test-fuzz-targets: look for clang-6.0 binary as well
Yuya Nishihara <yuya@tcha.org>
parents:
38235
diff
changeset
|
28 #if clang-libfuzzer |
40727
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
29 $ CXX=clang++ havefuzz || exit 80 |
40726
6c01fad8de32
tests: sniff for /usr/local/bin/gmake and use it in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
38246
diff
changeset
|
30 $ $MAKE -s clean all |
38236
a6347ae6168d
test-fuzz-targets: look for clang-6.0 binary as well
Yuya Nishihara <yuya@tcha.org>
parents:
38235
diff
changeset
|
31 #endif |
a6347ae6168d
test-fuzz-targets: look for clang-6.0 binary as well
Yuya Nishihara <yuya@tcha.org>
parents:
38235
diff
changeset
|
32 #if no-clang-libfuzzer clang-6.0 |
40727
d9fc51f77cc5
tests: sniff for libfuzzer actually being available in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
40726
diff
changeset
|
33 $ CXX=clang++-6.0 havefuzz || exit 80 |
40726
6c01fad8de32
tests: sniff for /usr/local/bin/gmake and use it in test-fuzz-targets.t
Augie Fackler <augie@google.com>
parents:
38246
diff
changeset
|
34 $ $MAKE -s clean all CC=clang-6.0 CXX=clang++-6.0 |
38236
a6347ae6168d
test-fuzz-targets: look for clang-6.0 binary as well
Yuya Nishihara <yuya@tcha.org>
parents:
38235
diff
changeset
|
35 #endif |
a6347ae6168d
test-fuzz-targets: look for clang-6.0 binary as well
Yuya Nishihara <yuya@tcha.org>
parents:
38235
diff
changeset
|
36 #if no-clang-libfuzzer no-clang-6.0 |
a6347ae6168d
test-fuzz-targets: look for clang-6.0 binary as well
Yuya Nishihara <yuya@tcha.org>
parents:
38235
diff
changeset
|
37 $ exit 80 |
a6347ae6168d
test-fuzz-targets: look for clang-6.0 binary as well
Yuya Nishihara <yuya@tcha.org>
parents:
38235
diff
changeset
|
38 #endif |
a6347ae6168d
test-fuzz-targets: look for clang-6.0 binary as well
Yuya Nishihara <yuya@tcha.org>
parents:
38235
diff
changeset
|
39 |
38172
24cc2969abae
tests: update fuzzer tests to include both fuzzers
Augie Fackler <augie@google.com>
parents:
35670
diff
changeset
|
40 Just run the fuzzers for five seconds each to verify it works at all. |
35670
2b9e2415f5b5
contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 $ ./bdiff -max_total_time 5 |
38246
46dcb9f14900
fuzz: new fuzzer for the mpatch code
Augie Fackler <augie@google.com>
parents:
38236
diff
changeset
|
42 $ ./mpatch -max_total_time 5 |
38172
24cc2969abae
tests: update fuzzer tests to include both fuzzers
Augie Fackler <augie@google.com>
parents:
35670
diff
changeset
|
43 $ ./xdiff -max_total_time 5 |